1{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Type where
5import qualified Data.Map as Map
6import SourceSyntax.PrettyPrint
7import Text.PrettyPrint as P
9data Type = Lambda Type Type
13 | Record (Map.Map String [Type]) Type
14 deriving (Eq, Show, Data, Typeable)
16fieldMap :: [(String,Type)] -> Map.Map String [Type]
18 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
20recordOf :: [(String,Type)] -> Type
21recordOf fields = Record (fieldMap fields) EmptyRecord
24listOf t = Data "List" [t]
26tupleOf :: [Type] -> Type
27tupleOf ts = Data ("_Tuple" ++ show (length ts)) ts
30instance Pretty Type where
33 Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
34 where t:ts = collectLambdas tipe
36 Data name tipes -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
37 EmptyRecord -> P.braces P.empty
38 Record fields ext -> error "not done yet"
42 Lambda arg@(Lambda _ _) body -> P.parens (pretty arg) : collectLambdas body
43 Lambda arg body -> pretty arg : collectLambdas body
46prettyParens tipe = parensIf needed (pretty tipe)
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