1{-# LANGUAGE DeriveDataTypeable #-}
2module Types.Types where
4import SourceSyntax.Location
5import Data.Char (isDigit)
6import Data.List (intercalate,isPrefixOf)
7import qualified Data.Set as Set
8import qualified Data.Map as Map
13data Type = LambdaT Type Type
17 | RecordT (Map.Map String [Type]) Type
18 | Super (Set.Set Type)
19 deriving (Eq, Ord, Data, Typeable)
21data Scheme = Forall [X] [Located Constraint] Type
22 deriving (Eq, Ord, Show, Data, Typeable)
24data Constraint = Type :=: Type
27 deriving (Eq, Ord, Show, Data, Typeable)
29recordT :: [(String,Type)] -> Map.Map String [Type]
31 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
33recordOf :: [(String,Type)] -> Type
34recordOf fields = RecordT (recordT fields) EmptyRecord
49number = Super $ Set.fromList [ int, float, time ]
50appendable t = Super $ Set.fromList [ string, text, listOf (VarT t) ]
51comparable t = Super $ Set.fromList [ int, float, char, string, time, date ]
53element = tipe "Element"
55listOf t = ADT "List" [t]
56signalOf t = ADT "Signal" [t]
57tupleOf ts = ADT ("Tuple" ++ show (length ts)) ts
58maybeOf t = ADT "Maybe" [t]
59eitherOf a b = ADT "Either" [a,b]
60pairOf t = tupleOf [t,t]
64t1 ==> t2 = LambdaT t1 t2
67name -: tipe = (,) name $ Forall [] [] tipe
69parens = ("("++) . (++")")
71instance Show Type where
73 let addParens (c:cs) =
74 if notElem ' ' cs || c == '(' || c == '{' then c:cs else parens (c:cs)
76 LambdaT t1@(LambdaT _ _) t2 -> parens (show t1) ++ " -> " ++ show t2
77 LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
78 VarT x -> 't' : show x
79 ADT "List" [ADT "Char" []] -> "String"
80 ADT "List" [tipe] -> "[" ++ show tipe ++ "]"
83 then parens . intercalate "," $ map show cs
84 else name ++ concatMap ((' ':) . addParens . show) cs
85 Super ts -> "{" ++ (intercalate "," . map show $ Set.toList ts) ++ "}"
88 start ++ intercalate ", " (concatMap fields $ Map.toList fs) ++ " }"
89 where field n s = n ++ " : " ++ show s
90 fields (n,ss) = map (field n) ss
93 _ -> "{ " ++ show t ++ " | "
96isTupleString 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