Created
January 4, 2015 08:03
-
-
Save tokiwoousaka/be2bb0c564b8eb0f4132 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{-# 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