Re: Re[2]: [Haskell-cafe] nested maybes

2007-02-05 Thread Martin DeMello
On 2/5/07, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello J., Sunday, February 4, 2007, 11:46:57 PM, you wrote: exists s wmap = isJust $ find (==s) . snd = Map.lookup (sort s) wmap exists s wmap = Map.lookup (sort s) wmap == snd == find (==s)

Re: [Haskell-cafe] nested maybes

2007-02-05 Thread Bryan Donlan
Martin DeMello wrote: On 2/5/07, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello J., Sunday, February 4, 2007, 11:46:57 PM, you wrote: exists s wmap = isJust $ find (==s) . snd = Map.lookup (sort s) wmap exists s wmap = Map.lookup (sort s) wmap == snd ==

[Haskell-cafe] nested maybes

2007-02-04 Thread Martin DeMello
I have a Data.Map.Map String - (Layout, [String]) as follows: type Anagrams = [String] type Cell = (Layout, Anagrams) type WordMap = Map.Map String Cell exists str wmap = let a = Map.lookup (sort str) wmap in case a of Nothing - False Just x - case (find (== str) (snd

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread Lemmih
On 2/4/07, Martin DeMello [EMAIL PROTECTED] wrote: I have a Data.Map.Map String - (Layout, [String]) as follows: type Anagrams = [String] type Cell = (Layout, Anagrams) type WordMap = Map.Map String Cell exists str wmap = let a = Map.lookup (sort str) wmap in case a of

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread J. Garrett Morris
Maybe has a Monad instance, so you can write this as follows (untested): exists str wmap = boolFromMaybe exists' where exists' = do x - Map.lookup (sort str) wmap find (== str) (snd x) boolFromMaybe (Just _) = True boolFromMaybe Nothing = False

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread Mattias Bengtsson
On Sun, 2007-02-04 at 19:54 +0530, Martin DeMello wrote: I have a Data.Map.Map String - (Layout, [String]) as follows: type Anagrams = [String] type Cell = (Layout, Anagrams) type WordMap = Map.Map String Cell exists str wmap = let a = Map.lookup (sort str) wmap in case a of

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread J. Garrett Morris
On 2/4/07, Udo Stenzel [EMAIL PROTECTED] wrote: J. Garrett Morris wrote: Small improvement (Data.Maybe is underappreciated): exists str wmap = isJust exists' where exists' = do x - Map.lookup (sort str) wmap find (== str) (snd x) This is true. Some time

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread Neil Mitchell
Hi This is true. Some time ago I swore off the use of fromRight and fromLeft in favor of maybe, and have been forgetting about the other functions in Data.Maybe ever since. I think you mean you swore off fromJust. Unfortunately when people started to debate adding fromLeft and fromRight they

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread Udo Stenzel
J. Garrett Morris wrote: On 2/4/07, Udo Stenzel [EMAIL PROTECTED] wrote: exists s wmap = isJust $ Map.lookup (sort s) wmap = find (== s) . snd If you're going to write it all on one line, I prefer to keep things going the same direction: Hey, doing it this way saved me a full two

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread Donald Bruce Stewart
u.stenzel: J. Garrett Morris wrote: On 2/4/07, Udo Stenzel [EMAIL PROTECTED] wrote: exists s wmap = isJust $ Map.lookup (sort s) wmap = find (== s) . snd If you're going to write it all on one line, I prefer to keep things going the same direction: Hey, doing it this way saved me a

Re: [Haskell-cafe] nested maybes

2007-02-04 Thread J. Garrett Morris
On 2/4/07, Udo Stenzel [EMAIL PROTECTED] wrote: J. Garrett Morris wrote: On 2/4/07, Udo Stenzel [EMAIL PROTECTED] wrote: Well, depends on whether we are allowed to define new combinators. I sometimes use -- Kleisli composition infixl 1 @@ (@@) :: Monad m = (a - m b) - (b - m c) - (a - m c) f