summaryrefslogtreecommitdiff
path: root/testsuite/tests/wasm/should_run/control-flow/src/Irr.hs
blob: 9604dc240486a654bb48e8b345a733aa2174fd82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}

module Irr
where

import GHC.Exts hiding (List)

data List a = Nil | Cons !a !(List a)

length'' :: Bool -> List a -> Int#
length'' !trigger !xs = if trigger then countA 0# xs else countB 0# xs
  where countA !n Nil = n
        countA !n (Cons _ as) = countB (n +# 1#) as
        countB !n Nil = n
        countB !n (Cons _ as) = countA (n +# 2#) as
        {-# NOINLINE countA #-}
        {-# NOINLINE countB #-}