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, Show)
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 ])
45element = tipe "Element"
47listOf t = ADT "List" [t]
48signalOf t = ADT "Signal" [t]
49tupleOf ts = ADT ("Tuple" ++ show (length ts)) ts
50maybeOf t = ADT "Maybe" [t]
51eitherOf a b = ADT "Either" [a,b]
52pairOf t = tupleOf [t,t]
54appendable t = Super (Set.fromList [ string, text, listOf (VarT t) ])
55--comparable = Super (Set.fromList [ int, float, char, string, time, date ])
58t1 ==> t2 = LambdaT t1 t2
61name -: tipe = (,) name $ Forall [] [] tipe
63parens = ("("++) . (++")")
65instance Show Type where
67 let show' t = case t of { LambdaT _ _ -> parens (show t) ; _ -> show t }
69 LambdaT t1@(LambdaT _ _) t2 -> show' t1 ++ " -> " ++ show t2
70 LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
71 VarT x -> 't' : show x
72 --ADT "List" [ADT "Char" []] -> "String"
73 ADT "List" [tipe] -> "[" ++ show tipe ++ "]"
76 then parens . intercalate "," $ map show cs
79 _ -> name ++ " " ++ unwords (map show cs)
80 Super ts -> "{" ++ (intercalate "," . map show $ Set.toList ts) ++ "}"
83 start ++ intercalate ", " (concatMap fields $ Map.toList fs) ++ " }"
84 where field n s = n ++ " : " ++ show s
85 fields (n,ss) = map (field n) ss
88 _ -> "{ " ++ show t ++ " | "
91isTupleString 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