purescript/purescript-record

insert and forall in record

Opened this issue · 2 comments

If i have forall in record then you can't insert

module Main where

import Prelude

import Control.Monad.Eff (Eff)
import Data.Record (insert)
import Data.Symbol (SProxy(..))
import Type.Row (class RowLacks)

type ConfigR r = (baz :: forall a. Array a | r)
type Config r = Record (ConfigR r)

add
  :: forall r
  . RowLacks "fiz" (ConfigR r)
  => Config r
  -> Config ( fiz :: String | r)
add c = insert (SProxy :: SProxy "fiz") "foo" c

error is:

  No type class instance was found for

    Prim.Union ( baz :: forall a. Array a
               | r4
               )
               ( fiz :: Entry
               )
               ( fiz :: t5
               | t6
               )

Any explanation of why it happens?

I guess if you have forall in record compiler can't calculate Union for it

You have to propagate the Union constraint, I believe. This is part of why it would be nice to have a real Prim.Row.Lacks constraint.

@natefaubion

add
  :: forall r
  . RowLacks "fiz" (ConfigR r)
  => Union (ConfigR r) ( fiz :: String) (fiz :: String | r)
  => Config r
  -> Config (fiz :: String | r)
add c = insert (SProxy :: SProxy "fiz") "foo" c

added this Union instance but still get same error