Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why not?

Name: Anonymous 2011-10-06 13:28


$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> let yoba a b = if a < b then 123 else "abc"

<interactive>:1:29:
    No instance for (Num [Char])
      arising from the literal `123' at <interactive>:1:29-31
    Possible fix: add an instance declaration for (Num [Char])
    In the expression: if a < b then 123 else "abc"
    In the definition of `yoba':
        yoba a b = if a < b then 123 else "abc"
Prelude>

Name: Anonymous 2011-10-06 14:50

If you really need to do that (which I'm sure you don't), use Either.

yoba :: (Ord a) => a -> a -> Either Int String
yoba a b | a < b     = Left 123
         | otherwise = Right "abc"

f :: (Ord a) => a -> a -> String
f a b = case yoba a b of
            Left _  -> "something"
            Right _ -> "something else"

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List