1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
5 , Canonical(..), Aliased(..)
7 , deepDealias, iteratedDealias, dealias
14import Control.Monad (liftM, liftM2, liftM3, liftM4, replicateM)
16import qualified Data.Map as Map
18import qualified AST.Module.Name as ModuleName
20import qualified Reporting.Annotation as A
21import qualified Reporting.Region as R
35 | RType R.Region (Maybe Name) Name [Raw]
36 | RRecord [(A.Located Name, Raw)] (Maybe Raw)
38 | RTuple Raw Raw [Raw]
42 = Lambda Canonical Canonical
44 | Type ModuleName.Canonical Name [Canonical]
45 | Record (Map.Map Name Canonical) (Maybe Canonical)
47 | Tuple Canonical Canonical [Canonical]
48 | Aliased ModuleName.Canonical Name [(Name, Canonical)] (Aliased Canonical)
67-- CONSTRUCT USEFUL TYPES
70cmd :: ModuleName.Canonical -> Name -> Canonical
73 (Type moduleName tipe [Var "msg"])
74 (Type (ModuleName.inCore "Platform.Cmd") "Cmd" [Var "msg"])
77sub :: ModuleName.Canonical -> Name -> Canonical
80 (Type moduleName tipe [Var "msg"])
81 (Type (ModuleName.inCore "Platform.Sub") "Sub" [Var "msg"])
88deepDealias :: Canonical -> Canonical
92 Lambda (deepDealias a) (deepDealias b)
98 Record (Map.map deepDealias fields) (fmap deepDealias ext)
100 Aliased _ _ args tipe' ->
101 deepDealias (dealias args tipe')
103 Type home name args ->
104 Type home name (map deepDealias args)
110 Tuple (deepDealias a) (deepDealias b) (map deepDealias cs)
113iteratedDealias :: Canonical -> Canonical
114iteratedDealias tipe =
116 Aliased _ _ args realType ->
117 iteratedDealias (dealias args realType)
123dealias :: [(Name, Canonical)] -> Aliased Canonical -> Canonical
124dealias args aliasType =
127 dealiasHelp (Map.fromList args) tipe
133dealiasHelp :: Map.Map Name Canonical -> Canonical -> Canonical
134dealiasHelp typeTable tipe =
137 dealiasHelp typeTable
144 Map.findWithDefault tipe x typeTable
147 Record (Map.map go fields) (fmap go ext)
149 Aliased home name args t' ->
150 Aliased home name (map (fmap go) args) t'
152 Type home name args ->
153 Type home name (map go args)
159 Tuple (go a) (go b) (map go cs)
166collectLambdas :: Canonical -> [Canonical]
170 arg : collectLambdas result
180instance Binary Canonical where
183 Lambda a b -> putWord8 0 >> put a >> put b
184 Var a -> putWord8 1 >> put a
185 Record a b -> putWord8 2 >> put a >> put b
187 Tuple a b c -> putWord8 4 >> put a >> put b >> put c
188 Aliased a b c d -> putWord8 5 >> put a >> put b >> put c >> put d
194 if potentialWord <= fromIntegral (maxBound :: Word8) then
195 do putWord8 (fromIntegral potentialWord)
200 putWord8 6 >> put home >> put name >> put ts
205 0 -> liftM2 Lambda get get
207 2 -> liftM2 Record get get
209 4 -> liftM3 Tuple get get get
210 5 -> liftM4 Aliased get get get get
211 6 -> liftM3 Type get get get
212 n -> liftM3 Type get get (replicateM (fromIntegral (n - 7)) get)
215instance Binary t => Binary (Aliased t) where
219 putWord8 0 >> put tipe
222 putWord8 1 >> put tipe
228 1 -> liftM Filled get
229 _ -> 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