Skip to content

Instantly share code, notes, and snippets.

@jkoppel
Created April 1, 2019 23:56
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 jkoppel/3b0c75d78979d7c4722466eccf61fe29 to your computer and use it in GitHub Desktop.
Save jkoppel/3b0c75d78979d7c4722466eccf61fe29 to your computer and use it in GitHub Desktop.
{-# LANGUAGE AllowAmbiguousTypes, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, UndecidableInstances #-}
class Lift' m a b where
lift' :: m a -> b
instance (Applicative m) => Lift' m a (m a) where
lift' = id
instance (Applicative m, Lift' m a b) => Lift' m (x -> a) (m x -> b) where
lift' f = lift' . ((<*>) f)
lift :: forall m a b. (Applicative m, Lift' m a b) => a -> b
lift = lift' . pure @m
main = do
a <- ((lift @IO :: (String -> String -> String) -> (IO String -> IO String -> IO String)) (++)) (pure "Hello, ") (pure "world")
putStrLn a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment