Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Created April 3, 2011 06:51
Show Gist options
  • Save jspahrsummers/900244 to your computer and use it in GitHub Desktop.
Save jspahrsummers/900244 to your computer and use it in GitHub Desktop.
data Tuple a b c d =
OneTuple a |
TwoTuple a b |
ThreeTuple a b c |
FourTuple a b c d
tuple1 :: Tuple a b c d -> Maybe a
tuple1 (OneTuple a) = Just a
tuple1 (TwoTuple a b) = Just a
tuple1 (ThreeTuple a b c) = Just a
tuple1 (FourTuple a b c d) = Just a
tuple2 :: Tuple a b c d -> Maybe b
tuple2 (TwoTuple a b) = Just b
tuple2 (ThreeTuple a b c) = Just b
tuple2 (FourTuple a b c d) = Just b
tuple2 _ = Nothing
tuple3 :: Tuple a b c d -> Maybe c
tuple3 (ThreeTuple a b c) = Just c
tuple3 (FourTuple a b c d) = Just c
tuple3 _ = Nothing
tuple4 :: Tuple a b c d -> Maybe d
tuple4 (FourTuple a b c d) = Just d
tuple4 _ = Nothing
tupletuple :: Tuple a b c d -> Either (Either a (a, b)) (Either (a, b, c) (a, b, c, d))
tupletuple (OneTuple a) = Left (Left a)
tupletuple (TwoTuple a b) = Left (Right (a, b))
tupletuple (ThreeTuple a b c) = Right (Left (a, b, c))
tupletuple (FourTuple a b c d) = Right (Right (a, b, c, d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment