Created
July 2, 2020 12:03
-
-
Save jmatsushita/c544c34971cecfd61528fa06c996460b 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 | |
-- useR :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit | |
-- useR (NatR { nat }) x = morphS nat x -- Error! | |
-- Error: Could not match type a4 with a1 | |
-- a4 rigid type variable bound at line 17, column 34-54... | |
-- Stays at line 17 even if I move the code around. | |
-- Actually it's also the same location in my local code base... Wat? | |
useR' :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit | |
useR' (NatR h) x = morphS h.nat x -- Works | |
useR'' :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit | |
useR'' (NatR h) = morphS h.nat -- Pointfree also works | |
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