1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Types
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- Data types for types
14-----------------------------------------------------------------------------
16{-# LANGUAGE DeriveDataTypeable #-}
18module Language.PureScript.Types where
21import Data.Generics (mkT, mkQ, everywhereBut)
23import Control.Monad.Unify
25import Language.PureScript.Names
32 -- A unification variable of type Type
34 = TUnknown (TypedUnknown Type)
44 -- Javascript booleans
48 -- Javascript array type constructor
52 -- Records, parameterized by a row of types
56 -- A function, with zero or more arguments
60 -- A named type variable
66 | TypeConstructor (Qualified ProperName)
72 -- A type synonym which is \"saturated\", i.e. fully applied
74 | SaturatedTypeSynonym (Qualified ProperName) [Type]
80 -- A type with a set of type class constraints
82 | ConstrainedType [(Qualified ProperName, Type)] Type
94 | RCons String Type Type deriving (Show, Eq, Data, Typeable)
97-- Smart constructor for function types
99function :: Type -> Type -> Type
100function t1 t2 = TypeApp (TypeApp Function t1) t2
103-- Convert a row to a list of pairs of labels and types
105rowToList :: Type -> ([(String, Type)], Type)
106rowToList (RCons name ty row) = let (tys, rest) = rowToList row
107 in ((name, ty):tys, rest)
111-- Convert a list of labels and types to a row
113rowFromList :: ([(String, Type)], Type) -> Type
114rowFromList ([], r) = r
115rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
118-- Check whether a type is a monotype
120isMonoType :: Type -> Bool
121isMonoType (ForAll _ _) = False
125-- Universally quantify a type
127mkForAll :: [String] -> Type -> Type
128mkForAll = flip . foldl . flip $ ForAll
131-- The empty record type
137-- Replace a type variable, taking into account variable shadowing
139replaceTypeVars :: (Data d) => String -> Type -> d -> d
140replaceTypeVars name t = everywhereBut (mkQ False isShadowed) (mkT replaceTypeVar)
142 replaceTypeVar (TypeVar v) | v == name = t
143 replaceTypeVar other = other
144 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