
Just noticed this difference in the definition of fromMaybe in two different places: http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/src/Data-Mayb... -- | The 'fromMaybe' function takes a default value and and 'Maybe' -- value. If the 'Maybe' is 'Nothing', it returns the default values; -- otherwise, it returns the value contained in the 'Maybe'. fromMaybe :: a -> Maybe a -> a fromMaybe d x = case x of {Nothing -> d;Just v -> v} and http://en.wikibooks.org/wiki/Haskell/Hierarchical_libraries/Maybe fromMaybe :: a -> Maybe a -> a fromMaybe z = maybe z id Michael

Excerpts from michael rice's message of Tue Jan 26 21:34:42 -0500 2010:
fromMaybe d x = case x of {Nothing -> d;Just v -> v} fromMaybe z = maybe z id
They're equivalent. Here the definition of maybe: maybe :: b -> (a -> b) -> Maybe a -> b maybe n _ Nothing = n maybe _ f (Just x) = f x Cheers, Edward

Didn't recognize the sameness. Aside from there being many ways to do the same thing, partial application makes the mixup even merrier.
Thanks,
Michael
--- On Tue, 1/26/10, Edward Z. Yang
fromMaybe d x = case x of {Nothing -> d;Just v -> v} fromMaybe z = maybe z id
They're equivalent. Here the definition of maybe: maybe :: b -> (a -> b) -> Maybe a -> b maybe n _ Nothing = n maybe _ f (Just x) = f x Cheers, Edward

There are actually only two (extensionally) possible total functions with
that type, as far as I can see :)
On Tue, Jan 26, 2010 at 11:12 PM, michael rice
Didn't recognize the sameness. Aside from there being many ways to do the same thing, partial application makes the mixup even merrier.
Thanks,
Michael
--- On *Tue, 1/26/10, Edward Z. Yang
* wrote: From: Edward Z. Yang
Subject: Re: [Haskell-cafe] Maybe, maybe not. To: "michael rice" Cc: "haskell-cafe" Date: Tuesday, January 26, 2010, 10:52 PM Excerpts from michael rice's message of Tue Jan 26 21:34:42 -0500 2010:
fromMaybe d x = case x of {Nothing -> d;Just v -> v} fromMaybe z = maybe z id
They're equivalent. Here the definition of maybe:
maybe :: b -> (a -> b) -> Maybe a -> b maybe n _ Nothing = n maybe _ f (Just x) = f x
Cheers, Edward
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2010/1/27 Edward Z. Yang
Excerpts from Daniel Peebles's message of Tue Jan 26 23:25:28 -0500 2010:
There are actually only two (extensionally) possible total functions with that type, as far as I can see :)
Is the other one... const?
As far as I can tell, yes. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com Jonathan Swift - "May you live every day of your life." - http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html

It might be more obvious by giving: fromMaybe :: a -> (a -> x, x) -> x Ivan Miljenovic wrote:
2010/1/27 Edward Z. Yang
: Excerpts from Daniel Peebles's message of Tue Jan 26 23:25:28 -0500 2010:
There are actually only two (extensionally) possible total functions with that type, as far as I can see :)
Is the other one... const?
As far as I can tell, yes.
-- Tony Morris http://tmorris.net/

2010/1/27 Tony Morris
It might be more obvious by giving:
fromMaybe :: a -> (a -> x, x) -> x
I actually found this more confusing, and am not sure of its validity: should that be "Maybe a" there at the beginning? -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com Pablo Picasso - "Computers are useless. They can only give you answers." - http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html

Ivan Miljenovic wrote:
2010/1/27 Tony Morris
: It might be more obvious by giving:
fromMaybe :: a -> (a -> x, x) -> x
I actually found this more confusing, and am not sure of its validity: should that be "Maybe a" there at the beginning?
Sorry a mistake. Correction: fromMaybe :: a -> ((a -> x, x) -> x) -> x {-# LANGUAGE RankNTypes #-} data Maybe' a = M (forall x. (a -> x, x) -> x) to :: Maybe' t -> Maybe t to (M f) = f (Just, Nothing) from :: Maybe a -> Maybe' a from (Just a) = M (flip fst a) from Nothing = M snd -- Tony Morris http://tmorris.net/
participants (5)
-
Daniel Peebles
-
Edward Z. Yang
-
Ivan Miljenovic
-
michael rice
-
Tony Morris