0
votes

I'm trying to write a simple path-finding function, but I'm having trouble with an ambiguous Haskell error.

This is my code (simplified to point out the error)

routes :: int -> int -> [(int,int)] -> [[int]]
routes start finish waypoints = [[4]]

And this is the error I'm getting

ERROR "/home/freefrag/Routes":2 - Cannot justify constraints in explicitly typed binding
*** Expression    : routes
*** Type          : a -> a -> [(a,a)] -> [[a]]
*** Given context : ()
*** Constraints   : Num a

can someone let me know what I'm doing wrong?

2
int is a universally quantified type variable, not the type of integer values. - danportin
Oh you're right, thanks a lot! - Maciek

2 Answers

4
votes

Capitalize your types. Like this:

routes :: Int -> Int -> [(Int,Int)] -> [[Int]]
routes start finish waypoints = [[4]]

Types start with uppercase letters. Type variables start with lowercase letters.

1
votes

Do you mean?:

Int -> Int -> [(Int, Int)] -> [[Int]] 

Otherwise, try:

routes :: Num int => int -> int -> [(int,int)] -> [[int]]
routes start finish waypoints = [[4]]

See section 2.4, Identifiers and Operators, in The Haskell 98 Report. It reads quote:

"Identifiers are lexically distinguished into two namespaces (Section 1.4): those that begin with a lower-case letter (variable identifiers) and those that begin with an upper-case letter (constructor identifiers)."