Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,869
    • Issues 4,869
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19642
Closed
Open
Created Apr 02, 2021 by jberryman@trac-jberryman

Clarifications to LinearTypes entry in users guide

Summary

I'm just starting to try to understand linear types, from the users guide: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/linear_types.html

I've made my best effort to read the entry closely a couple times, as well as experiment a little, and have some questions. I don't understand things well enough to offer a PR that improves things, unfortunately; hopefully hearing what's confusing to a newbie is constructive.

I don't understand what "use" or "consume" means.

The bulleted definition doesn't seem sufficient. aspiwack-tweag on reddit suggests "use" has something to do with evaluation, and so I wonder if a base case should be added to that bullet list. I'm looking for something precise, like the docs for seq.

"multiplicity polymorphism" feels pretty slippery

The docs begin...

A function f is linear if: when its result is consumed exactly once, then its argument is consumed exactly once.

So I expect that...

id a = a

...is by that definition linear.

Yet we can give it the type signature id :: a %m -> a, which my intuition says ought to be a rigid type error. Maybe multiplicity is just a little... weird? It would help to call that out in the docs if so, even if a more satisfying answer is too much for the users guide.

Related: it seems only a function that "is linear" can be declared multiplicity-polymorphic. If that's so, I think adding this observation to the docs would help people like me.

The datatypes section starts talking about "linear fields" without defining them

It seems like "linear field" means a field that doesn't have to be "consumed exactly once" if it's on the LHS of a linear arrow. If that's so maybe an explanation to that effect to lead off the data types section, and a caveat mention in the "Pattern-matching" bullet point

In general I find it confusing to be using "unrestricted" or "linear" to refer to both values and arrows, but maybe that's pedantic.

Environment

  • ghc 9.1.20201218 (what I have on hand...)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking