Skip to content

Add MonadFix instance for Vector #178

Closed

Description

@treeowl

I believe this should be equivalent to the MonadFix instance for []:

instance MonadFix Vector where
  mfix f
    | V.null v0 = V.empty
    | otherwise = v
    where
      v = V.generate (V.length v0)
                     (\i -> if i == 0
                            then V.head v0
                            else f (v ! i) ! i)
      v0 = fix (f . V.head)

Of course, that generate can be replaced with something slightly more efficient, but I don't know if it's worth the trouble.

Activity

  1. treeowl commented on Jul 5, 2017

    @treeowl
    ContributorAuthor

    Actually, it may be worth the trouble. We don't really want to hold on to v0 any longer than necessary. So we should likely walk over it monadically to pull the thunks out, using the MonadFix instance for ST s. I'm not completely sure that works, but I think it probably does.

  2. added 4 commits that reference this issue on Jul 5, 2017
    8ec75f0
    57f5d61
    56df7de
    915a5bb
  3. treeowl commented on Jul 11, 2017

    @treeowl
    ContributorAuthor

    Actually, some of this attempt to avoid leaks may be useless (particularly the part that forces use of runST). I'll post an update and explanation.

  4. added this to the 0.13 milestone on Jun 11, 2020
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions