diff options
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 219 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 151 |
3 files changed, 187 insertions, 187 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 60807cc6..0511988a 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -8,7 +8,10 @@ | |||
8 | {-# LANGUAGE DeriveFunctor #-} | 8 | {-# LANGUAGE DeriveFunctor #-} |
9 | {-# LANGUAGE ScopedTypeVariables #-} | 9 | {-# LANGUAGE ScopedTypeVariables #-} |
10 | {-# LANGUAGE MultiParamTypeClasses #-} | 10 | {-# LANGUAGE MultiParamTypeClasses #-} |
11 | module LambdaCube.Compiler.DesugaredSource where | 11 | module LambdaCube.Compiler.DesugaredSource |
12 | ( module LambdaCube.Compiler.DesugaredSource | ||
13 | , FixityDir(..), Fixity(..) | ||
14 | )where | ||
12 | 15 | ||
13 | import Data.Monoid | 16 | import Data.Monoid |
14 | import Data.Maybe | 17 | import Data.Maybe |
@@ -19,8 +22,6 @@ import Data.Bits | |||
19 | import qualified Data.Map as Map | 22 | import qualified Data.Map as Map |
20 | import qualified Data.Set as Set | 23 | import qualified Data.Set as Set |
21 | import qualified Data.IntMap as IM | 24 | import qualified Data.IntMap as IM |
22 | import Control.Monad.Reader | ||
23 | import Control.Monad.State | ||
24 | import Control.Arrow hiding ((<+>)) | 25 | import Control.Arrow hiding ((<+>)) |
25 | import Control.DeepSeq | 26 | import Control.DeepSeq |
26 | 27 | ||
@@ -53,14 +54,6 @@ pattern MatchName :: SName -> SName | |||
53 | pattern MatchName cs <- 'm':'a':'t':'c':'h':cs where MatchName cs = "match" ++ cs | 54 | pattern MatchName cs <- 'm':'a':'t':'c':'h':cs where MatchName cs = "match" ++ cs |
54 | 55 | ||
55 | 56 | ||
56 | -------------------------------------------------------------------------------- fixity | ||
57 | |||
58 | data FixityDir = Infix | InfixL | InfixR | ||
59 | deriving (Eq, Show) | ||
60 | |||
61 | data Fixity = Fixity !FixityDir !Int | ||
62 | deriving (Eq, Show) | ||
63 | |||
64 | -------------------------------------------------------------------------------- file position | 57 | -------------------------------------------------------------------------------- file position |
65 | 58 | ||
66 | -- source position without file name | 59 | -- source position without file name |
@@ -392,6 +385,39 @@ trSExp f = g where | |||
392 | trSExp' :: SExp -> SExp' a | 385 | trSExp' :: SExp -> SExp' a |
393 | trSExp' = trSExp elimVoid | 386 | trSExp' = trSExp elimVoid |
394 | 387 | ||
388 | instance Up a => PShow (SExp' a) where | ||
389 | pShowPrec _ = showDoc_ . sExpDoc | ||
390 | |||
391 | sExpDoc :: Up a => SExp' a -> NDoc | ||
392 | sExpDoc = \case | ||
393 | SGlobal ns -> shAtom $ sName ns | ||
394 | SAnn a b -> shAnn ":" False (sExpDoc a) (sExpDoc b) | ||
395 | TyType a -> shApp Visible (shAtom "tyType") (sExpDoc a) | ||
396 | SApp h a b -> shApp h (sExpDoc a) (sExpDoc b) | ||
397 | Wildcard t -> shAnn ":" True (shAtom "_") (sExpDoc t) | ||
398 | SBind_ _ h _ a b -> shLam (usedVar 0 b) h (sExpDoc a) (sExpDoc b) | ||
399 | SLet _ a b -> shLet_ (sExpDoc a) (sExpDoc b) | ||
400 | STyped _{-(e,t)-} -> shAtom "<<>>" -- todo: expDoc e | ||
401 | SVar _ i -> shVar i | ||
402 | SLit _ l -> shAtom $ show l | ||
403 | |||
404 | shLam usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 a) b | ||
405 | where | ||
406 | lam = case h of | ||
407 | BPi{} -> shArr | ||
408 | _ -> shLam' | ||
409 | |||
410 | p = case h of | ||
411 | BMeta -> cpar . shAnn ":" True (inBlue' $ DVar 0) | ||
412 | BLam h -> vpar h | ||
413 | BPi h -> vpar h | ||
414 | |||
415 | vpar Hidden = (\p -> DBrace p) . shAnn ":" True (inGreen' $ DVar 0) | ||
416 | vpar Visible = ann (inGreen' $ DVar 0) | ||
417 | |||
418 | ann | usedVar = shAnn ":" False | ||
419 | | otherwise = const id | ||
420 | |||
395 | -------------------------------------------------------------------------------- statement | 421 | -------------------------------------------------------------------------------- statement |
396 | 422 | ||
397 | data Stmt | 423 | data Stmt |
@@ -474,174 +500,3 @@ data Extension | |||
474 | extensionMap :: Map.Map String Extension | 500 | extensionMap :: Map.Map String Extension |
475 | extensionMap = Map.fromList $ map (show &&& id) [toEnum 0 .. ] | 501 | extensionMap = Map.fromList $ map (show &&& id) [toEnum 0 .. ] |
476 | 502 | ||
477 | -------------------------------------------------------------------------------- pretty print | ||
478 | |||
479 | data NDoc | ||
480 | = DAtom String | ||
481 | | DOp Fixity NDoc String NDoc | ||
482 | | DPar String NDoc String | ||
483 | | DLam String [NDoc] String NDoc | ||
484 | | DVar Int | ||
485 | | DFreshName Bool{-False: dummy-} NDoc | ||
486 | | DUp Int NDoc | ||
487 | | DColor Color NDoc | ||
488 | -- add wl-pprint combinators as necessary here | ||
489 | deriving (Eq) | ||
490 | |||
491 | pattern DParen x = DPar "(" x ")" | ||
492 | pattern DBrace x = DPar "{" x "}" | ||
493 | pattern DArr x y = DOp (Fixity InfixR (-1)) x "->" y | ||
494 | pattern DAnn x y = DOp (Fixity InfixR (-3)) x ":" y | ||
495 | |||
496 | data Color = Green | Blue | Underlined | ||
497 | deriving (Eq) | ||
498 | |||
499 | inGreen' = DColor Green | ||
500 | inBlue' = DColor Blue | ||
501 | epar = DColor Underlined | ||
502 | |||
503 | strip = \case | ||
504 | DColor _ x -> strip x | ||
505 | DUp _ x -> strip x | ||
506 | DFreshName _ x -> strip x | ||
507 | x -> x | ||
508 | |||
509 | simple x = case strip x of | ||
510 | DAtom{} -> True | ||
511 | DVar{} -> True | ||
512 | DPar{} -> True | ||
513 | _ -> False | ||
514 | |||
515 | renderDocX :: NDoc -> Doc | ||
516 | renderDocX = render . addPar (-10) . flip runReader [] . flip evalStateT (flip (:) <$> iterate ('\'':) "" <*> ['a'..'z']) . showVars | ||
517 | where | ||
518 | showVars x = case x of | ||
519 | DAtom s -> pure x | ||
520 | DColor c x -> DColor c <$> showVars x | ||
521 | DPar l x r -> DPar l <$> showVars x <*> pure r | ||
522 | DOp pr x s y -> DOp pr <$> showVars x <*> pure s <*> showVars y | ||
523 | DVar i -> asks $ DAtom . lookupVarName i | ||
524 | DFreshName True x -> gets head >>= \n -> modify tail >> local (n:) (showVars x) | ||
525 | DFreshName False x -> local ("_":) $ showVars x | ||
526 | DUp i x -> local (dropNth i) $ showVars x | ||
527 | DLam lam vs arr e -> DLam lam <$> (mapM showVars vs) <*> pure arr <*> showVars e | ||
528 | where | ||
529 | lookupVarName i xs | i < length xs = xs !! i | ||
530 | lookupVarName i _ = ((\s n -> n: '_': s) <$> iterate ('\'':) "" <*> ['a'..'z']) !! i | ||
531 | |||
532 | addPar :: Int -> NDoc -> NDoc | ||
533 | addPar pr x = case x of | ||
534 | DAtom{} -> x | ||
535 | DColor c x -> DColor c $ addPar pr x | ||
536 | DPar l x r -> DPar l (addPar (-20) x) r | ||
537 | DOp pr' x s y -> paren $ DOp pr' (addPar (precL pr') x) s (addPar (precR pr') y) | ||
538 | DLam lam vs arr e -> paren $ DLam lam (addPar 10 <$> vs) arr (addPar (-10) e) | ||
539 | where | ||
540 | paren d | ||
541 | | protect x = DParen d | ||
542 | | otherwise = d | ||
543 | where | ||
544 | protect x = case x of | ||
545 | DAtom{} -> False | ||
546 | DPar{} -> False | ||
547 | DOp (Fixity _ pr') _ _ _ -> pr' < pr | ||
548 | DLam{} -> -10 < pr | ||
549 | |||
550 | precL (Fixity Infix i) = i+1 | ||
551 | precL (Fixity InfixL i) = i | ||
552 | precL (Fixity InfixR i) = i+1 | ||
553 | precR (Fixity Infix i) = i+1 | ||
554 | precR (Fixity InfixL i) = i+1 | ||
555 | precR (Fixity InfixR i) = i | ||
556 | |||
557 | render x = case x of | ||
558 | DColor Green x -> text $ inGreen $ show $ render x -- TODO | ||
559 | DColor Blue x -> text $ inBlue $ show $ render x -- TODO | ||
560 | DColor Underlined x -> text $ underlined $ show $ render x -- TODO | ||
561 | DAtom s -> text s | ||
562 | DPar l x r -> text l <> render x <> text r | ||
563 | DOp _ x s y -> case s of | ||
564 | "" -> render x <+> render y | ||
565 | _ | simple x && simple y && s /= "," -> render x <> text s <> render y | ||
566 | | otherwise -> (render x <++> s) <+> render y | ||
567 | DLam lam vs arr e -> text lam <> hsep (render <$> vs) <+> text arr <+> render e | ||
568 | where | ||
569 | x <++> "," = x <> text "," | ||
570 | x <++> s = x <+> text s | ||
571 | |||
572 | instance Up a => PShow (SExp' a) where | ||
573 | pShowPrec _ = showDoc_ . sExpDoc | ||
574 | |||
575 | -- name De Bruijn indices | ||
576 | type NameDB a = StateT [String] (Reader [String]) a | ||
577 | |||
578 | showDoc :: NDoc -> String | ||
579 | showDoc = show . renderDocX | ||
580 | |||
581 | showDoc_ :: NDoc -> Doc | ||
582 | showDoc_ = renderDocX | ||
583 | |||
584 | sExpDoc :: Up a => SExp' a -> NDoc | ||
585 | sExpDoc = \case | ||
586 | SGlobal ns -> shAtom $ sName ns | ||
587 | SAnn a b -> shAnn ":" False (sExpDoc a) (sExpDoc b) | ||
588 | TyType a -> shApp Visible (shAtom "tyType") (sExpDoc a) | ||
589 | SApp h a b -> shApp h (sExpDoc a) (sExpDoc b) | ||
590 | Wildcard t -> shAnn ":" True (shAtom "_") (sExpDoc t) | ||
591 | SBind_ _ h _ a b -> shLam (usedVar 0 b) h (sExpDoc a) (sExpDoc b) | ||
592 | SLet _ a b -> shLet_ (sExpDoc a) (sExpDoc b) | ||
593 | STyped _{-(e,t)-} -> shAtom "<<>>" -- todo: expDoc e | ||
594 | SVar _ i -> shVar i | ||
595 | SLit _ l -> shAtom $ show l | ||
596 | |||
597 | shVar = DVar | ||
598 | |||
599 | shLet i a b = shLam' (cpar . shLet' (inBlue' $ shVar i) $ DUp i a) (DUp i b) | ||
600 | shLet_ a b = DFreshName True $ shLam' (cpar . shLet' (shVar 0) $ DUp 0 a) b | ||
601 | |||
602 | shLam usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 a) b | ||
603 | where | ||
604 | lam = case h of | ||
605 | BPi{} -> shArr | ||
606 | _ -> shLam' | ||
607 | |||
608 | p = case h of | ||
609 | BMeta -> cpar . shAnn ":" True (inBlue' $ DVar 0) | ||
610 | BLam h -> vpar h | ||
611 | BPi h -> vpar h | ||
612 | |||
613 | vpar Hidden = (\p -> DBrace p) . shAnn ":" True (inGreen' $ DVar 0) | ||
614 | vpar Visible = ann (inGreen' $ DVar 0) | ||
615 | |||
616 | ann | usedVar = shAnn ":" False | ||
617 | | otherwise = const id | ||
618 | |||
619 | ----------------------------------------- | ||
620 | |||
621 | shAtom = DAtom | ||
622 | |||
623 | shTuple [] = DAtom "()" | ||
624 | shTuple [x] = DParen $ DParen x | ||
625 | shTuple xs = DParen $ foldr1 (\x y -> DOp (Fixity InfixR (-20)) x "," y) xs | ||
626 | |||
627 | shAnn _ True x y | strip y == DAtom "Type" = x | ||
628 | shAnn s _ x y = DOp (Fixity InfixR (-3)) x s y | ||
629 | |||
630 | shApp _ x y = DOp (Fixity InfixL 10) x "" y | ||
631 | |||
632 | shArr = DArr | ||
633 | |||
634 | shCstr x y = DOp (Fixity Infix (-2)) x "~" y | ||
635 | |||
636 | shLet' x y = DOp (Fixity Infix (-4)) x ":=" y | ||
637 | |||
638 | getFN (DFreshName True a) = first (+1) $ getFN a | ||
639 | getFN a = (0, a) | ||
640 | |||
641 | shLam' x (getFN -> (i, DLam "\\" xs "->" y)) = iterateN i (DFreshName True) $ DLam "\\" (iterateN i (DUp 0) x: xs) "->" y | ||
642 | shLam' x y = DLam "\\" [x] "->" y | ||
643 | |||
644 | cpar s | simple s = s | ||
645 | cpar s = DParen s | ||
646 | |||
647 | |||
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index 8a9e56c1..fd2cdbfd 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -146,18 +146,14 @@ mkDesugarInfo ss = DesugarInfo | |||
146 | 146 | ||
147 | data Prec | 147 | data Prec |
148 | = PrecAtom -- ( _ ) ... -- 20 | 148 | = PrecAtom -- ( _ ) ... -- 20 |
149 | | PrecAtom' | ||
150 | | PrecAt -- _@_ {assoc} -- in patterns -- 13 | 149 | | PrecAt -- _@_ {assoc} -- in patterns -- 13 |
151 | | PrecProj -- _ ._ {left} -- 12 | 150 | | PrecProj -- _ ._ {left} -- 12 |
152 | | PrecSwiz -- _%_ {left} -- 11 | 151 | | PrecSwiz -- _%_ {left} -- 11 |
153 | | PrecApp -- _ _ {left} -- 10 | 152 | | PrecApp -- _ _ {left} -- 10 |
154 | | PrecOp -- 0 - 9 | 153 | | PrecOp -- 0 - 9 |
155 | | PrecArr -- _ -> _ {right} -- -1 | 154 | | PrecArr -- _ -> _ {right} -- -1 |
156 | | PrecEq -- _ ~ _ -- -2 | ||
157 | | PrecAnn -- _ :: _ {right} -- -3 | 155 | | PrecAnn -- _ :: _ {right} -- -3 |
158 | | PrecLet -- _ := _ -- -4 | ||
159 | | PrecLam -- \ _ -> _ {right} {accum} -- -10 | 156 | | PrecLam -- \ _ -> _ {right} {accum} -- -10 |
160 | -- _ , _ {right} -- -20 | ||
161 | deriving (Eq, Ord) | 157 | deriving (Eq, Ord) |
162 | 158 | ||
163 | -------------------------------------------------------------------------------- expression parsing | 159 | -------------------------------------------------------------------------------- expression parsing |
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index e1d41fc1..5044eecf 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -21,9 +21,14 @@ import qualified Data.Set as Set | |||
21 | import Data.Map (Map) | 21 | import Data.Map (Map) |
22 | import qualified Data.Map as Map | 22 | import qualified Data.Map as Map |
23 | import Control.Monad.Except | 23 | import Control.Monad.Except |
24 | import Control.Monad.Reader | ||
25 | import Control.Monad.State | ||
26 | import Control.Arrow hiding ((<+>)) | ||
24 | import Debug.Trace | 27 | import Debug.Trace |
25 | 28 | ||
26 | import Text.PrettyPrint.Leijen | 29 | import Text.PrettyPrint.Leijen hiding ((<$>)) |
30 | |||
31 | import LambdaCube.Compiler.Utils | ||
27 | 32 | ||
28 | -------------------------------------------------------------------------------- | 33 | -------------------------------------------------------------------------------- |
29 | 34 | ||
@@ -150,3 +155,147 @@ error_ = error . correctEscs | |||
150 | trace_ = trace . correctEscs | 155 | trace_ = trace . correctEscs |
151 | throwError_ = throwError . correctEscs | 156 | throwError_ = throwError . correctEscs |
152 | 157 | ||
158 | |||
159 | -------------------------------------------------------------------------------- fixity | ||
160 | |||
161 | data FixityDir = Infix | InfixL | InfixR | ||
162 | deriving (Eq, Show) | ||
163 | |||
164 | data Fixity = Fixity !FixityDir !Int | ||
165 | deriving (Eq, Show) | ||
166 | |||
167 | -------------------------------------------------------------------------------- pretty print | ||
168 | |||
169 | data NDoc | ||
170 | = DAtom String | ||
171 | | DOp Fixity NDoc String NDoc | ||
172 | | DPar String NDoc String | ||
173 | | DLam String [NDoc] String NDoc | ||
174 | | DVar Int | ||
175 | | DFreshName Bool{-False: dummy-} NDoc | ||
176 | | DUp Int NDoc | ||
177 | | DColor Color NDoc | ||
178 | -- add wl-pprint combinators as necessary here | ||
179 | deriving (Eq) | ||
180 | |||
181 | pattern DParen x = DPar "(" x ")" | ||
182 | pattern DBrace x = DPar "{" x "}" | ||
183 | pattern DArr x y = DOp (Fixity InfixR (-1)) x "->" y | ||
184 | pattern DAnn x y = DOp (Fixity InfixR (-3)) x ":" y | ||
185 | |||
186 | data Color = Green | Blue | Underlined | ||
187 | deriving (Eq) | ||
188 | |||
189 | inGreen' = DColor Green | ||
190 | inBlue' = DColor Blue | ||
191 | epar = DColor Underlined | ||
192 | |||
193 | strip = \case | ||
194 | DColor _ x -> strip x | ||
195 | DUp _ x -> strip x | ||
196 | DFreshName _ x -> strip x | ||
197 | x -> x | ||
198 | |||
199 | simple x = case strip x of | ||
200 | DAtom{} -> True | ||
201 | DVar{} -> True | ||
202 | DPar{} -> True | ||
203 | _ -> False | ||
204 | |||
205 | renderDocX :: NDoc -> Doc | ||
206 | renderDocX = render . addPar (-10) . flip runReader [] . flip evalStateT (flip (:) <$> iterate ('\'':) "" <*> ['a'..'z']) . showVars | ||
207 | where | ||
208 | showVars x = case x of | ||
209 | DAtom s -> pure x | ||
210 | DColor c x -> DColor c <$> showVars x | ||
211 | DPar l x r -> DPar l <$> showVars x <*> pure r | ||
212 | DOp pr x s y -> DOp pr <$> showVars x <*> pure s <*> showVars y | ||
213 | DVar i -> asks $ DAtom . lookupVarName i | ||
214 | DFreshName True x -> gets head >>= \n -> modify tail >> local (n:) (showVars x) | ||
215 | DFreshName False x -> local ("_":) $ showVars x | ||
216 | DUp i x -> local (dropNth i) $ showVars x | ||
217 | DLam lam vs arr e -> DLam lam <$> (mapM showVars vs) <*> pure arr <*> showVars e | ||
218 | where | ||
219 | lookupVarName i xs | i < length xs = xs !! i | ||
220 | lookupVarName i _ = ((\s n -> n: '_': s) <$> iterate ('\'':) "" <*> ['a'..'z']) !! i | ||
221 | |||
222 | addPar :: Int -> NDoc -> NDoc | ||
223 | addPar pr x = case x of | ||
224 | DAtom{} -> x | ||
225 | DColor c x -> DColor c $ addPar pr x | ||
226 | DPar l x r -> DPar l (addPar (-20) x) r | ||
227 | DOp pr' x s y -> paren $ DOp pr' (addPar (precL pr') x) s (addPar (precR pr') y) | ||
228 | DLam lam vs arr e -> paren $ DLam lam (addPar 10 <$> vs) arr (addPar (-10) e) | ||
229 | where | ||
230 | paren d | ||
231 | | protect x = DParen d | ||
232 | | otherwise = d | ||
233 | where | ||
234 | protect x = case x of | ||
235 | DAtom{} -> False | ||
236 | DPar{} -> False | ||
237 | DOp (Fixity _ pr') _ _ _ -> pr' < pr | ||
238 | DLam{} -> -10 < pr | ||
239 | |||
240 | precL (Fixity Infix i) = i+1 | ||
241 | precL (Fixity InfixL i) = i | ||
242 | precL (Fixity InfixR i) = i+1 | ||
243 | precR (Fixity Infix i) = i+1 | ||
244 | precR (Fixity InfixL i) = i+1 | ||
245 | precR (Fixity InfixR i) = i | ||
246 | |||
247 | render x = case x of | ||
248 | DColor Green x -> text $ inGreen $ show $ render x -- TODO | ||
249 | DColor Blue x -> text $ inBlue $ show $ render x -- TODO | ||
250 | DColor Underlined x -> text $ underlined $ show $ render x -- TODO | ||
251 | DAtom s -> text s | ||
252 | DPar l x r -> text l <> render x <> text r | ||
253 | DOp _ x s y -> case s of | ||
254 | "" -> render x <+> render y | ||
255 | _ | simple x && simple y && s /= "," -> render x <> text s <> render y | ||
256 | | otherwise -> (render x <++> s) <+> render y | ||
257 | DLam lam vs arr e -> text lam <> hsep (render <$> vs) <+> text arr <+> render e | ||
258 | where | ||
259 | x <++> "," = x <> text "," | ||
260 | x <++> s = x <+> text s | ||
261 | |||
262 | showDoc :: NDoc -> String | ||
263 | showDoc = show . renderDocX | ||
264 | |||
265 | showDoc_ :: NDoc -> Doc | ||
266 | showDoc_ = renderDocX | ||
267 | |||
268 | shVar = DVar | ||
269 | |||
270 | shLet i a b = shLam' (cpar . shLet' (inBlue' $ shVar i) $ DUp i a) (DUp i b) | ||
271 | shLet_ a b = DFreshName True $ shLam' (cpar . shLet' (shVar 0) $ DUp 0 a) b | ||
272 | |||
273 | ----------------------------------------- | ||
274 | |||
275 | shAtom = DAtom | ||
276 | |||
277 | shTuple [] = DAtom "()" | ||
278 | shTuple [x] = DParen $ DParen x | ||
279 | shTuple xs = DParen $ foldr1 (\x y -> DOp (Fixity InfixR (-20)) x "," y) xs | ||
280 | |||
281 | shAnn _ True x y | strip y == DAtom "Type" = x | ||
282 | shAnn s _ x y = DOp (Fixity InfixR (-3)) x s y | ||
283 | |||
284 | shApp _ x y = DOp (Fixity InfixL 10) x "" y | ||
285 | |||
286 | shArr = DArr | ||
287 | |||
288 | shCstr x y = DOp (Fixity Infix (-2)) x "~" y | ||
289 | |||
290 | shLet' x y = DOp (Fixity Infix (-4)) x ":=" y | ||
291 | |||
292 | getFN (DFreshName True a) = first (+1) $ getFN a | ||
293 | getFN a = (0, a) | ||
294 | |||
295 | shLam' x (getFN -> (i, DLam "\\" xs "->" y)) = iterateN i (DFreshName True) $ DLam "\\" (iterateN i (DUp 0) x: xs) "->" y | ||
296 | shLam' x y = DLam "\\" [x] "->" y | ||
297 | |||
298 | cpar s | simple s = s | ||
299 | cpar s = DParen s | ||
300 | |||
301 | |||