-
Notifications
You must be signed in to change notification settings - Fork 16
Description
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).fooOne 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).fooBut 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.