Skip to content

Lazy List's mapWithIndex is not lazy #218

Description

@worldmaker18349276

mapWithIndex f = foldrWithIndex (\i x acc -> f i x : acc) nil

The implementation of FunctorWithIndex for Lazy List uses folding, which, unlike Functor, is not lazy.

It should be:

instance functorWithIndexList :: FunctorWithIndex Int List where
  mapWithIndex f xs = List (go 0 <$> unwrap xs)
    where
    go i = \step -> case step of
      Nil -> Nil
      Cons x xs' -> Cons (f i x) (List (go (i + 1) <$> unwrap xs'))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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