haskell / haskell/primitive

Offer an extremely general function for building immutable arrays using mutation

Open
#103 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
123
Forks
60
PR merge metrics
No merged PRs in 30d

Description

This may look a bit strange....

```haskell
create :: (forall h f g.
Applicative h => (forall x. f x -> h (g x)) -> t f -> h (t g))
-> (forall s. ST s (t (MutableArray s)))
-> t Array
create f m = runST $ m >>= f unsafeFreezeArray
```

Using something like `Vinyl`, users can use this function to use a single `ST` action to safely produce multiple arrays, of multiple types, along with arbitrary additional context. It's much easier to understand with the [Traversable](https://hackage.haskell.org/package/rank2classes-1.0.2/docs/Rank2.html#t:Traversable) class from `rank2classes`:

```haskell
runArraysHet :: Rank2.Traversable t
=> (forall s. ST s (t (MutableArray s)))
-> t Array
runArraysHet m = runST $ m >>= Rank2.traverse unsafeFreezeArray
```

but `primitive` obviously has no business depending on `rank2classes`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.