Thanks! I have two more articles nearly ready to post, so stay tuned. Anyway, return for the Maybe monad is just Just, because its argument is arbitrary (it's not restricted to be a Maybe type). Written out fully, it's:
return :: a -> Maybe a return x = Just x -- or just: -- return = Just
Notice that a can be any type whatsoever, not just a Maybe type. The value returned from return (I know that sounds weird) will be a Maybe type, but the argument can be of any type.
(Possible) eq. 6 proof & dice roll errors
anonymous
December 7 2010, 00:18:23 UTC
Hey there,
I’m all very new to this, but I think I may have found some little errors:
1. In the Eq. 6 proof, the lines
= map f x1 : map f (xs ++ y) -- definition of map = map f x1 : (map f xs ++ map f y) -- inductive hypothesis = (map f x1 : map f xs) ++ map f y -- definition of ++
the first map on each line should be omitted, according to the definition of the map function.
2. In the dice roll function, the if and else branches don’t have the same types-(n1,n2) vs. [ ]. If I understand this all correctly, the tuple should be made into a list: [(n1,n2)].
Of course, if any of this is wrong, feel free to correct me!
Thanks a lot for these guides. Especially the monadic functions vs. monadic values discussion and the in-depth treatment of example monads are invaluable!
Re: (Possible) eq. 6 proof & dice roll errorsmvanierDecember 17 2010, 01:16:28 UTC
Thanks for your bug fixes! I'll have a corrected version up shortly. It's embarrassing to see these mistakes, but it's great to have readers who catch them. Thanks also for your positive comments -- I really appreciate them.
Re: (Possible) eq. 6 proof & dice roll errorsmvanierDecember 17 2010, 01:22:21 UTC
BTW the dice roll function is correct, as you can verify by typing into ghci or copying to a file and running from ghci. The "then" branch of the if is "return (n1, n2)" which is just [(n1, n2)] by the definition of return for the list monad. So both branches of the if have the same type.
Trivial typo
anonymous
February 28 2011, 05:43:05 UTC
In your dice roll example, you say "find all pairs of numbers between 1 and 6 that sum to the number 7". It should be "sum to the number 6". Just thought I'd point that out.
Comments 12
return Nothing = Nothing
PS: your tutorial is very intuitive and nice. Done a good job!
Reply
return :: a -> Maybe a
return x = Just x
-- or just:
-- return = Just
Notice that a can be any type whatsoever, not just a Maybe type. The value returned from return (I know that sounds weird) will be a Maybe type, but the argument can be of any type.
Reply
Reply
return x = Just x
then it doesn't seem to match what's built in to Haskell, viz:
*Main> return Nothing
Nothing
and
*Main> return (Just 3)
Just 3
Is there something I'm missing? Your tutorials are awesome, by the way, thanks.
Reply
I’m all very new to this, but I think I may have found some little errors:
1. In the Eq. 6 proof, the lines
= map f x1 : map f (xs ++ y) -- definition of map
= map f x1 : (map f xs ++ map f y) -- inductive hypothesis
= (map f x1 : map f xs) ++ map f y -- definition of ++
the first map on each line should be omitted, according to the definition of the map function.
2. In the dice roll function, the if and else branches don’t have the same types-(n1,n2) vs. [ ]. If I understand this all correctly, the tuple should be made into a list: [(n1,n2)].
Of course, if any of this is wrong, feel free to correct me!
Thanks a lot for these guides. Especially the monadic functions vs. monadic values discussion and the in-depth treatment of example monads are invaluable!
Reply
Reply
Reply
Reply
Reply
Leave a comment