Skip to content

Instantly share code, notes, and snippets.

@jroesch
Created March 31, 2015 07:36
Show Gist options
  • Save jroesch/53db23122aaa446ff0de to your computer and use it in GitHub Desktop.
Save jroesch/53db23122aaa446ff0de to your computer and use it in GitHub Desktop.
{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, UndecidableInstances, FlexibleInstances, OverlappingInstances, FunctionalDependencies #-}
class Cast a b | a -> b where
to :: a -> b
data Point2 = Point2 Int Int
deriving (Show)
data Point3 = Point3 Int Int Int
instance Cast Point3 Point2 where
to (Point3 x y _) = Point2 x y
class ToString a where
toString :: a -> String
instance ToString Point2 where
toString = show
instance (Cast a Point2) => ToString a where
toString x = toString $ to x
instance ToString (Point3) where
toString x = "yolo"
foo :: (ToString a) => a -> String
foo x = (toString x) ++ "X"1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment