Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Last active April 26, 2018 05:17
Show Gist options
  • Save frasertweedale/d6154727d630f694fa129966d308e131 to your computer and use it in GitHub Desktop.
Save frasertweedale/d6154727d630f694fa129966d308e131 to your computer and use it in GitHub Desktop.
type coercion with poly-kinded phantom type
{-# 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