"unreify" combinator
- Dominant language
- Haskell
- Stars
- 105
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I'm playing around with reflection for the first time in some production code (eep) and I found a need for this function...
```haskell
unreify :: forall a f r. (forall s. f s -> r) -> (forall s. Reifies s a => f s) -> r
unreify k x = reify (error "unreify: impossible?!" :: a) (\p -> k (x `asProxyOf` p))
asProxyOf :: f s -> Proxy s -> f s
asProxyOf x _ = x
```
My use-case is trying to `Show` a data type that looks like this:
```haskell
data Foo = Foo (forall s. Reifies s Bar => What s)
instance Show (What s) -- doesn't need a 'Reifies s Bar'
instance Show Foo where
show (Foo x) = ???
```
In `???`, I have an `x :: Reifies s Bar => What s`, and I thus I need to pick some `s` such that `Reifies s Bar` (i.e. `reify` a `Bar`), but I don't have a `Bar` around, and I also know that I don't need one to show a `What s` (because I can provide a `forall s. What s -> String` function - `show`!)
I was wondering if this combinator makes sense, not necessarily for the library proper, but more as some sort of proof by parametricity that the `undefined` can't possibly be forced.
Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.