git.iko.soy/rowtype-yoga/purescript-native
on f6055cb help sign in
69 lines 1.9 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Types
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Types where
19import Data.Data
20import Language.PureScript.Names
22data Type
23 = TUnknown Int
24 | Number
25 | String
26 | Boolean
27 | Array Type
28 | Object Row
29 | Function [PolyType] Type
30 | TypeVar String
31 | TypeConstructor (Qualified ProperName)
32 | TypeApp Type Type
33 | SaturatedTypeSynonym (Qualified ProperName) [Type]
34 | ForAll [String] Type
35 | Skolem Int deriving (Show, Eq, Data, Typeable)
37type PolyType = Type
39data Row
40 = RUnknown Int
41 | RowVar String
42 | REmpty
43 | RCons String Type Row deriving (Show, Eq, Data, Typeable)
45typesToRow :: [(String, Type)] -> Row
46typesToRow [] = REmpty
47typesToRow ((name, ty):tys) = RCons name ty (typesToRow tys)
49rowToList :: Row -> ([(String, Type)], Row)
50rowToList (RCons name ty row) = let (tys, rest) = rowToList row
51 in ((name, ty):tys, rest)
52rowToList r = ([], r)
54rowFromList :: ([(String, Type)], Row) -> Row
55rowFromList ([], r) = r
56rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
58isMonoType :: Type -> Bool
59isMonoType (ForAll _ _) = False
60isMonoType ty = isPolyType ty
62isPolyType :: Type -> Bool
63isPolyType (Array ty) = isMonoType ty
64isPolyType (Object ps) = all isMonoType (map snd . fst $ rowToList ps)
65isPolyType (Function args ret) = all isPolyType args && isMonoType ret
66isPolyType (TypeApp t1 t2) = isMonoType t1 && isMonoType t2
67isPolyType (SaturatedTypeSynonym _ args) = all isMonoType args
68isPolyType (ForAll idents ty) = isPolyType ty
69isPolyType _ = True