Skip to content

Instantly share code, notes, and snippets.

@Shimuuar
Forked from qnikst/magick.hs
Created August 28, 2012 18:02
Show Gist options
  • Save Shimuuar/3501478 to your computer and use it in GitHub Desktop.
Save Shimuuar/3501478 to your computer and use it in GitHub Desktop.
Do magik
import Data.Default
import Debug.Trace
data Proxy a = Proxy
class Magick a where
magickStorage :: Proxy [a] -> String
instance Magick Int where
magickStorage = const "Int"
instance Magick Char where
magickStorage = const "String"
instance Default Char where
def = '\0'
doMagick :: (Default a, Magick a) => [a]
doMagick = inner Proxy
where inner :: (Default a, Magick a) => Proxy [a] -> [a]
inner s | trace (magickStorage s) True = [def]
{-
% runhaskell magick.hs
Int
[0]
String
"\NUL"
-}
main = do
let x = doMagick :: [Int]
y = doMagick :: String
print x
print y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment