Could not deduce (Num int) from the context ()

Hamish Mackenzie hamish.k.mackenzie at googlemail.com
Fri Nov 13 18:18:19 EST 2009


Int is a type (types alway start with a capital letter).  Change it to

firstFunction :: Int -> Int

and it should be fine.

Because 'int' starts with a lower case letter the compiler interpreted it as a type variable, so it complained because it was not clear 'int' was a type of class Num.  This will make sense when you get to the type classes stuff.

On 14 Nov 2009, at 09:29, edwin ancaer wrote:

> Hello, 
> 
> I'vo got the following code in leksah: 
> 
> ----------------------------------------------------------------------------
> --
> -- Module      :  Main
> -- Copyright   :
> -- License     :  AllRightsReserved
> --
> -- Maintainer  :
> -- Stability   :
> -- Portability :
> --
> -- |
> --
> -----------------------------------------------------------------------------
> 
> module Main (
> 
> 
> ) where
> firstfunction :: int -> int 
> firstfunction  a =  a * a
> 
> main = putStrLn (show ( firstfunction 5 ))
> 
> 
> Could you please explain why I get the error below, and what does it
> mean? I copied the function definition from Yet another Haskell
> tutorial, page 45 (it's called square there).
> 
> 
> src/Main.hs:20:20:
>    Could not deduce (Num int) from the context ()
>      arising from a use of `*' at src/Main.hs:20:20-24
>    Possible fix:
>      add (Num int) to the context of
>        the type signature for `firstfunction'
>    In the expression: a * a
>    In the definition of `firstfunction': firstfunction a = a * a
> 
> 
> 
> _______________________________________________
> Leksah mailing list
> Leksah at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/leksah




More information about the Leksah mailing list