Skip to content

Instantly share code, notes, and snippets.

@kavu
Created January 18, 2012 12:17
Show Gist options
  • Save kavu/1632741 to your computer and use it in GitHub Desktop.
Save kavu/1632741 to your computer and use it in GitHub Desktop.
Haskell class experiments
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, IncoherentInstances #-}
class (MyClass t) where
doShow :: (Show t) => t -> String
instance (MyClass String) where
doShow x = "Your string is " ++ x
instance (MyClass t) where
doShow x = "Your parameter is " ++ show x
instance (MyClass [t]) where
doShow x = do
let list = show $ x ++ reverse x
"Your new List is " ++ list
some :: (MyClass t, Show t) => t -> String
some = doShow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment