Skip to content

zipWith throws NonTermination exception #491

@mirpa29

Description

@mirpa29

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions