-
-
Save Shimuuar/3501478 to your computer and use it in GitHub Desktop.
Do magik
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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