Skip to content

Instantly share code, notes, and snippets.

@cstanfill
Created July 12, 2015 17:39
Show Gist options
  • Save cstanfill/a476c360485547299eeb to your computer and use it in GitHub Desktop.
Save cstanfill/a476c360485547299eeb to your computer and use it in GitHub Desktop.
haskell tuple nth functions
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
class First a b | b -> a where
first' :: b -> a
class Second a b | b -> a where
second' :: b -> a
instance First a ((,) a b) where
first' (x,_) = x
instance First a ((,,) a b c) where
first' (x,_,_) = x
instance Second b ((,) a b) where
second' (_,y) = y
instance Second b ((,,) a b c) where
second' (_,y,_) = y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment