Skip to content

Instantly share code, notes, and snippets.

@aavogt
Created April 15, 2015 04:39
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 aavogt/1cb0ca6f1654b09111d3 to your computer and use it in GitHub Desktop.
Save aavogt/1cb0ca6f1654b09111d3 to your computer and use it in GitHub Desktop.
another variadic uncurry
{-# 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