Type specification error

#1

I’m encountering a baffling type error involving the following function:

roll :: Int -> Int -> (List Int -> Int) -> Effect Int
roll m n s = s <$> (sequence $ replicate n $ randomInt 1 m)

the error is

  Could not match type

    List

  with type

    List

while trying to match type List Int
  with type List Int
while checking that expression (apply sequence) ((apply (replicate n)) ((randomInt 1) m))
  has type t0 (List Int)
in value declaration roll

where t0 is an unknown type

when I remove the type signature and check the type, it’s

forall a. Int -> Int -> (List Int -> a) -> Effect a

Am I not allowed to specify the type further?

#2

It’s hard to know without seeing the whole file, but you are probably mixing up strict and lazy lists (strict data type, with the lazy functions or vice versa). The error isn’t printing the qualification. It’s confusing.

1 Like
#3
import Data.List.Lazy.Types as L
...
roll :: Int -> Int -> (L.List Int -> Int) -> Effect Int

seemed to do the trick, so I guess laziness was the issue.

Thanks!

#4

We have an issue for this, it’s definitely a pretty common problem! It’s high on my list of things-to-fix-when-I-get-a-chance.

2 Likes