8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Haskell で (a == 1 && a == 2 && a == 3) を真にする

Last updated at Posted at 2018-01-22

Stack Overflow の記事 Can (a ==1 && a== 2 && a==3) ever evaluate to true?
が元ネタらしい。

このコードは数字を全て a と同じ値としてしまうという方針です。

-- >>> main 
-- True
main :: IO ()
main = print (a == 1 && a == 2 && a == 3)

-- `A == A = True` となる普通の Eq インスタンスも導出する
data A = A deriving (Eq)

a :: A
a = A

instance Num A where
  -- `A` 型の整数リテラルは全て値 `A` として読む
  fromInteger _ = A
  -- のこりのメソッドはいらないので単に `undefined` にする
  (+) = undefined
  (*) = undefined
  abs = undefined
  signum = undefined
  negate = undefined
8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?