fumieval / extensible

Extensible records, variants, structs, effects, tangles
BSD 3-Clause "New" or "Revised" License
128 stars 20 forks source link

Parentheses required for functions in a Record type definition #24

Closed igrep closed 5 years ago

igrep commented 6 years ago

I'm not sure this can (or should) be fixed, but let me report for our info.

For example, in ghci, pasting the following snippet raises a type error:

:set -XTypeOperators
:set -XDataKinds
import Data.Extensible
type Foo = Record '["func" >: Int -> Bool]
<interactive>:4:19: error:
    • Expected kind ‘[Assoc k0 *]’,
        but ‘'["func" >: Int -> Bool]’ has kind ‘[*]’
    • In the first argument of ‘Record’, namely
        ‘'["func" >: Int -> Bool]’
      In the type ‘Record '["func" >: Int -> Bool]’
      In the type declaration for ‘Foo’

<interactive>:4:21: error:
    • Expected a type, but
      ‘"func" >: Int’ has kind
      ‘Assoc GHC.Types.Symbol *’
    • In the first argument of ‘Record’, namely
        ‘'["func" >: Int -> Bool]’
      In the type ‘Record '["func" >: Int -> Bool]’
      In the type declaration for ‘Foo’

Because GHC interprets "func" >: Int -> Bool as:

 ("func" >: Int) -> Bool

To avoid the error, we have to wrap the function with parentheses:

type Foo = Record '["func" >: (Int -> Bool)]
fumieval commented 6 years ago

-> effectively has -1 fixity, which is not accessible to us. I don't think there's a way to work around. You could define a synonym for -> with higher fixity though.