[Haskell-cafe] First time haskell - parse error!
Kyle Murphy
orclev at gmail.com
Tue Mar 9 18:02:00 EST 2010
Seems like a good time to mention the Maybe monad looks like it would be a
good fit here.
score :: String -> String -> Maybe String
score s [] = Nothing
score s g =
if valid 4 g
then let s1 = "Golds "
s2 = show (gold s g)
s3 = ", Silvers "
s4 = show (silver s g)
in Just (s1 ++ s2 ++ s3 ++ s4)
else Just "Bad Guess"
-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.
On Tue, Mar 9, 2010 at 17:42, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> On Tue, Mar 09, 2010 at 08:42:44PM +0100, Sebastian Hungerecker wrote:
> > On 09.03.2010 20:04, boblettoj wrote:
> >> score :: String -> String -> String
> >> score [s] [] = false
> >> score [s] [g] =
> >> if valid 4 g
> >> then (s1 ++ s2 ++ s3 ++ s4) where
> >> s1 = "Golds "
> >> s2 = show (gold s g)
> >> s3 = ", Silvers "
> >> s4 = show (silver s g)
> >> else "Bad Guess"
> >>
> >
> > Apart from the parse error there is also a type error
> > in your code:
> > When the second argument is empty, you return false
> > although you declared the function to return a String,
> > not a boolean.
>
> Not quite; data Bool = True | False, and the code uses a lowercase 'f'
> 'false'. Perhaps 'false' is defined as a String somewhere else? A bit
> odd, perhaps, but not necessarily a type error.
>
> -Brent
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100309/940de563/attachment.html
More information about the Haskell-Cafe
mailing list