[Haskell-cafe] Is there a handy refl or refl generator for converting GADT types?
Roman
effectfully at gmail.com
Sat Jun 27 15:09:29 UTC 2020
You can define a view
viewGlobalRef :: GlobalRef s -> Either InstanceName (GlobalRef s')
viewGlobalRef FromIntegerGlobal = Right FromIntegerGlobal
viewGlobalRef FromDecimalGlobal = Right FromDecimalGlobal
viewGlobalRef (InstanceGlobal name) = Left name
but that loses the `s ~ Resolved` information in the `InstanceGlobal`
case, so I'd define and use
matchGlobalRef
:: GlobalRef s
-> (s ~ Resolved => InstanceName -> r)
-> (forall s'. GlobalRef s' -> r)
-> r
matchGlobalRef globalRef handleInstanceGlobal handleOther =
case globalRef of
FromIntegerGlobal -> handleOther FromIntegerGlobal
FromDecimalGlobal -> handleOther FromDecimalGlobal
InstanceGlobal name -> handleInstanceGlobal name
More information about the Haskell-Cafe
mailing list