Skip to content

Is multiplicity multiplication available to the user?

Summary

I wanted to reproduce the multiplicity-polymorphic composition example from the Linear Haskell paper, but the compiler seems to be failing on multiplicity multiplication. Is multiplicity multiplication even supported? From a quick chat with @aspiwack at ICFP, I got a feeling that it is but regardless of the answer it would be nice to add a note about it in the docs (I wasn't able to find the answer on the wiki page either).

Steps to reproduce

Here's recent head:

❯ ghci
GHCi, version 9.3.20210826: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/artem/.ghci

λ> :! cat lin.hs
{-# language LinearTypes, RankNTypes #-}

comp :: forall {p} {q} a b c.
  (b %p -> c) %1 ->
  (a %q -> b) %p ->
  a           %(p * q) ->
  c
comp f g x = f (g x)

λ> :l lin.hs
[1 of 1] Compiling Main             ( lin.hs, interpreted )

lin.hs:6:17: error:
    • Expected kind ‘*
                     -> GHC.Types.Multiplicity -> GHC.Types.Multiplicity’,
        but ‘p’ has kind ‘GHC.Types.Multiplicity’
    • In the type signature:
        comp :: forall {p} {q} a b c. (b %p -> c)
                                      %1 -> (a %q -> b) %p -> a %(p (*) q) -> c
  |
6 |   a           %(p * q) ->
  |                 ^^^^^
Failed, no modules loaded.

Expected behavior

The file correctly type checks and loads.

Environment

  • GHC version used: HEAD from 2021-08-26

Optional:

  • Operating System: Linux
  • System Architecture: x86-64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information