Last active
April 26, 2018 05:17
-
-
Save frasertweedale/d6154727d630f694fa129966d308e131 to your computer and use it in GitHub Desktop.
type coercion with poly-kinded phantom type
This file contains 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
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE DataKinds #-} | |
module Poly where | |
data Mode = Mode1 | Mode2 | |
data Action ctx a = Action | |
-- | Coerce the phantoms (poly-kinded) | |
-- | |
coerceAction :: Action ctx a -> Action ctx' a | |
coerceAction Action = Action | |
-- 'coerceAction' specialised to restrict input ctx to kind Mode | |
-- and output ctx to (). This is not required (see 'x' below); | |
-- merely a demonstration that 'coerceAction' is poly-kinded. | |
-- | |
coerceActionModeToUnit :: Action (ctx :: Mode) a -> Action () a | |
coerceActionModeToUnit = coerceAction | |
x :: Action () () | |
x = coerceAction (Action :: Action 'Mode1 ()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment