Created
June 11, 2019 05:05
-
-
Save mstksg/13919be0176a82d64699ce5c34df3e28 to your computer and use it in GitHub Desktop.
Promoted MuRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc ghci --package data-reify | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Data.Reify | |
import Data.Functor.Compose | |
instance MuRef a => MuRef [a] where | |
type DeRef [a] = Compose [] (DeRef a) | |
mapDeRef | |
:: forall f u. Applicative f | |
=> (forall b. (MuRef b, Compose [] (DeRef a) ~ DeRef b) => b -> f u) | |
-> [a] | |
-> f (Compose [] (DeRef a) u) | |
mapDeRef f = fmap Compose . traverse go | |
where | |
go :: a -> f (DeRef a u) | |
go = mapDeRef @a $ \(x :: b) -> f @[b] [x] | |
main :: IO () | |
main = putStrLn "hi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment