Created
November 25, 2019 16:19
-
-
Save facundominguez/2c0292bf6a721b450c46486ff3b71f24 to your computer and use it in GitHub Desktop.
Variadic operations over an abstract monad
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 DataKinds #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE IncoherentInstances #-} | |
import Control.Monad.IO.Class | |
import GHC.TypeLits | |
-- All instances are incoherent because of -XIncoherentInstances | |
class Variadic r where | |
instance {-# OVERLAPPABLE #-} MonadIO m => Variadic (m b) where | |
instance Variadic r => Variadic (a -> r) where | |
instance {-# OVERLAPPABLE #-} | |
TypeError (Text "Expected a variadic function but got: " :$$: ShowType x) | |
=> Variadic x where | |
call :: Variadic r => r | |
call = undefined | |
g :: forall m. MonadIO m => m () | |
g = do | |
let -- partial :: String -> m () | |
partial = call 'x' (5 :: Int) | |
res1 <- partial "z1" | |
partial "z2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment