Skip to content

Question on using ToRecord #2

@bbarker

Description

@bbarker

In the following example, I get an instance not found error for ToRecordOption:

type MyRecRows  = (foo:: Int, bar:: String)
type MyRec = Record MyRecRows

recTest :: Opt.Option MyRecRows -> String
recTest myRecOpt = (show fooInt)
  <> "\n"
  <> (show $ Opt.get(SProxy :: _ "bar") myRecOpt)
  where
    fooInt :: Int
    fooInt = ((Opt.toRecord' myRecOpt) :: MyRec).foo

One point of confusion is that I think this should be returning a "maybe-fied" record, so I should really have fooInt :: Maybe Int:

recTest :: Opt.Option MyRecRows -> String
recTest myRecOpt = (show fooInt)
  <> "\n"
  <> (show $ Opt.get(SProxy :: _ "bar") myRecOpt)
  where
    fooInt :: Maybe Int
    fooInt = (Opt.toRecord' myRecOpt).foo

But the error becomes worse:

    Option.ToRecordOption t3
                          ( bar :: String
                          , foo :: Int
                          )
                          ( foo :: Maybe Int
                          | t0
                          )

Is there a suggested way around this problem?

Also, I wonder if it might be possible to have another function, toRecordMay or some such, that goes from Option opt -> Maybe rec, such that we get a populated record only if every field of the record (or, perhaps easier to reason about: every field in the option) is not Nothing*, otherwise just return Nothing. I think this could be highly useful for accumulating state incrementally.

*One exception is that if some fields of the output record are themselves Maybe values, but really we would still be requiring a value is Just x where x might be Nothing. Maybe this is worthy of its own issue to discuss separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions