1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Types
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Types where
20import Data.Generics (mkT, mkQ, everywhereBut)
22import Language.PureScript.Names
23import Language.PureScript.Unknown (Unknown(..))
26 = TUnknown (Unknown Type)
32 | Function [Type] Type
34 | TypeConstructor (Qualified ProperName)
36 | SaturatedTypeSynonym (Qualified ProperName) [Type]
38 | ConstrainedType [(Qualified ProperName, Type)] Type
41 | RCons String Type Type deriving (Show, Eq, Data, Typeable)
43rowToList :: Type -> ([(String, Type)], Type)
44rowToList (RCons name ty row) = let (tys, rest) = rowToList row
45 in ((name, ty):tys, rest)
48rowFromList :: ([(String, Type)], Type) -> Type
49rowFromList ([], r) = r
50rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
52isMonoType :: Type -> Bool
53isMonoType (ForAll _ _) = False
54isMonoType ty = isPolyType ty
56isPolyType :: Type -> Bool
57isPolyType (Array ty) = isMonoType ty
58isPolyType (Object ps) = all isPolyType (map snd . fst $ rowToList ps)
59isPolyType (Function args ret) = all isPolyType args && isPolyType ret
60isPolyType (TypeApp t1 t2) = isMonoType t1 && isMonoType t2
61isPolyType (SaturatedTypeSynonym _ args) = all isPolyType args
62isPolyType (ForAll _ ty) = isPolyType ty
65mkForAll :: [String] -> Type -> Type
66mkForAll = flip . foldl . flip $ ForAll
71replaceTypeVars :: (Data d) => String -> Type -> d -> d
72replaceTypeVars name t = everywhereBut (mkQ False isShadowed) (mkT replaceTypeVar)
74 replaceTypeVar (TypeVar v) | v == name = t
75 replaceTypeVar other = other
76 isShadowed (ForAll v _) | v == name = True
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list