Folding over a heterogeneous Record - basic example not working

Trying to get the basic example from the README of heterogeneous working. Any pointers much appreciated.

data ShowProps = ShowProps


instance showProps ::
  (Show a, IsSymbol sym) =>
  FoldingWithIndex ShowProps (SProxy sym) String a String where
  foldingWithIndex ShowProps prop str a =
    pre <> reflectSymbol prop <> ": " <> show a
    where
    pre | str == "" = ""
        | otherwise = str <> ", "

showRecord :: forall r.
  HFoldlWithIndex ShowProps String { | r } String =>
  { | r } ->
  String
showRecord r =
  "{ " <> hfoldlWithIndex ShowProps "" r <> " }"

showRecord { a: "foo" , b: 42 , c: false }

However:

No type class instance was found for
                                                        
    Heterogeneous.Folding.FoldingWithIndex ShowProps    
                                           (Proxy "bar")
                                           String       
                                           Int          
                                           t2           
                                                        

while solving type class constraint
                                                    
  Heterogeneous.Folding.FoldlRecord ShowProps       
                                    String          
                                    t1              
                                    ( bar :: Int    
                                    , baz :: Boolean
                                    , foo :: String 
                                    )               
                                    String          
                                                    
while applying a function showRecord
  of type HFoldlWithIndex ShowProps String (Record t0) String => Record t0 -> String
  to argument { foo: "foo"
              , bar: 42   
              , baz: false
              }           
while inferring the type of showRecord { foo: "foo"
                                       , bar: 42   
                                       , baz: false
                                       }

Looks like replacing this with Proxy sym has done the trick! I really should actually read the compiler output more often.

If it helps, I added a recipe for purescript-heterogeneous

2 Likes

Thanks @JordanMartinez, very helpful indeed. I also put a PR in to heterogenerous to update the README, for what its worth.