Last active
February 18, 2017 16:20
-
-
Save dylnb/f3c279db088194c2d072f0e931589343 to your computer and use it in GitHub Desktop.
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 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