rank-n-types

Generalizing from a specific type to a class in a GADT

空扰寡人 提交于 2020-01-24 00:41:04
问题 I have the following definitions {-# LANGUAGE GADTs, TypeInType, RankNTypes #-} import Data.Kind class Character (a :: * -> *) where showVal :: a b -> b -> String data ExampleCharacter a where Variable :: ExampleCharacter String EqualSign :: ExampleCharacter () Deref :: ExampleCharacter () instance Character ExampleCharacter where showVal Variable = id showVal EqualSign = const "=" showVal Deref = const "*" data Symbol :: forall a. ExampleCharacter a -> * where Terminal :: a -> Symbol (b ::

Function composition and forall'ed types

删除回忆录丶 提交于 2019-12-23 09:47:42
问题 Let's say we have some code like this, which typechecks just fine: {-# LANGUAGE RankNTypes #-} data Foo a type A a = forall m. Monad m => Foo a -> m () type PA a = forall m. Monad m => Foo a -> m () type PPFA a = forall m. Monad m => Foo a -> m () _pfa :: PPFA a -> PA a _pfa = _pfa _pa :: PA a -> A a _pa = _pa _pp :: PPFA a -> A a _pp x = _pa $ _pfa x main :: IO () main = putStrLn "yay" We note that _pp x = _pa $ _pfa x is too verbose, and we try to replace it with _pp = _pa . _pfa . Suddenly