Ahn Ki-yung wrote:
Simple Cat (revisitied)
\begin{code}
import IO
findM f [] = return Nothing
findM f (x:xs) = do { v - x; if f v then return (Just v) else findM f xs }
isLeft (Left _) = True
isLeft _ = False
main = findM (isLeft) (hCat stdin) where hCat h = try (hGetLine h) : hCat h
Simple Cat (revisitied)
\begin{code}
import IO
findM f [] = return Nothing
findM f (x:xs) = do { v - x; if f v then return (Just v) else findM f xs }
isLeft (Left _) = True
isLeft _ = False
main = findM (isLeft) (hCat stdin) where hCat h = try (hGetLine h) : hCat h
\end{code}
This is my
Simple Cat (revisitied)
\begin{code}
import IO
findM f [] = return Nothing
findM f (x:xs) = do { v - x; if f v then return (Just v) else findM f xs }
isLeft (Left _) = True
isLeft _ = False
main = findM (isLeft) (hCat stdin) where hCat h = try (hGetLine h) : hCat h
\end{code}
Jorge Adriano wrote:
Seems to me like the name findM could be misleading
mapM :: (Monad m) = (a - m b) - [a] - m [b]
filterM :: (Monad m) = (a - m Bool) - [a] - m [a]
These take a monadic function and a list of elements. Yours works the other
way around (takes a function and a list of 'monadic
\begin{code}
import IO
findM f [] = return Nothing
findM f (x:xs) = do { b - f x; if b then return (Just x) else findM f xs }
isLeft (Left _) = True
isLeft _ = False
main =
findM (=return.isLeft) $
map (try . uncurry (=)) $
zip (hGetCharS stdin)
I appreciate your comment.
I agree that the type of findM should be the one you suggested,
and it still fits my original purpose. It's no more than a step arout.
\begin{code}
import IO
findM f [] = return Nothing
findM f (x:xs) = do { b - f x; if b then return (Just x) else findM f xs }
G'day all.
On Wed, Nov 20, 2002 at 08:25:46PM +, Jorge Adriano wrote:
I think both versions can be very useful:
findM :: (Monad m) = (a - m Bool) - [a] - m (Maybe a)
findM' :: (Monad m) = (a - Bool) - [m a] - m (Maybe a)
I can also make a case for:
findM'' :: (Monad
I am trying to construct an infinate list of pairs of random colors.
I am hung up on getting a random color. I have:
data Color = Blue | Red | Green deriving (Eq, Ord, Show)
am I supposed to instantiate a Random class instance from color?
I am not sure exactly how the random number generator
G'day all.
On Wed, Nov 20, 2002 at 08:44:36PM -0500, Mike T. Machenry wrote:
I am trying to construct an infinate list of pairs of random colors.
I am hung up on getting a random color. I have:
data Color = Blue | Red | Green deriving (Eq, Ord, Show)
am I supposed to instantiate a Random
Andrew and list,
I am a beginer. I really don't know what I would do if I derived
Color from Enum. You say I could create elements that way. Is there
some simple example someone could post to the list? Thank you for
your help.
-mike
On Thu, Nov 21, 2002 at 01:55:55PM +1100, Andrew J Bromage
10 matches
Mail list logo