Skip to content

Add MonadFix instance for Vector #178

Closed
@treeowl

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.

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