Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-24 Thread Alexander Solla
On Mon, May 23, 2011 at 6:21 PM, Richard O'Keefe o...@cs.otago.ac.nz wrote: On 24/05/2011, at 5:49 AM, Alexander Solla wrote: There's a library function for it, but also: filter ((/=) Nothing) The problem with that in general is that it only applies to [Maybe t] if Eq t, but you don't

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-24 Thread Henning Thielemann
Alexander Solla schrieb: Personally, I find non-functional values without Eq instances to be degenerate. So I really do not mind superfluous Eq constraints. I would not hesitate to use filter ((/=) Nothing) in a function whose type has no free type variables. It's just a bit of plumbing

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-24 Thread Alexander Solla
Personally, I find non-functional values without Eq instances to be degenerate. So I really do not mind superfluous Eq constraints. I would not hesitate to use filter ((/=) Nothing) in a function whose type has no free type variables. It's just a bit of plumbing inside of a more

[Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread michael rice
What's the best way to end up with a list composed of only the Just values,no Nothings? Michael ==  import Control.Monad.Stateimport Data.Maybe type GeneratorState = State Int tick :: GeneratorState (Maybe Int)tick = do n - get          if ((n `mod` 7) == 0)           

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Malcolm Wallace
On 23 May 2011, at 17:20, michael rice wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? Go to haskell.org/hoogle Type in [Maybe a] - [a] Click on first result. ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Gregory Crosswhite
On 5/23/11 9:20 AM, michael rice wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? Try catMaybes in Data.Maybe. Cheers, Greg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Max Bolingbroke
On 23 May 2011 17:20, michael rice nowg...@yahoo.com wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? http://haskell.org/hoogle/?hoogle=%3A%3A+%5BMaybe+a%5D+-%3E+%5Ba%5D Data.Maybe.catMaybes is what you want :-) Cheers, Max

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Malcolm Wallace
On 23 May 2011, at 17:20, michael rice wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? Alternatively, [ x | Just x - originals ] It also occurs to me that perhaps you still want the Just constructors. [ Just x | Just x -

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Gregory Crosswhite
On 5/23/11 9:29 AM, Max Bolingbroke wrote: On 23 May 2011 17:20, michael rice nowg...@yahoo.com mailto:nowg...@yahoo.com wrote: What's the best way to end up with a list composed of only the Just values, no Nothings?

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Alexander Solla
On Mon, May 23, 2011 at 9:20 AM, michael rice nowg...@yahoo.com wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? Michael == import Control.Monad.State import Data.Maybe type GeneratorState = State Int tick ::

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread michael rice
leads to another. It's interesting how ideas begin bubbling up after one absorbs some critical mass of Haskell. Michael   --- On Mon, 5/23/11, Malcolm Wallace malcolm.wall...@me.com wrote: From: Malcolm Wallace malcolm.wall...@me.com Subject: Re: [Haskell-cafe] [Maybe Int] sans Nothings

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Brent Yorgey
On Mon, May 23, 2011 at 10:49:55AM -0700, Alexander Solla wrote: On Mon, May 23, 2011 at 9:20 AM, michael rice nowg...@yahoo.com wrote: What's the best way to end up with a list composed of only the Just values, no Nothings? Michael == import

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Gregory Crosswhite
On 05/23/2011 12:08 PM, Brent Yorgey wrote: Just a minor quibble: note that filter (not . isNothing) is slightly preferable since it does not introduce a frivolous equality constraint on the type wrapped by the Maybe. Or even better, filter isJust :-) Cheers, Greg

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Henning Thielemann
Brent Yorgey schrieb: On Mon, May 23, 2011 at 10:49:55AM -0700, Alexander Solla wrote: There's a library function for it, but also: filter ((/=) Nothing) is readable enough. Just a minor quibble: note that filter (not . isNothing) is slightly preferable since it does not introduce a

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Ertugrul Soeylemez
Gregory Crosswhite gcr...@phys.washington.edu wrote: Or even better, filter isJust To make it worse again the original function can be generalized in a few ways. Here is a generalization from the inner Maybe type: import Data.Foldable as F catFoldables :: Foldable t = [t a] -

Re: [Haskell-cafe] [Maybe Int] sans Nothings

2011-05-23 Thread Richard O'Keefe
On 24/05/2011, at 5:49 AM, Alexander Solla wrote: There's a library function for it, but also: filter ((/=) Nothing) The problem with that in general is that it only applies to [Maybe t] if Eq t, but you don't actually _need_ t to support equality. filter isJust will do the job, where