Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: RFC: A Perlesque Introduction to Haskell, Part One (draft)

by Sidhekin (Priest)
on Jun 24, 2004 at 02:29 UTC ( [id://369227]=note: print w/replies, xml ) Need Help??


in reply to Re^3: RFC: A Perlesque Introduction to Haskell, Part One (draft)
in thread RFC: A Perlesque Introduction to Haskell, Part One (DRAFT)

Haskel goes a little further, though, because it supports function-dispatch by pattern matching...

My mind has been full of Perl6 lately ... so bear with me ...

multi sub factorial (Any where {$^n==0} $n) { 1 } multi sub factorial ($n) { $n * factorial $n-1 }

... which of course will recurse infinitely when given factorial 0.5 or factorial -1 ...

ObTopic: How do the Haskell examples handle those cases?

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^5: RFC: A Perlesque Introduction to Haskell, Part One (draft)
by ihb (Deacon) on Jun 24, 2004 at 02:44 UTC

    How do the Haskell examples handle those cases?

    It doesn't. You can use "boolean guards" though to handle different cases:

    fac 0 = 1; fac n | n > 0 = n * fac (n-1) | otherwise = ...
    otherwise is just a standard alias for True to make it read well.

    ihb

Re^5: RFC: A Perlesque Introduction to Haskell, Part One (draft)
by etcshadow (Priest) on Jun 24, 2004 at 02:40 UTC
    Touche. I was referring to perl 5, not perl 6. But that's cool to know.
    ------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found