You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* WIP Pattern guards
* Introduce GuardedExpr constructor
* Longer names for alternative desugaring
* isIrrefutable
* Consistently value binders `vb`
* Introduce isIrrefutable in Purescrupt/AST/Binders
* Consolidate out of line code generation
* Comment on special casing ConditionalGuards
* Why do we need to scrutinize again
* Remove warnings from AST/Traversals
* Remove trueLit constant
* Remove (***) import from CoreFn/Desugar
* Removed shadowing in Linter/Exhaustive
* Missed a tick
* Make SourceFileSpec work
* Fix AST/Traversals
* Desugar with less cases
* Desugar remaining alternatives if there are no guards remaining
```
g n | p = ...
g n | b <- f = ...
```
The pattern guard wouldn't be desugared without this patch because
`p` was the only guarded expression in the first alternative which
resulted in the empty list case in `desugarGuardedAlternative` so the
remaining second alternative is passed as-is upwards again.
* Update comment
* Remove redundant Show constraint
* Remove redundant Monad constraint
* Remove duplication
* Use short-circuiting fold in CodeGen/JS
* Correct generation of pattern guards with irrefutable patterns
Consider
```
f ... | i <- g = ...
```
Where i is an irrefutable pattern we would generate
```
case ... of
... -> case g of
i -> ...
_ -> ...
```
We generated an unreachable case alternative Which is bogus of course!
A pattern match on `i` will never fail! This patch stops generating
the unreachable case.
* Fix everythingWithScope
This lead to undetected shadowing. Fortunately the fix was to delete
some wrong "duplicated" code.
* Error on desugaring pattern guards to CoreFn
* Use scoped type variable m to dry code
* Error when trying to typecheck pattern guard
These are desugared to usual cases and guards already
* Make sure to not evaluate scrutinees twice
* Typos
* A few examples
handleDoNotationElement (PositionedDoNotationElement pos com e) =PositionedDoNotationElement pos com <$> handleDoNotationElement e
156
174
175
+
handleGuard::Guard->mGuard
176
+
handleGuard (ConditionGuard e) =ConditionGuard<$> (g' <=< g) e
177
+
handleGuard (PatternGuard b e) =PatternGuard<$> (h' <=< h) b <*> (g' <=< g) e
178
+
157
179
everywhereOnValuesM
158
180
::forallm
159
181
. (Monadm)
@@ -169,7 +191,7 @@ everywhereOnValuesM f g h = (f', g', h')
169
191
170
192
f'::Declaration->mDeclaration
171
193
f' (DataBindingGroupDeclaration ds) = (DataBindingGroupDeclaration<$>traverse f' ds) >>= f
172
-
f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$>traverse h' bs <*>eitherM (traverse (pairM g' g')) g' val) >>= f
194
+
f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$>traverse h' bs <*>traverse (guardedExprM handleGuard g') val) >>= f
173
195
f' (BindingGroupDeclaration ds) = (BindingGroupDeclaration<$>traverse (\(name, nameKind, val) -> (,,) name nameKind <$> g' val) ds) >>= f
174
196
f' (TypeClassDeclaration name args implies deps ds) = (TypeClassDeclaration name args implies deps <$>traverse f' ds) >>= f
175
197
f' (TypeInstanceDeclaration name cs className args ds) = (TypeInstanceDeclaration name cs className args <$> traverseTypeInstanceBody (traverse f') ds) >>= f
@@ -214,14 +236,18 @@ everywhereOnValuesM f g h = (f', g', h')
everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
398
430
where
399
431
f'' s =uncurry f' <=< f s
400
432
401
433
f' s (DataBindingGroupDeclaration ds) =DataBindingGroupDeclaration<$>traverse (f'' s) ds
402
-
f' s (ValueDeclaration name nameKind bs val) =ValueDeclaration name nameKind <$>traverse (h'' s) bs <*>eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
434
+
f' s (ValueDeclaration name nameKind bs val) =ValueDeclaration name nameKind <$>traverse (h'' s) bs <*>traverse (guardedExprM (k' s) (g'' s)) val
403
435
f' s (BindingGroupDeclaration ds) =BindingGroupDeclaration<$>traverse (thirdM (g'' s)) ds
404
436
f' s (TypeClassDeclaration name args implies deps ds) =TypeClassDeclaration name args implies deps <$>traverse (f'' s) ds
405
437
f' s (TypeInstanceDeclaration name cs className args ds) =TypeInstanceDeclaration name cs className args <$> traverseTypeInstanceBody (traverse (f'' s)) ds
@@ -444,7 +476,7 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
444
476
445
477
i'' s =uncurry i' <=< i s
446
478
447
-
i' s (CaseAlternative bs val) =CaseAlternative<$>traverse (h'' s) bs <*>eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
479
+
i' s (CaseAlternative bs val) =CaseAlternative<$>traverse (h'' s) bs <*>traverse (guardedExprM (k' s) (g'' s)) val
448
480
449
481
j'' s =uncurry j' <=< j s
450
482
@@ -453,6 +485,9 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
453
485
j' s (DoNotationLet ds) =DoNotationLet<$>traverse (f'' s) ds
454
486
j' s (PositionedDoNotationElement pos com e1) =PositionedDoNotationElement pos com <$> j'' s e1
455
487
488
+
k' s (ConditionGuard e) =ConditionGuard<$> g'' s e
489
+
k' s (PatternGuard b e) =PatternGuard<$> h'' s b <*> g'' s e
490
+
456
491
everythingWithScope
457
492
::forallr
458
493
. (Monoidr)
@@ -479,14 +514,10 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
479
514
f' s (DataBindingGroupDeclaration ds) =
480
515
let s' =S.union s (S.fromList (mapMaybe getDeclIdent ds))
481
516
infoldMap (f'' s') ds
482
-
f' s (ValueDeclaration name _ bs (Rightval)) =
517
+
f' s (ValueDeclaration name _ bs val) =
483
518
let s' =S.insert name s
484
519
s'' =S.union s' (S.fromList (concatMap binderNames bs))
485
-
infoldMap (h'' s') bs <> g'' s'' val
486
-
f' s (ValueDeclaration name _ bs (Left gs)) =
487
-
let s' =S.insert name s
488
-
s'' =S.union s' (S.fromList (concatMap binderNames bs))
0 commit comments