Why is GHC complaining about non-exhaustive patterns?

后端 未结 3 1306
梦如初夏
梦如初夏 2020-12-10 10:19

When I compile the following code with GHC (using the -Wall flag):

module Main where

data Tree a = EmptyTree | Node a (Tree a) (Tree a) derivin         


        
3条回答
  •  悲哀的现实
    2020-12-10 11:11

    GHC is not able to infer whether your three guards in the insert x (Node a left right) cover all possible cases, and consequently there will be no body to be associated with insert x (Node a left right). Try replacing the last condition x > a with otherwise (a synonim for True). In this specific case however, it's true that the guards do not cover all cases, see augustss' example about double numbers.

提交回复
热议问题