1

I have a function which has this type by default :

func :: Integer -> (Integer,Integer) -> [[String]] -> ([Char],[Char],[Char],[Char]) -> (Integer,Integer)

But I want it to return (Int,Int) When I wrote this :

func:: Integer -> (Integer,Integer) -> [[String]] -> ([Char],[Char],[Char],[Char]) -> (Int,Int) 

I get this error : Main> :l play

ERROR "play.hs":64 - Type error in explicitly typed binding
*** Term           : func
*** Type           : Integer -> (Integer,Integer) -> [[String]] -> ([Char],[Char],[Char],[Char]) -> (Integer,Integer)
*** Does not match : Integer -> (Integer,Integer) -> [[String]] -> ([Char],[Char],[Char],[Char]) -> (Int,Int)

How can I fix this? Thanks.

2
  • Int is not Integer. Haskell has no implicit conversion between numeric types. Commented Mar 30, 2013 at 14:35
  • @nymk Do you have any suggestion to fix it? Thanks. Commented Mar 30, 2013 at 14:37

1 Answer 1

3

Write a new wrapper function to wrap func, then use the wrapper function instead.

func' :: Integer ->
         (Integer,Integer) ->
         [[String]] ->
         ([Char],[Char],[Char],[Char]) ->
         (Int,Int)
func' a b c d = (fromInteger x, fromInteger y) where
    (x, y) = func a b c d

Alternatively, you could insert the calls to fromInteger directly into func.

The issue here is that Int and Integer are different types, and the compiler does not convert between them implicitly --- you have to do so explicitly, hence the calls to fromInteger. fromInteger converts from Integer to any numeric type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.