-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Describe the bug
If I define Fibonacci sequence and use zipWith from linear-base, it throws exception starting at 3rd number
euler-hs-linear: Uncaught exception ghc-internal:GHC.Internal.Control.Exception.Base.NonTermination:
<<loop>>
I reduced my code to
import Data.Word
import qualified Data.List.Linear as Linear
import qualified Data.Num.Linear as Linear
import Data.Unrestricted.Linear (Consumable, lseq)
test :: Word32
test = fib !! 2
where
fib = 1 : 2 : Linear.zipWith (Linear.+) fib (tail fib)
-- my implementation of linear zipWith
linZipWith ∷ (Consumable a, Consumable b) ⇒ (a ⊸ b ⊸ c) → [a] ⊸ [b] ⊸ [c]
linZipWith _ [] ys = ys `lseq` []
linZipWith _ xs [] = xs `lseq` []
linZipWith f (x:xs) (y:ys) = f x y : linZipWith f xs ys
To Reproduce
Using index greater than 1 into fib will throw exception.
Expected behavior
I expected type error, if any. My implementation linZipWith works fine, no type errors, no exception.
Environment
ghc 9.12.2
linear-base 0.5
Additional context
I have no experience with Linear Types. I wanted to try it in some simple code.
Metadata
Metadata
Assignees
Labels
No labels