[nhc-bugs] Re: type synonym bug
Malcolm Wallace
Malcolm.Wallace@cs.york.ac.uk
Fri, 28 Mar 2003 17:32:01 +0000
Feliks Kluzniak <feliks@crt.se> writes:
> When I tried to compile my large program (which goes through GHC without any
> warnings), I get a bunch of strange error messages. I have managed to
> extract a small example that demonstrates the problem (see below).
>
> I think my function is OK, don't you? In any case the error message seems
> confusing, since the derived type and the given type are shown as identical.
Thanks for the report - this bug is new to us. You are right that nhc98
should accept this program, and that the error message is confusing.
The cause appears to be that nhc98 does not expand the type synonym
type GNode a = a
correctly. Our resident type system hacker will have a look at it, I'm sure.
Regards,
Malcolm
> ------------------------------- The diagnostics:
> $ nhc98 -c SeeStrange.hs
> ====== Errors after type inference/checking:
> Derived type for Main.unknownNodesInEdges at 17:1 can not be unified with
> given type due to (type-variable occurrence check fails)
> Derived:((GEdges a) -> ((GNodes a) -> (GEdges a)))
> Given :((GEdges a) -> ((GNodes a) -> (GEdges a)))
> Type error (type-variable occurrence check fails)
> when trying to apply function at 18:42 to its 2nd argument at 18:65.
>
> Type error (type-variable occurrence check fails)
> when trying to apply function at 18:10 to its 2nd argument at 18:33.
>
> ------------------------------ SeeStrange.hs:
> import List ( nub )
>
> type GNode a = a
>
> type GNodes a = [ GNode a ]
>
>
> type GEdge a = ( GNode a , GNode a )
>
> type GEdges a = [ GEdge a ]
>
>
> -- Find edges that contain occurrences of nodes not given in arg2.
>
> unknownNodesInEdges :: (Eq a) => GEdges a -> GNodes a -> GEdges a
>
> unknownNodesInEdges edges nodes =
> nub (filter (notNode . fst) edges ++ filter (notNode . snd) edges)
> where
> notNode = \x -> notElem x nodes
> ----------------------------------------------------------------------------