2module Types.Types where
5import Data.Char (isDigit)
6import Data.List (intercalate,isPrefixOf)
7import qualified Data.Set as Set
8import qualified Data.Map as Map
12data Type = LambdaT Type Type
16 | RecordT (Map.Map String [Type]) Type
17 | Super (Set.Set Type)
20data Scheme = Forall [X] [Context Constraint] Type deriving (Eq, Ord)
22data Constraint = Type :=: Type
25 deriving (Eq, Ord, Show)
27recordT :: [(String,Type)] -> Map.Map String [Type]
29 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
31recordOf :: [(String,Type)] -> Type
32recordOf fields = RecordT (recordT fields) EmptyRecord
38number = Super (Set.fromList [ int, float ])
43string = listOf char -- tipe "String"
46time = float --tipe "Time"
51element = tipe "Element"
52direction = tipe "Direction"
57position = tipe "Position"
58location = tipe "Location"
60listOf t = ADT "List" [t]
61signalOf t = ADT "Signal" [t]
62tupleOf ts = ADT ("Tuple" ++ show (length ts)) ts
63maybeOf t = ADT "Maybe" [t]
64eitherOf a b = ADT "Maybe" [a,b]
65pairOf t = tupleOf [t,t]
67appendable t = Super (Set.fromList [ string, text, listOf t ])
68comparable = Super (Set.fromList [ int, float, char, string, time, date ])
71jsNumber = tipe "JSNumber"
72jsString = tipe "JSString"
73jsElement = tipe "JSElement"
74jsArray t = ADT "JSArray" [t]
75jsTuple ts = ADT ("JSTuple" ++ show (length ts)) ts
76jsonValue = tipe "JsonValue"
77jsonObject = tipe "JsonObject"
80t1 ==> t2 = LambdaT t1 t2
83name -: tipe = (,) name $ Forall [] [] tipe
87parens = ("("++) . (++")")
89instance Show Type where
92 { LambdaT t1@(LambdaT _ _) t2 -> parens (show t1) ++ " -> " ++ show t2
93 ; LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
94 ; VarT x -> 't' : show x
95 ; ADT "List" [ADT "Char" []] -> "String"
96 ; ADT "List" [tipe] -> "[" ++ show tipe ++ "]"
99 then parens . intercalate "," $ map show cs
102 _ -> parens $ name ++ " " ++ unwords (map show cs)
103 ; Super ts -> "{" ++ (intercalate "," . map show $ Set.toList ts) ++ "}"
104 ; EmptyRecord -> "{}"
106 start ++ intercalate ", " (concatMap fields $ Map.toList fs) ++ " }"
107 where field n s = n ++ " :: " ++ show s
108 fields (n,ss) = map (field n) ss
111 _ -> "{ " ++ show t ++ " | "
114instance Show Scheme where
115 show (Forall [] [] t) = show t
116 show (Forall xs cs t) =
117 concat [ "Forall ", show xs
118 , concatMap (("\n "++) . show) cs
119 , "\n ", parens (show t) ]
121isTupleString str = "Tuple" `isPrefixOf` str && all isDigit (drop 5 str)
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