summaryrefslogtreecommitdiff
path: root/testsuite/tests/stranal/sigs/T5075.hs
blob: 15b135744655b41e106afdccf2367c1e4d84817c (plain)
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
-- | This module currently asserts that we give functions that always return
-- the same constructor of a sum type the CPR property.
module T5075 where

-- Omission of the type signature is deliberate, otherwise we won't get a join
-- point (this is up to the desugarer, not sure why).
-- f :: (Ord a, Num a) => a -> Either a b
f x = case x < 10 of
  True  -> Left x
  False -> f (x*2)

-- Similarly a join point. Should WW nonetheless
g :: Int -> Int -> Maybe Int
g x y = go x
  where
    go x = case x < y of
      True  -> Just x
      False -> go (x*2)

-- Here, go is not a join point, but still should be WW'd for Just.
-- Unfortunately, CPR can't see that (+?) returns Just, so h won't get the CPR
-- property. It probably could by only considering the @Just@ case of the
-- inlined (+?).
h :: Int -> Maybe Int
h x = go x +? go (x+1)
  where
    Just x +? Just y = Just (x + y)
    _      +? _      = Nothing
    go z
      | z > 10    = Just (x + z)
      | otherwise = go (z*2)