Haskell , "", , "" .
, (, 2 3 Integer) . , sqrt id Double -> Double, , @pigworker, , "" :
sqrt 4 = 2
id 4 = 4
, sqrt id - . , .
undef1 undef2 () -> (), :
undef1, undef2 :: () -> ()
undef1 = undefined
undef2 = \_ -> undefined
, ?
, , , . :
> seq undef1 ()
*** Exception: Prelude.undefined
> seq undef2 ()
()
>
, GHCi. , Haskell:
seq undef1 ()
-- use defn of undef1
= seq undefined ()
-- seq semantics: WHNF of undefined is _|_, so value is _|_
= _|_
seq undef2 ()
-- use defn of undef2
= seq (\_ -> undefined) ()
-- seq semantics: (\_ -> undefined) is already in WHNF and is not _|_,
-- so value is second arg ()
= ()
, ? , Hask , , () , / .
/ : ( ) , . / . Hask Haskell ( ), , , .
, undef1 undef2 , , Haskell .
, undef1 . id undef2, , . , , . , . .
, Hask. id ( ) Hask, :
undef1
= undef1 . id -- because `id` is identity
= undef2 -- same value
undef1 /= undef2 - , undef1 = undef2 .
- Hask Haskell.
Hask, , - , f g , f x = g x x ( _|_). , . f x g x , , , f x = g x f x g x f x g x? .
undef1 undef2 , undef1 x = undef2 x x () ( () _|_). , (), :
undef1 ()
-- defn of undef1
= undefined ()
-- application of an undefined function
= _|_
undef2 ()
-- defn of undef2
= (\_ -> undefined) ()
-- application of a lambda
= undefined
-- semantics of undefined
= _|_
_|_, :
undef1 _|_
-- defn of undef1
= undefined _|_
-- application of an undefined function
= _|_
undef2 _|_
-- defn of undef2
= (\_ -> undefined) _|_
-- application of a lambda
= undefined
-- semantics of undefined
= _|_
, undef1 . id undef2 Hask ( , , Hask ), .
, , @nm, , , Haskell Hask > , , , Hask .
, undef1 . id = undef2 Haskell
, , .
f g, , - , x WHNF seq. f g Hask, f x = g x x, . , , , WHNF, ( ), undefined.
, undef1 . id undef2 , , undefined WHNF. , WHNF:
undef1 . id
-- defn of composition
= \x -> undef1 (id x)
-- this is a lambda, so it is in WHNF and is defined
undef2
-- defn of undef2
= \_ -> undefined
-- this is a lambda, so it is in WHNF and is defined
, undef1 x = undef2 x x. , :
(undef1 . id) x
-- defn of composition
= (\x -> undef1 (id x)) x
-- lambda application
= undef1 (id x)
-- defn of id
= undef1 x
Haskell x, , (undef1 . id) x = undef2 x x. , WHNF , , , undef1 . id = undef2 Haskell.