-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBasics.hs
86 lines (57 loc) · 1.62 KB
/
Basics.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
module Basics
(module Data.Monoid,
module Control.Applicative,
Sort(..),
above, oneLev, zero,
Ident(..), DisplayContext,
Position, dummyPosition,
isDummyId, modId, synthId, dummyId,
Lattice(..)) where
import Display
import Control.Applicative
import Data.Sequence (Seq)
import Data.Monoid
--------------
-- Ident
instance Pretty Ident where
pretty (Ident _ x) = text x
data Ident = Ident {identPosition :: Position, idString :: String}
deriving (Show,Eq)
isDummyIdS ('_':x) = True
isDummyIdS _ = False
isDummyId (Ident _ xs) = isDummyIdS xs
synthId :: String -> Ident
synthId = Ident dummyPosition
dummyId = synthId "_"
type DisplayContext = Seq Ident
----------------
-- Position
type Position = (Int,Int)
dummyPosition = (0,0)
modId :: (String -> String) -> Ident -> Ident
modId f (Ident pos x) = Ident pos (f x)
------------------
-- Sort
instance Lattice Int where
(⊔) = max
class Lattice a where
(⊔) :: a -> a -> a
instance Ord Sort where
compare (Sort x) (Sort y) = compare x y
newtype Sort = Sort {sortLevel :: Int}
deriving (Eq,Num)
instance Lattice Sort where
x ⊔ Sort (-1) = Sort (-1) -- is this a lattice?
Sort x ⊔ Sort y = Sort (x ⊔ y)
instance Show Sort where
show s = render (pretty s)
instance Pretty Sort where
pretty s = prettyLev s
star = "∗" -- ⋆★*∗
prettyLev (Sort (-1) ) = "□"
prettyLev (Sort 0 ) = star <> mempty
prettyLev (Sort l ) = star <> subscriptPretty l
above (Sort l) = Sort (l + 1)
oneLev = Sort 1
zero = Sort 0