blob: 02502c087a37a3908edac6670b23f8d111c0b352 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
module Irr3 -- like Irr, but simplified
where
import GHC.Exts hiding (List)
data List = Nil | Cons !List
length'' :: Int# -> List -> Int#
length'' !trigger !xs =
case trigger of 0# -> countA 0# xs
_ -> 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 #-}
|