3 , Canonical(..), Aliased(..)
4 , Port(..), getPortType
5 , deepDealias, iteratedDealias, dealias
10import Control.Arrow (second)
12import qualified Data.Map as Map
14import qualified AST.Variable as Var
15import qualified Reporting.Annotation as A
16import qualified Reporting.Region as R
32 | RRecord [(String, Raw)] (Maybe Raw)
36 = Lambda Canonical Canonical
39 | App Canonical [Canonical]
40 | Record [(String, Canonical)] (Maybe Canonical)
41 | Aliased Var.Canonical [(String, Canonical)] (Aliased Canonical)
53 | Signal { root :: t, arg :: t }
57getPortType :: Port tipe -> tipe
64tuple :: R.Region -> [Raw] -> Raw
66 let name = Var.Raw ("_Tuple" ++ show (length types))
68 A.A region (RApp (A.A region (RType name)) types)
75deepDealias :: Canonical -> Canonical
79 Lambda (deepDealias a) (deepDealias b)
85 Record (map (second deepDealias) fields) (fmap deepDealias ext)
87 Aliased _name args tipe' ->
88 deepDealias (dealias args tipe')
94 App (deepDealias f) (map deepDealias args)
97iteratedDealias :: Canonical -> Canonical
100 Aliased _ args realType ->
101 iteratedDealias (dealias args realType)
107dealias :: [(String, Canonical)] -> Aliased Canonical -> Canonical
108dealias args aliasType =
111 dealiasHelp (Map.fromList args) tipe
117dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
118dealiasHelp typeTable tipe =
119 let go = dealiasHelp typeTable in
125 Map.findWithDefault tipe x typeTable
128 Record (map (second go) fields) (fmap go ext)
130 Aliased original args t' ->
131 Aliased original (map (second go) args) t'
137 App (go f) (map go args)
144collectLambdas :: Canonical -> [Canonical]
146 gatherLambda getCanLambda tipe
149gatherLambda :: (t -> Maybe (t,t)) -> t -> [t]
150gatherLambda get tipe =
153 arg : gatherLambda get body
159getRawLambda :: Raw -> Maybe (Raw, Raw)
160getRawLambda (A.A _ tipe) =
162 RLambda arg body -> Just (arg, body)
166getCanLambda :: Canonical -> Maybe (Canonical, Canonical)
169 Lambda arg body -> Just (arg, body)
177instance Binary Canonical where
181 putWord8 0 >> put t1 >> put t2
187 putWord8 2 >> put name
190 putWord8 3 >> put t1 >> put t2
193 putWord8 4 >> put fs >> put ext
195 Aliased var args t ->
196 putWord8 5 >> put var >> put args >> put t
201 0 -> Lambda <$> get <*> get
204 3 -> App <$> get <*> get
205 4 -> Record <$> get <*> get
206 5 -> Aliased <$> get <*> get <*> get
207 _ -> error "Error reading a valid type from serialized string"
210instance Binary t => Binary (Aliased t) where
214 putWord8 0 >> put tipe
217 putWord8 1 >> put tipe
224 _ -> error "Error reading a valid type from serialized string"
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