Skip to content

Instantly share code, notes, and snippets.

@dylnb
Last active February 18, 2017 16:20
Show Gist options
  • Save dylnb/f3c279db088194c2d072f0e931589343 to your computer and use it in GitHub Desktop.
Save dylnb/f3c279db088194c2d072f0e931589343 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
module App where
class Apply f g ret | f g -> ret where
app :: f -> g -> ret
instance Applicative f => Apply (f (a -> b)) (f a) (f b) where
fs `app` xs = fs <*> xs
instance (Applicative f, Applicative g) => Apply (f (g (a -> b))) (f (g a)) (f (g b)) where
gfs `app` gxs = pure app <*> gfs <*> gxs
funcs :: [Int -> Int]
funcs = [id]
args :: [Int]
args = [3]
test1 :: [Int]
test1 = funcs `app` args
test2 :: [[Int]]
test2 = [funcs] `app` [args]
main :: IO ()
main = print test1 >> print test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment