Skip to content

Instantly share code, notes, and snippets.

@mstksg
Created June 11, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstksg/13919be0176a82d64699ce5c34df3e28 to your computer and use it in GitHub Desktop.
Save mstksg/13919be0176a82d64699ce5c34df3e28 to your computer and use it in GitHub Desktop.
Promoted MuRef
#!/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