summaryrefslogtreecommitdiff
path: root/compiler/coreSyn
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2013-09-13 18:40:36 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2013-09-13 21:58:26 +0200
commit17a868afa169c52d8525a95cbed87b2fc12044c6 (patch)
treea04530408077a286a80ca8d34c5d6dc0c98eddc6 /compiler/coreSyn
parent638da2fecaaaf743c4da7f8e2522f4afc0d8400c (diff)
downloadhaskell-coercible.tar.gz
Introduce coerce :: Coercible a b -> a -> bcoercible
This is the result of the design at http://ghc.haskell.org/trac/ghc/wiki/NewtypeWrappers The goal is to be able to convert between, say [First Int] and [Last Int] with zero run-time overhead. To that end, we introduce a special two parameter type class Coercible whose instances are created automatically and on-the fly. This relies on and exploits the recent addition of roles to core.
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r--compiler/coreSyn/MkCore.lhs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/coreSyn/MkCore.lhs b/compiler/coreSyn/MkCore.lhs
index c6fc2be21f..656ffa8184 100644
--- a/compiler/coreSyn/MkCore.lhs
+++ b/compiler/coreSyn/MkCore.lhs
@@ -28,6 +28,9 @@ module MkCore (
-- * Constructing/deconstructing equality evidence boxes
mkEqBox,
+ -- * Constructing Coercible evidence
+ mkCoercible,
+
-- * Constructing general big tuples
-- $big_tuples
mkChunkified,
@@ -305,6 +308,11 @@ mkEqBox co = ASSERT2( typeKind ty2 `eqKind` k, ppr co $$ ppr ty1 $$ ppr ty2 $$ p
where Pair ty1 ty2 = coercionKind co
k = typeKind ty1
+mkCoercible :: Coercion -> CoreExpr
+mkCoercible co = ASSERT2( typeKind ty2 `eqKind` k, ppr co $$ ppr ty1 $$ ppr ty2 $$ ppr (typeKind ty1) $$ ppr (typeKind ty2) )
+ Var (dataConWorkId coercibleDataCon) `mkTyApps` [ty1, ty2] `App` Coercion co
+ where Pair ty1 ty2 = coercionKind co
+ k = typeKind ty1
\end{code}
%************************************************************************