Skip to content

Instantly share code, notes, and snippets.

@facundominguez
Created November 25, 2019 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save facundominguez/2c0292bf6a721b450c46486ff3b71f24 to your computer and use it in GitHub Desktop.
Save facundominguez/2c0292bf6a721b450c46486ff3b71f24 to your computer and use it in GitHub Desktop.
Variadic operations over an abstract monad
{-# 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