Created
April 15, 2015 04:39
-
-
Save aavogt/1cb0ca6f1654b09111d3 to your computer and use it in GitHub Desktop.
another variadic uncurry
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 FlexibleContexts #-} | |
{-# LANGUAGE IncoherentInstances #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Olaf where | |
{- | | |
>>> eval (+) (1,2) :: Int | |
3 | |
>>> eval (+) 1 2 :: Int | |
3 | |
>>> eval (+) 1 (2 :: Int) | |
3 | |
>>> eval (+) (1 :: Int) 2 | |
3 | |
>>> eval (,,) (1,2) 3 | |
(1,2,3) | |
>>> eval (,,) 1 (2,3) :: (Int,Int,Int) | |
(1,2,3) | |
-- the wrong instance is chosen: | |
>>> eval (+) (1 :: Int,2) | |
... | |
...No instance for (Show ((Int, ...) -> (Int, ...))) | |
... | |
>>> eval (,,) 1 (2,3) | |
... | |
...No instance for (Show (... -> ... | |
... | |
-} | |
class Uncurry f r where | |
eval :: f -> r | |
instance (a ~ a') => Uncurry a a' where | |
eval = id | |
instance (a ~ a', Uncurry f (b -> c)) => Uncurry (a -> f) ((a', b) -> c) where | |
eval f (a,b) = eval (f a) b | |
instance (a ~ a', Uncurry f c) => Uncurry (a -> f) (a' -> c) where | |
eval f a = eval (f a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment