The problem is with all 3 lines taken together:
somefunction a [] = [a]:[]
somefunction [] b = [b]:[]
somefunction (x:xs) (y:ys) = x:[y]
None of them are incorrect taken on their own. The problem is that the three equations are inconsistent about the return type of somefunction
.
From the last equation, we can see that both arguments are lists (since you pattern match on them using the list constructor :
).
From the last equation, we can see that the return type is a list whose elements must be the same type as the elements of the argument lists (which must also both be the same type), since the return value is x:[y]
(which is more often written [x, y]
; just the list containing only the two elements x
and y
) and x
and y
were elements of the argument lists. So if x
has type t0
, the arguments to somefunction
both have type [t0]
and the return type is [t0]
.
Now try to apply those facts to the first equation. a
must be a list. So [a]
(the list containing exactly one element a
) must be a list of lists. And then [a]:[]
(the list whose first element is [a]
and whose tail is empty - also written [[a]]
) must be a list of lists of lists! If the parameter a
has type [t0]
(to match the type we figured out from looking at the last equation), then [a]
has type [[t0]]
and [a]:[]
(or [[a]]
) has type [[[t0]]]
, which is the return type we get from this equation.
To reconcile what we learned from those two equations we need to find some type expression to use for t0
such that [t0] = [[[t0]]]
, which also requires that t0 = [[t0]]
. This is impossible, which is what the error message Occurs check: cannot construct the infinite type: t0 = [[t0]]
was about.
If your intention was to return one of the parameters as-is when the other one is empty, then you need something more like:
somefunction a [] = a
somefunction [] b = b
somefunction (x:xs) (y:ys) = [x, y]
Or it's possible that the first two equations were correct (you intend to return a list of lists of lists?), in which case the last one needs to be modified. Without knowing what you wanted the function to do, I can't say.