purescript-record icon indicating copy to clipboard operation
purescript-record copied to clipboard

insert and forall in record

Open safareli opened this issue 7 years ago • 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

safareli avatar Apr 10 '18 18:04 safareli

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 avatar Apr 10 '18 18:04 natefaubion

@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

safareli avatar Apr 10 '18 18:04 safareli