on master help sign in
Add type constructor for extensible records.
0d96f82evancz
compiler/Parse/Types.hs+10−3
@@ -84,16 +84,23 @@ typeAlias = do
84 Left msg -> fail msg
84 Left msg -> fail msg
85 Right t -> return (TypeAlias alias [1..n] t : ctor)
85 Right t -> return (TypeAlias alias [1..n] t : ctor)
86 where ctor = case tipe of
86 where ctor = case tipe of
87+ RecordPT extension kvs ->
87− RecordPT _ kvs -> [toConstructor start end alias kvs]
88+ [toConstructor start end alias extension kvs]
88 _ -> []
89 _ -> []
89
90
90−toConstructor start end alias kvs =
91+toConstructor start end alias Nothing kvs =
91 Definition (FnDef alias args (loc (Record rec)))
92 Definition (FnDef alias args (loc (Record rec)))
92 where
93 where
93 loc = pos start end
94 loc = pos start end
94 args = map fst kvs
95 args = map fst kvs
95 rec = map (\a -> (a, [], loc (Var a))) args
96 rec = map (\a -> (a, [], loc (Var a))) args
96−
97+toConstructor start end alias (Just _) kvs =
98+ Definition (FnDef alias (args++["_ext_"]) (loc rec))
99+ where
100+ loc = pos start end
101+ args = map fst kvs
102+ rec = foldl insert (Var "_ext_") (zip args (map (loc . Var) args))
103+ insert e (k,v) = Insert (loc e) k v
97
104
98typeAnnotation :: IParser Def
105typeAnnotation :: IParser Def
99typeAnnotation = TypeAnnotation <$> try start <*> (toType <$> typeExpr)
106typeAnnotation = TypeAnnotation <$> try start <*> (toType <$> typeExpr)