aboutsummaryrefslogtreecommitdiff
path: root/src/ContDo.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-11-07 21:39:09 +0100
committerTom Smeding <tom@tomsmeding.com>2025-11-07 21:39:09 +0100
commit4ccf1996a5bd739dfb1e62fb3bfb189c04fb6d89 (patch)
tree3f9cb86e846705c87f5539f2aecfdb2b00d76545 /src/ContDo.hs
parent92bca235e3aaa287286b6af082d3fce585825a35 (diff)
Rewrite CPSy code as do-code using QualifiedDoqualified-contdo
Credits for this trick go to Leary on IRC: https://ircbrowse.tomsmeding.com/browse/lchaskell?id=1691743#trid1691743 Advantage: all the binders are on the left-hand side. Disadvantages: - all continuations need to pass exactly one value, i.e. tuples are required - wacky shit
Diffstat (limited to 'src/ContDo.hs')
-rw-r--r--src/ContDo.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ContDo.hs b/src/ContDo.hs
new file mode 100644
index 0000000..255e21a
--- /dev/null
+++ b/src/ContDo.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MonoLocalBinds #-}
+module ContDo where
+
+import GHC.TypeLits
+
+(>>=) :: (a -> b) -> a -> b
+(>>=) = ($)
+
+class AlwaysFail a
+instance TypeError (Text "fail") => AlwaysFail a
+
+fail :: AlwaysFail a => String -> a
+fail = error