What's the absurd function in Data.Void useful for?

前端 未结 6 1830
孤街浪徒
孤街浪徒 2020-12-04 07:42

The absurd function in Data.Void has the following signature, where Void is the logically uninhabited type exported by that package:



        
6条回答
  •  执笔经年
    2020-12-04 07:55

    Generally, you can use it to avoid apparently-partial pattern matches. For example, grabbing an approximation of the data type declarations from this answer:

    data RuleSet a            = Known !a | Unknown String
    data GoRuleChoices        = Japanese | Chinese
    type LinesOfActionChoices = Void
    type GoRuleSet            = RuleSet GoRuleChoices
    type LinesOfActionRuleSet = RuleSet LinesOfActionChoices
    

    Then you could use absurd like this, for example:

    handleLOARules :: (String -> a) -> LinesOfActionsRuleSet -> a
    handleLOARules f r = case r of
        Known   a -> absurd a
        Unknown s -> f s
    

提交回复
热议问题