Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Created January 4, 2015 08:03
Show Gist options
  • Save tokiwoousaka/be2bb0c564b8eb0f4132 to your computer and use it in GitHub Desktop.
Save tokiwoousaka/be2bb0c564b8eb0f4132 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
module Main where
type Bool' = forall a. a -> a -> a
true :: Bool'
true = const
false :: Bool'
false = const id
class Eq' a where
(.==) :: a -> a -> Bool'
data Foo = Hoge | Piyo | Fuga deriving Show
instance Eq' Foo where
Hoge .== Hoge = true
Piyo .== Piyo = true
Fuga .== Fuga = true
_ .== _ = false
--それっぽく書くための小細工
_if :: a -> a
_if = id
main :: IO ()
main = do
putStrLn $ _if (Hoge .== Hoge) "○" "✕"
putStrLn $ _if (Piyo .== Fuga) "○" "✕"
putStrLn $ _if (Fuga .== Fuga) "○" "✕"
{- 実行結果
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment