Search code examples
haskellpolymorphismghcityping

Type of list ranges: how can I make my function less polymorphic?


I have a function

sasiad (x,y) = [ (x+dx,y+dy) | dy <- [-1..1], dx <- [-1..1], x+dx >= 0, y+dy >= 0]

I don't like the type of that function. I would like it to return [(Int,Int)] instead of [(t,t1)] Is it possible to force ghci to make that?


Solution

  • Yes, add a type annotation:

    sasiad (x,y) = [ (x+dx,y+dy) | dy <- [-1..1], dx <- [-1..1], x+dx >= 0, y+dy >= 0] :: [(Int, Int)]