···127127128128-- And primitive functions have a type and a javascript definition:
129129130130-pfunc plusInt : Int -> Int -> Int := `(x,y) => x + y`
131131-pfunc plusString : String -> String -> String := `(x,y) => x + y`
130130+pfunc addInt : Int -> Int -> Int := `(x,y) => x + y`
131131+pfunc addString : String -> String -> String := `(x,y) => x + y`
132132133133--- We can make them Plus instances:
134133135134instance Add Int where
136136- _+_ = plusInt
135135+ _+_ = addInt
137136138138-instance Add String where
139139- _+_ = plusString
137137+138138+infixr 7 _++_
139139+class Concat a where
140140+ _++_ : a → a → a
140141141141-concat : String -> String -> String
142142-concat a b = a + b
142142+instance Concat String where
143143+ _++_ = addString
144144+145145+143146144147-- Now we define Monad
145148class Monad (m : U -> U) where
···172175_>>_ : ∀ m a b. {{Monad m}} -> m a -> m b -> m b
173176ma >> mb = ma >>= (λ _ => mb)
174177175175--- Now we define list and show it is a monad. At the moment, I don't
176176--- have sugar for Lists,
178178+-- Now we define list and show it is a monad.
177179178180infixr 3 _::_
179181data List : U -> U where
180182 Nil : ∀ A. List A
181183 _::_ : ∀ A. A -> List A -> List A
182182-183183-infixr 7 _++_
184184-_++_ : ∀ a. List a -> List a -> List a
185185-Nil ++ ys = ys
186186-(x :: xs) ++ ys = x :: (xs ++ ys)
187184188185instance Monad List where
189186 pure a = a :: Nil
190187 bind Nil f = Nil
191188 bind (x :: xs) f = f x ++ bind xs f
192189193193-/-
194194-This desugars to: (the names in guillemots are not user-accessible)
190190+-- and has the _++_ operator
195191196196-«Monad List,pure» : { a : U } -> a:0 -> List a:1
197197-pure a = _::_ a Nil
192192+instance ∀ a. Concat (List a) where
193193+ Nil ++ ys = ys
194194+ (x :: xs) ++ ys = x :: (xs ++ ys)
198195199199-«Monad List,bind» : { a : U } -> { b : U } -> (List a) -> (a -> List b) -> List b
200200-bind Nil f = Nil bind (_::_ x xs) f = _++_ (f x) (bind xs f)
196196+-- A utility function used in generating Show instances below:
201197202202-«Monad List» : Monad List
203203-«Monad List» = MkMonad «Monad List,pure» «Monad List,bind»
204204-205205--/
198198+joinBy : String → List String → String
199199+joinBy _ Nil = ""
200200+joinBy _ (x :: Nil) = x
201201+joinBy s (x :: y :: xs) = joinBy s ((x ++ s ++ y) :: xs)
206202207207--- We'll want Pair below. `,` has been left for use as an operator.
208208--- Also we see that → can be used in lieu of ->
203203+-- We define a product of two types (→ can be used in lieu of ->)
209204infixr 1 _,_ _×_
210205data _×_ : U → U → U where
211206 _,_ : ∀ A B. A → B → A × B
···218213 y <- ys
219214 pure (x, y)
220215216216+-- The prelude defines Eq and Show, which can be derived
217217+218218+infixl 6 _==_
219219+class Eq a where
220220+ _==_ : a → a → Bool
221221+222222+derive Eq Nat
223223+224224+class Show a where
225225+ show : a → String
226226+227227+derive Show Nat
221228222229data Unit = MkUnit
223230···235242236243pfunc putStrLn uses (MkIORes MkUnit) : String -> IO Unit := `(s) => (w) => {
237244 console.log(s)
238238- return Prelude_MkIORes(null,Prelude_MkUnit,w)
245245+ return Tour_MkIORes(Tour_MkUnit, w)
239246}`
240247241248main : IO Unit
242242-main = putStrLn "Hello, World!"
249249+main = do
250250+ putStrLn "Hello, World!"
251251+ putStrLn $ show (S (S Z))
···100100 neutral = MkResult Nil
101101102102data UnifyMode = UNormal | UPattern
103103-instance Show UnifyMode where
104104- show UNormal = "UNormal"
105105- show UPattern = "UPattern"
103103+derive Show UnifyMode
106104107105check : Context -> Raw -> Val -> M Tm
108106
+1-1
src/Lib/Eval.newt
···105105 top <- getTop
106106 if nm == name
107107 then do
108108- debug $ \ _ => "ECase \{show nm} \{show sp} \{show nms} \{showTm t}"
108108+ debug $ \ _ => "ECase \{show nm} \{show sp} \{show nms} \{show t}"
109109 pushArgs env (sp <>> Nil) nms
110110 else case lookup nm top of
111111 (Just (MkEntry _ str type (DCon _ _ k str1) _)) => evalCase env sc xs
+1-1
src/Lib/ProcessDecl.newt
···306306 debug $ \ _ => "dcty \{render 90 $ pprint Nil dcty}"
307307 let (_,args) = funArgs codomain
308308309309- debug $ \ _ => "traverse \{show $ map showTm args}"
309309+ debug $ \ _ => "traverse \{show $ map show args}"
310310 -- This is a little painful because we're reverse engineering the
311311 -- individual types back out from the composite type
312312 args' <- traverse (eval env) args
+9-60
src/Lib/Syntax.newt
···123123 imports : List Import
124124 decls : List Decl
125125126126-foo : List String -> String
127127-foo ts = "(" ++ unwords ts ++ ")"
128128-129126instance Show Raw
130127131131-instance Show Clause where
132132- show (MkClause fc cons pats expr) = show (fc, cons, pats, expr)
133133-134134-instance Show Import where
135135- show (MkImport _ str) = foo ("MkImport" :: show str :: Nil)
136136-137137-instance Show BindInfo where
138138- show (BI _ nm icit quant) = foo ("BI" :: show nm :: show icit :: show quant :: Nil)
139139-140140--- this is for debugging, use pretty when possible
141141-142142-instance Show Decl where
143143- show (TypeSig _ str x) = foo ("TypeSig" :: show str :: show x :: Nil)
144144- show (DDerive _ x y) = foo ("DDerive" :: show x :: show y :: Nil)
145145- show (FunDef _ str clauses) = foo ("FunDef" :: show str :: show clauses :: Nil)
146146- show (Data _ str xs ys) = foo ("Data" :: show str :: show xs :: show ys :: Nil)
147147- show (DCheck _ x y) = foo ("DCheck" :: show x :: show y :: Nil)
148148- show (PType _ name ty) = foo ("PType" :: name :: show ty :: Nil)
149149- show (ShortData _ lhs sigs) = foo ("ShortData" :: show lhs :: show sigs :: Nil)
150150- show (PFunc _ nm used ty src) = foo ("PFunc" :: nm :: show used :: show ty :: show src :: Nil)
151151- show (PMixFix _ nms prec fix) = foo ("PMixFix" :: show nms :: show prec :: show fix :: Nil)
152152- show (Class _ (_,nm) tele decls) = foo ("Class" :: nm :: "..." :: (show $ map show decls) :: Nil)
153153- show (Instance _ nm decls) = foo ("Instance" :: show nm :: (show $ map show decls) :: Nil)
154154- show (Record _ nm tele nm1 decls) = foo ("Record" :: show nm :: show tele :: show nm1 :: show decls :: Nil)
155155- show (Exports _ nms) = foo ("Exports" :: show nms :: Nil)
156156-157157-158158-instance Show Module where
159159- show (MkModule name imports decls) = foo ("MkModule" :: show name :: show imports :: show decls :: Nil)
160160-161161-162162-instance Show RCaseAlt where
163163- show (MkAlt x y)= foo ("MkAlt" :: show x :: show y :: Nil)
164164-165165-instance Show UpdateClause where
166166- show (ModifyField _ nm tm) = foo ("ModifyField" :: nm :: show tm :: Nil)
167167- show (AssignField _ nm tm) = foo ("AssignField" :: nm :: show tm :: Nil)
168168-169169-instance Show Raw where
170170- show (RImplicit _) = "_"
171171- show (RImpossible _) = "()"
172172- show (RHole _) = "?"
173173- show (RUpdateRec _ clauses tm) = foo ("RUpdateRec" :: show clauses :: show tm :: Nil)
174174- show (RVar _ name) = foo ("RVar" :: show name :: Nil)
175175- show (RLit _ x) = foo ( "RLit" :: show x :: Nil)
176176- show (RLet _ x ty v scope) = foo ( "Let" :: show x :: " : " :: show ty :: " = " :: show v :: " in " :: show scope :: Nil)
177177- show (RPi _ bi y z) = foo ( "Pi" :: show bi :: show y :: show z :: Nil)
178178- show (RApp _ x y z) = foo ( "App" :: show x :: show y :: show z :: Nil)
179179- show (RLam _ bi y) = foo ( "Lam" :: show bi :: show y :: Nil)
180180- show (RCase _ x Nothing xs) = foo ( "Case" :: show x :: " of " :: show xs :: Nil)
181181- show (RCase _ x (Just ty) xs) = foo ( "Case" :: show x :: " : " :: show ty :: " of " :: show xs :: Nil)
182182- show (RDo _ stmts) = foo ( "DO" :: "FIXME" :: Nil)
183183- show (RU _) = "U"
184184- show (RIf _ x y z) = foo ( "If" :: show x :: show y :: show z :: Nil)
185185- show (RWhere _ _ _) = foo ( "Where" :: "FIXME" :: Nil)
186186- show (RAs _ nm x) = foo ( "RAs" :: nm :: show x :: Nil)
187187-128128+derive Show Clause
129129+derive Show Import
130130+derive Show BindInfo
131131+derive Show DoStmt
132132+derive Show Decl
133133+derive Show Module
134134+derive Show RCaseAlt
135135+derive Show UpdateClause
136136+derive Show Raw
188137189138instance Pretty Literal where
190139 pretty (LString t) = text t
+4-38
src/Lib/Token.newt
···1313 | StringKind
1414 | JSLit
1515 | Symbol
1616- | Space
1717- | Comment
1816 | Pragma
1917 | Projection
2020- -- not doing Layout.idr
2121- | LBrace
2222- | Semi
2323- | RBrace
2424- | EOI
2518 | StartQuote
2619 | EndQuote
2720 | StartInterp
2821 | EndInterp
29223030-3131-instance Show Kind where
3232- show Ident = "Ident"
3333- show UIdent = "UIdent"
3434- show Keyword = "Keyword"
3535- show MixFix = "MixFix"
3636- show Number = "Number"
3737- show Character = "Character"
3838- show Symbol = "Symbol"
3939- show Space = "Space"
4040- show LBrace = "LBrace"
4141- show Semi = "Semi"
4242- show RBrace = "RBrace"
4343- show Comment = "Comment"
4444- show EOI = "EOI"
4545- show Pragma = "Pragma"
4646- show StringKind = "String"
4747- show JSLit = "JSLit"
4848- show Projection = "Projection"
4949- show StartQuote = "StartQuote"
5050- show EndQuote = "EndQuote"
5151- show StartInterp = "StartInterp"
5252- show EndInterp = "EndInterp"
5353-2323+derive Show Kind
54245525instance Eq Kind where
5626 a == b = show a == show b
···6131 kind : Kind
6232 text : String
63336464-6565-6634instance Show Token where
6735 show (Tok k v) = "<\{show k}:\{show v}>"
6868-69367037BTok : U
7138BTok = WithBounds Token
72397373-7474-value : BTok -> String
4040+value : BTok → String
7541value (MkBounded (Tok _ s) _) = s
764277437878-getStart : BTok -> (Int × Int)
4444+getStart : BTok → (Int × Int)
7945getStart (MkBounded _ (MkBounds l c _ _)) = (l,c)
80468181-getEnd : BTok -> (Int × Int)
4747+getEnd : BTok → (Int × Int)
8248getEnd (MkBounded _ (MkBounds _ _ el ec)) = (el,ec)
+13-112
src/Lib/Types.newt
···1414Name = String
15151616data Icit = Implicit | Explicit | Auto
1717-1818-instance Show Icit where
1919- show Implicit = "Implicit"
2020- show Explicit = "Explicit"
2121- show Auto = "Auto"
1717+derive Show Icit
1818+derive Eq Icit
22192320data BD = Bound | Defined
2424-2525-instance Eq BD where
2626- Bound == Bound = True
2727- Defined == Defined = True
2828- _ == _ = False
2929-3030-instance Show BD where
3131- show Bound = "bnd"
3232- show Defined = "def"
2121+derive Eq BD
2222+derive Show BD
33233424data Quant = Zero | Many
3535-3636-instance Show Quant where
3737- show Zero = "0 "
3838- show Many = ""
3939-4040-instance Eq Quant where
4141- Zero == Zero = True
4242- Many == Many = True
4343- _ == _ = False
2525+derive Eq Quant
2626+derive Show Quant
44274528-- We could make this polymorphic and use for environment...
4629···130113instance Show CaseAlt where
131114 show = showCaseAlt
132115133133-134134-showTm : Tm -> String
135135-showTm = show
136136-137137--- I can't really show val because it's HOAS...
138138-139139--- TODO derive
140140-141141-instance Eq Icit where
142142- Implicit == Implicit = True
143143- Explicit == Explicit = True
144144- Auto == Auto = True
145145- _ == _ = False
146146-147147--- Eq on Tm. We've got deBruijn indices, so I'm not comparing names
148148-149149-instance Eq (Tm) where
150150- -- (Local x) == (Local y) = x == y
151151- (Bnd _ x) == (Bnd _ y) = x == y
152152- (Ref _ x) == Ref _ y = x == y
153153- (Lam _ n _ _ t) == Lam _ n' _ _ t' = t == t'
154154- (App _ t u) == App _ t' u' = t == t' && u == u'
155155- (UU _) == (UU _) = True
156156- (Pi _ n icit rig t u) == (Pi _ n' icit' rig' t' u') = icit == icit' && rig == rig' && t == t' && u == u'
157157- _ == _ = False
158158-159159--- TODO App and Lam should have <+/> but we need to fix
160160--- INFO pprint to `nest 2 ...`
161161--- maybe return Doc and have an Interpolation..
162162--- If we need to flatten, case is going to get in the way.
163163-164116pprint' : Int -> List String -> Tm -> Doc
165117pprintAlt : Int -> List String -> CaseAlt -> Doc
166118pprintAlt p names (CaseDefault t) = text "_" <+> text "=>" <+> pprint' p ("_" :: names) t
···282234283235284236showClosure (MkClosure xs t) = "(%cl [\{show $ length xs} env] \{show t})"
285285-286286--- instance Show Closure where
287287--- show = showClosure
288237289238Context : U
290239291240data MetaKind = Normal | User | AutoSolve | ErrorHole
292241293293-instance Show MetaKind where
294294- show Normal = "Normal"
295295- show User = "User"
296296- show AutoSolve = "Auto"
297297- show ErrorHole = "ErrorHole"
298298-299299-instance Eq MetaKind where
300300- Normal == Normal = True
301301- User == User = True
302302- AutoSolve == AutoSolve = True
303303- ErrorHole == ErrorHole = True
304304- _ == _ = False
242242+derive Show MetaKind
243243+derive Eq MetaKind
305244306245-- constrain meta applied to val to be a val
307246···328267 next : Int
329268 mcmode : MetaMode
330269331331-instance Eq MetaMode where
332332- CheckAll == CheckAll = True
333333- CheckFirst == CheckFirst = True
334334- NoCheck == NoCheck = True
335335- _ == _ = False
270270+derive Eq MetaMode
336271337272data ConInfo = NormalCon | SuccCon | ZeroCon | EnumCon | TrueCon | FalseCon
338273339339-instance Eq ConInfo where
340340- NormalCon == NormalCon = True
341341- SuccCon == SuccCon = True
342342- ZeroCon == ZeroCon = True
343343- EnumCon == EnumCon = True
344344- TrueCon == TrueCon = True
345345- FalseCon == FalseCon = True
346346- _ == _ = False
274274+derive Eq ConInfo
347275348276instance Show ConInfo where
349277 show NormalCon = ""
···356284data Def = Axiom | TCon Int (List QName) | DCon Nat ConInfo (List Quant) QName | Fn Tm | PrimTCon Int
357285 | PrimFn String Nat (List QName)
358286 | PrimOp String
359359-360360-instance Show Def where
361361- show Axiom = "axiom"
362362- show (PrimOp op) = "PrimOp \{show op}"
363363- show (TCon _ strs) = "TCon \{show strs}"
364364- show (DCon ix ci k tyname) = "DCon \{show ix} \{show k} \{show tyname} \{show ci}"
365365- show (Fn t) = "Fn \{show t}"
366366- show (PrimTCon _) = "PrimTCon"
367367- show (PrimFn src arity used) = "PrimFn \{show src} \{show arity} \{show used}"
368368-369369--- entry in the top level context
287287+derive Show Def
370288371289data EFlag = Hint | Inline | Export
372372-373373-instance Show EFlag where
374374- show Hint = "hint"
375375- show Inline = "inline"
376376- show Export = "export"
377377-378378-instance Eq EFlag where
379379- Hint == Hint = True
380380- Inline == Inline = True
381381- Export == Export = True
382382- _ == _ = False
290290+derive Show EFlag
291291+derive Eq EFlag
383292384293record TopEntry where
385294 constructor MkEntry
···410319 modErrors : List Error
411320 modInfos : List EditorInfo
412321413413--- Top level context.
414414--- Most of the reason this is separate is to have a different type
415415--- `Def` for the entries.
416416---
417417--- The price is that we have names in addition to levels. Do we want to
418418--- expand these during normalization?
419419-420420--- A placeholder while walking through dependencies of a module
421322emptyModCtx : String → String → ModContext
422323emptyModCtx modName source = MkModCtx modName source emptyMap (MC emptyMap Nil 0 NoCheck) emptyMap Nil Nil Nil
423324
-2
src/Lib/Util.newt
···2020data Binder : U where
2121 MkBinder : FC -> String -> Icit -> Quant -> Tm -> Binder
22222323--- I don't have a show for terms without a name list
2424-2523instance Show Binder where
2624 show (MkBinder _ nm icit quant t) = "[\{show quant}\{nm} \{show icit} : ...]"
2725
+1-5
src/Prelude.newt
···744744tail (x :: xs) = xs
745745746746data Ordering = LT | EQ | GT
747747-instance Eq Ordering where
748748- LT == LT = True
749749- EQ == EQ = True
750750- GT == GT = True
751751- _ == _ = False
747747+derive Eq Ordering
752748753749pfunc jsCompare uses (EQ LT GT) : ∀ a. a → a → Ordering := `(_, a, b) => a == b ? Prelude_EQ : a < b ? Prelude_LT : Prelude_GT`
754750