No Linear newtypes - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Georgi Lyubenov // googleson78

Hey! is anyone familiar with the reason for why newtype constructors must be linear? e.g.

{-# LANGUAGE LinearTypes #-}

newtype Ur a where
  Ur :: a -> Ur a

doesn't work

[1 of 1] Compiling Main             ( linear.hs, interpreted )

linear.hs:4:3: error:
    • A newtype constructor must be linear
    • In the definition of data constructor ‘Ur’
      In the newtype declaration for ‘Ur’
  |
4 |   Ur :: a -> Ur a
  |   ^^^^^^^^^^^^^^^
Failed, no modules loaded.
Georgi Lyubenov // googleson78

this hints to me that linear types also carry some runtime info?

Georgi Lyubenov // googleson78

or perhaps they didn't want to limit their possibilities (in some way??) for implementation details in the future, and so forbade this for that reason

Torsten Schmits

given that you can't write an implementation for a constructor this seems like something that should be implicit

Torsten Schmits

well that they are linear by default

Georgi Lyubenov // googleson78

if you write data Bla a = MkBla a, MkBla is linear by default