Last active
July 2, 2020 11:54
-
-
Save jmatsushita/26d86d12b21be1f84e9e396b6f0a4712 to your computer and use it in GitHub Desktop.
Problem type checking with natural transformation in record type
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
| 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