1{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Type where
5import qualified Data.Map as Map
6import qualified SourceSyntax.Helpers as Help
7import SourceSyntax.PrettyPrint
8import Text.PrettyPrint as P
10data Type = Lambda Type Type
14 | Record (Map.Map String [Type]) Type
15 deriving (Eq, Show, Data, Typeable)
17fieldMap :: [(String,Type)] -> Map.Map String [Type]
19 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
21recordOf :: [(String,Type)] -> Type
22recordOf fields = Record (fieldMap fields) EmptyRecord
25listOf t = Data "_List" [t]
27tupleOf :: [Type] -> Type
28tupleOf ts = Data ("_Tuple" ++ show (length ts)) ts
31instance Pretty Type where
34 Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
35 where t:ts = collectLambdas tipe
37 Data "_List" [t] -> P.brackets (pretty t)
39 | Help.isTuple name -> P.parens . P.sep . P.punctuate P.comma $ map prettyParens tipes
40 | otherwise -> P.hang (P.text name) 2 (P.sep $ map prettyParens tipes)
41 EmptyRecord -> P.braces P.empty
42 Record fields ext -> error "not done yet"
46 Lambda arg@(Lambda _ _) body -> P.parens (pretty arg) : collectLambdas body
47 Lambda arg body -> pretty arg : collectLambdas body
50prettyParens 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