This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
SkipConstructor.hs
56 lines (47 loc) · 2.39 KB
/
SkipConstructor.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
module SkipConstructor where
data T = Ok1
| Ok2
| NonPositive (T -> T) -- Skipped – untranslatable, non-positive recursion
| Record { field :: () } -- Skipped – testing record fields
| SkipMe -- Skipped – boring
skipEquations :: T -> T
skipEquations Ok1 = Ok1
skipEquations Ok2 = Ok2
skipEquations (NonPositive f) = f (skipEquations (NonPositive f)) -- This equation should be skipped before becoming impossible recursion
skipEquations (Record u) = Record u -- This equation should be skipped
skipEquations SkipMe = SkipMe -- This equation should be skipped
skipCaseBranches :: T -> T
skipCaseBranches t = case t of
Ok1 -> Ok1
Ok2 -> Ok2
NonPositive f -> f (skipCaseBranches (NonPositive f)) -- This case should be skipped before becoming impossible recursion
Record u -> Record u -- This case should be skipped
SkipMe -> SkipMe -- This case should be skipped
nestedPattern :: (Bool, Maybe T) -> Maybe T
nestedPattern (True, Just Ok1) = Just Ok1
nestedPattern (True, Just Ok2) = Just Ok1
nestedPattern (True, Just SkipMe) = Just SkipMe -- This case should be skipped
nestedPattern _ = Nothing
-- Issue #130; see also issue #135
extraUnderscore :: T -> T
extraUnderscore Ok1 = Ok1
extraUnderscore Ok2 = Ok2
extraUnderscore _ = Ok1 -- This underscore case is redundant and needs to be eliminated
recordPattern :: T -> ()
recordPattern Record{field = u} = u -- This pattern shouldn't fail on the record field
recordPattern _ = ()
-- Issue #132 (duplicates: #133, #134)
multipleArguments :: T -> Bool -> Bool
multipleArguments Ok1 True = False
multipleArguments Ok1 False = True
multipleArguments (NonPositive _) b = b -- The whole equation, not just the first argument, should be skipped
multipleArguments _ _ = False
listComprehension :: [T] -> [T]
listComprehension ts = [Ok1 | Ok1 <- ts] ++ [f SkipMe | NonPositive f <- ts, True]
patternGuard :: T -> T
patternGuard t | Ok1 <- t = t
| NonPositive f <- t = f t
patternGuard t | True
, Record{} <- t
, True = t
patternGuard _ = Ok2