Is Hask even a category?

https://wiki.haskell.org/Hask :

Consider:

undef1 = undefined :: a -> b
undef2 = \_ -> undefined

Note that this is not the same value:

seq undef1 () = undefined
seq undef2 () = ()

This can be a problem because undef1 . id = undef2. To make the category Hask , we define two functions fand gas one and the same morphism, if f x = g xfor all x. Thus, undef1and undef2are different meanings, but the same morphism in Hask .

What does this mean or how can I verify that: undef1and undef2- different meanings, but the same morphism?

+6
source share
1 answer

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.

+2

All Articles