The compiler complains if a polymorphic function recursively calls the same function with a different type parameter.
SSCCE
silly : List a -> String
silly xs =
case xs of
[] ->
"Hello, world!"
x :: rest ->
silly (List.map Just rest)
So we should have silly [1,2,3] = silly [Just 2, Just 3] = silly [Just (Just 3)] = silly [] = "Hello, world!".
Running elm make gives this output:
-- TYPE MISMATCH ------------------------------------------------- src/Silly.elm
The 1st argument to `silly` is not what I expect:
11| silly (List.map Just rest)
^^^^^^^^^^^^^^^^^^
This `map` call produces:
List (Maybe a)
But `silly` needs the 1st argument to be:
List a
For a workaround, the following compiles.
silly : List a -> String
silly xs =
case xs of
[] ->
"Hello, world!"
x :: rest ->
silly2 (List.map Just rest)
silly2 : List a -> String
silly2 = silly
The compiler complains if a polymorphic function recursively calls the same function with a different type parameter.
SSCCE
So we should have
silly [1,2,3] = silly [Just 2, Just 3] = silly [Just (Just 3)] = silly [] = "Hello, world!"
.Running elm make gives this output:
For a workaround, the following compiles.