1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
5 , Canonical(..), Aliased(..)
7 , deepDealias, iteratedDealias, dealias
13import Control.Arrow (second)
14import Control.Monad (liftM, liftM2, liftM3, replicateM)
16import qualified Data.Map as Map
17import Data.Text (Text)
19import qualified AST.Module.Name as ModuleName
20import qualified AST.Variable as Var
21import qualified Reporting.Annotation as A
22import qualified Reporting.Region as R
36 | RType R.Region (Maybe Text) Text [Raw]
37 | RRecord [(A.Located Text, Raw)] (Maybe Raw)
39 | RTuple Raw Raw [Raw]
43 = Lambda Canonical Canonical
45 | Type Var.Canonical [Canonical]
46 | Record [(Text, Canonical)] (Maybe Canonical)
48 | Tuple Canonical Canonical [Canonical]
49 | Aliased Var.Canonical [(Text, Canonical)] (Aliased Canonical)
68-- CONSTRUCT USEFUL TYPES
71cmd :: ModuleName.Canonical -> Text -> Canonical
76sub :: ModuleName.Canonical -> Text -> Canonical
81effect :: Var.Canonical -> ModuleName.Canonical -> Text -> Canonical
82effect effectName moduleName tipe =
84 (Type (Var.fromModule moduleName tipe) [Var "msg"])
85 (Type effectName [Var "msg"])
92deepDealias :: Canonical -> Canonical
96 Lambda (deepDealias a) (deepDealias b)
102 Record (map (second deepDealias) fields) (fmap deepDealias ext)
104 Aliased _name args tipe' ->
105 deepDealias (dealias args tipe')
108 Type name (map deepDealias args)
114 Tuple (deepDealias a) (deepDealias b) (map deepDealias cs)
117iteratedDealias :: Canonical -> Canonical
118iteratedDealias tipe =
120 Aliased _ args realType ->
121 iteratedDealias (dealias args realType)
127dealias :: [(Text, Canonical)] -> Aliased Canonical -> Canonical
128dealias args aliasType =
131 dealiasHelp (Map.fromList args) tipe
137dealiasHelp :: Map.Map Text Canonical -> Canonical -> Canonical
138dealiasHelp typeTable tipe =
141 dealiasHelp typeTable
148 Map.findWithDefault tipe x typeTable
151 Record (map (second go) fields) (fmap go ext)
153 Aliased original args t' ->
154 Aliased original (map (second go) args) t'
157 Type name (map go args)
163 Tuple (go a) (go b) (map go cs)
170collectLambdas :: Canonical -> [Canonical]
174 arg : collectLambdas result
184instance Binary Canonical where
187 Lambda t1 t2 -> putWord8 0 >> put t1 >> put t2
188 Var x -> putWord8 1 >> put x
189 Record fs ext -> putWord8 2 >> put fs >> put ext
191 Tuple a b cs -> putWord8 4 >> put a >> put b >> put cs
192 Aliased var args t -> putWord8 5 >> put var >> put args >> put t
198 if potentialWord <= fromIntegral (maxBound :: Word8) then
199 do putWord8 (fromIntegral potentialWord)
203 putWord8 6 >> put name >> put ts
208 0 -> liftM2 Lambda get get
210 2 -> liftM2 Record get get
212 4 -> liftM3 Tuple get get get
213 5 -> liftM3 Aliased get get get
214 6 -> liftM2 Type get get
215 n -> liftM2 Type get (replicateM (fromIntegral (n - 7)) get)
218instance Binary t => Binary (Aliased t) where
222 putWord8 0 >> put tipe
225 putWord8 1 >> put tipe
231 1 -> liftM Filled get
232 _ -> 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