[cvs-nhc98] cvs commit: nhc98/src/compiler98 NT.hs TypeUnify.hs

olaf@glass.cse.ogi.edu olaf@glass.cse.ogi.edu
Tue, 1 Apr 2003 05:54:37 -0800


olaf        2003/04/01 05:54:36 PST

  Modified files:
    src/compiler98       NT.hs TypeUnify.hs 
  Log:
  Remove another bug in type checker with respect to type synonyms.
  
  The program below did not type check (occurrence check failure), because the type checker did not expand type synonyms before doing the occurrence check. Expansion of a type can lead to a type with less type variables, or in this case the type to be substituted is just a simple type variable.
  
  In turned out that for the latter handling of type class contexts it is important that a substitution never replaces a variable by a type that is not a type variable but becomes a type variable after type synonym expansion. So unification assures that the resulting substitution meets this constraint.
  
  There may still be further errors with respect to unexpanded type synonyms in nhc98. Simply exanding all first would avoid all the problems, but also lead to less readable type error messages.
  
  -- begin
  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
  
  Revision  Changes    Path
  1.6       +7 -1      nhc98/src/compiler98/NT.hs
  1.9       +36 -26    nhc98/src/compiler98/TypeUnify.hs