[Haskell-cafe] ghci and applicative

Paul Keir pkeir at dcs.gla.ac.uk
Fri Jun 12 03:13:18 EDT 2009


Hi,

I'm finding that some data types which use Applicative to
instantiate the Num class, give responses I wasn't expecting
at the ghci prompt. A simple example is list:

import Control.Applicative

instance (Num a) => Num [a] where
 as + bs = (+) <$> as <*> bs
 (*) = undefined;    abs = undefined
 signum = undefined; fromInteger = undefined

f1 = let op = (+) in [1,2,3] `op` [1,1,1]
f2 = let op = (+) in op [1,2,3] [1,1,1]

Functions f1 and f2 give no problems at the ghci prompt.
However if I instead type the body of either interactively,
I get an error:

*Main> let op = (+)
*Main> [1,2,3] `op` [1,1,1]

<interactive>:1:0:
    Couldn't match expected type `Integer' against inferred type `[a]'
    In the first argument of `op', namely `[1, 2, 3]'
    In the expression: [1, 2, 3] `op` [1, 1, 1]
    In the definition of `it': it = [1, 2, 3] `op` [1, 1, 1]

I get the same error message with op [1,2,3] [1,1,1]. Any thoughts?

Thanks,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090612/74790124/attachment.html


More information about the Haskell-Cafe mailing list