Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Achim Schneider
tsuraan tsur...@gmail.com wrote: Is there a more concise way to do this? I use someIO = f where f Opt1 = ... If it's a common pattern, you can even do opts f _ _ (Opt1 x) = f x opts _ g _ (Opt2 x) = g x opts _ _ h (Opt3 x) = h x . Functions are easier to mess around with than case

Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Maciej Marcin Piechotka
On Mon, 2011-03-14 at 17:56 +0100, Yves Parès wrote: If you have only one alternative, then you can simply do: Opt1 - someIO E.g., if you are _sure_ that foo returns always a 'Just' within a monad you can perfectly do : Just x - foo Please beware - it is not exactly the same as with

Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Donn Cave
Quoth Achim Schneider bars...@web.de, ... I use someIO = f where f Opt1 = ... If it's a common pattern, you can even do opts f _ _ (Opt1 x) = f x opts _ g _ (Opt2 x) = g x opts _ _ h (Opt3 x) = h x . Functions are easier to mess around with than case expressions. I like

Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Ertugrul Soeylemez
Hello tsuraan, Most often, when we multi-pattern-match on the return value of a monadic computation, we talk about Maybe or Either or [], and I often find myself doing this: someIO1 :: IO (Maybe A) someIO2 :: IO (Either A B) result1 - someIO1 = maybe ... result2 - someIO2 =

Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Tillmann Rendel
Hi, Donn Cave wrote: someIO= f where f Opt1 = ... I like this ... or, I would like it, if I could make it work! I get The last statement in a 'do' construct must be an expression, Where-clauses can only be used on equations, not on expressions or statements, so you would need

Re: [Haskell-cafe] Question on a common pattern

2011-03-15 Thread Donn Cave
Quoth Tillmann Rendel ren...@informatik.uni-marburg.de, ... Where-clauses can only be used on equations, not on expressions or statements, so you would need to float the where clause outwards: So ... not to put too fine a point on it, but ... as useful as function notation could be for the

[Haskell-cafe] Question on a common pattern

2011-03-14 Thread tsuraan
In my code, I'm doing this quite a lot: x - someIO case x of Opt1 - ... Having a line for extracting the value from the IO (or STM) and then acting on the value seems unnatural. Is there a more concise way to do this? This code: case someIO of Opt1 - ... Doesn't work, but is there

Re: [Haskell-cafe] Question on a common pattern

2011-03-14 Thread Ozgur Akgun
See this thread: http://www.haskell.org/pipermail/haskell-cafe/2010-October/084291.html On 14 March 2011 15:48, tsuraan tsur...@gmail.com wrote: In my code, I'm doing this quite a lot: x - someIO case x of Opt1 - ... Having a line for extracting the value from the IO (or STM) and then

Re: [Haskell-cafe] Question on a common pattern

2011-03-14 Thread Chris Dornan
-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of tsuraan Sent: 14 March 2011 15:49 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Question on a common pattern In my code, I'm doing this quite a lot: x - someIO case x of Opt1 - ... Having a line for extracting

Re: [Haskell-cafe] Question on a common pattern

2011-03-14 Thread Yves Parès
If you have only one alternative, then you can simply do: Opt1 - someIO E.g., if you are _sure_ that foo returns always a 'Just' within a monad you can perfectly do : Just x - foo 2011/3/14 tsuraan tsur...@gmail.com In my code, I'm doing this quite a lot: x - someIO case x of Opt1 -

Re: [Haskell-cafe] Question on a common pattern

2011-03-14 Thread tsuraan
See this thread: http://www.haskell.org/pipermail/haskell-cafe/2010-October/084291.html Which links to http://hackage.haskell.org/trac/ghc/ticket/4359 . Looks like there's already been quite a bit of discussion on this already :) Thanks for the link.

Re: [Haskell-cafe] Question on a common pattern

2011-03-14 Thread tsuraan
If you have only one alternative, then you can simply do: Opt1 - someIO E.g., if you are _sure_ that foo returns always a 'Just' within a monad you can perfectly do : Just x - foo That's interesting. I had no idea that one could do that. I think what I'm looking for is something along