Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement