Skip to content

Instantly share code, notes, and snippets.

@jmatsushita
Last active July 2, 2020 11:54
Show Gist options
  • Select an option

  • Save jmatsushita/26d86d12b21be1f84e9e396b6f0a4712 to your computer and use it in GitHub Desktop.

Select an option

Save jmatsushita/26d86d12b21be1f84e9e396b6f0a4712 to your computer and use it in GitHub Desktop.
Problem type checking with natural transformation in record type
module Main where
import Prelude
import Effect (Effect)
import Data.Foldable (fold)
import TryPureScript (h1, text, render)
data Nat m n = Nat (m ~> n)
data NatR m n = NatR { nat :: (m ~> n) }
morphS :: forall m n. Monad m => Monad n => (m ~> n) -> m Unit -> n Unit
morphS t fm = t fm
class (Monad m, Monad n) <= ClassNat nat m n where
foo :: nat -> m Unit -> n Unit
instance classNat :: (Monad m, Monad n) => ClassNat (Nat m n) m n where
foo (Nat nat) x = pure (morphS nat (pure unit)) x
-- instance classNatR :: (Monad m, Monad n) => ClassNat (NatR m n) m n where
-- foo (NatR { nat }) = pure (morphS nat (pure unit))
-- Error: Could not match type a4 with a1
-- a4 rigid type variable bound at line 17, column 34-54...
-- Wat? Stays at line 17 even if I move the code around.
-- instance classNatR' :: (Monad m, Monad n) => ClassNat (NatR m n) m n where
-- foo (NatR { nat }) x = pure (morphS nat (pure unit)) x
-- Same Error: Could not match type a4 with a1
instance classNatR :: (Monad m, Monad n) => ClassNat (NatR m n) m n where
foo (NatR n) = pure (morphS n.nat (pure unit))
main :: Effect Unit
main =
render $ fold
[ h1 (text "Try natural transformation in records!")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment