What is the kind of Void?

前端 未结 4 1670
醉话见心
醉话见心 2021-02-01 14:41

Seeing as the type of Void is uninhabited, can it be regarded as a type \"constructor\"? Or is this just a quick \"hack\" to be able to safely disregard / disable f

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 15:15

    Luis Casillas showed that a polymorphic type can be uninhabited in vanilla Haskell. But there are also uninhabited monomorphic types. The classic one looks like this:

    data Void = Void !Void
    
    absurd :: Void -> a
    absurd (Void x) = absurd x
    

    Imagine trying to construct something of type Void.

    void :: Void
    void = Void _
    

    You need something of type Void to fill the hole. Since that's the whole point of void, the only sensible choice is

    void :: Void
    void = Void void
    

    If the Void constructor were lazy, that would be a cyclical structure Void (Void (Void ...)). But since it's strict, void can be written equivalently as

    void = void `seq` Void void
    

    which is obviously not going to fly.

提交回复
热议问题