tweag / tweag/linear-base

A way to enforce uniqueness in typeclass instances

Open
#183 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bikeshedding
Dominant language
Haskell
Stars
359
Forks
45
PR merge metrics
No merged PRs in 30d

Description

Most linear data structures require a way to enforce and maintain their uniqueness. And we have a few different ways to satisfy this requirement (see #130). However, some typeclass functions does not provide a way to enforce this property, so we can not implement them neatly as we'd like to.

Below is an example (originally posted at https://github.com/tweag/linear-base/issues/130#issuecomment-689509565)

Most operations on linear mutable vectors rely on the vector being unique, so the usual way to create a vector is to take a linear callback (alloc :: ... -> (Vector a #-> Unrestricted b) #-> Unrestricted b).

Today, I was implementing the Monoid instance for linear mutable vectors. Implementing mappend went well, since we already get two vectors, we can create a new one using the fact that we have access to some unique values.

However, I had a problem when implementing mempty :: a, because it doesn't provide a way to create a unique value. With the suggestion on #130 , we could have something like mempty :: Source #-> a instead. Otherwise, I need something like mempty :: forall b. (a #-> Unrestricted b) #-> b which is not pretty. Or we somehow have to accept that linear mutable vectors (at least with the current representation) are not monoids.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading this issue alongside #130, then examine the typeclass signatures discussed here, especially Monoid.mempty and the linear mutable vector example. Done would require an agreed design for enforcing uniqueness in typeclass instances; this issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.