在 PureScript 上按 maybe 类型拆分大小写

Case split on a maybe type on PureScript

我正在按照 PureScript by example, and by chapter 3 (rest of definitions there) there is an exercise to delete duplicate entries from a bog, but I cannot get to work the case split for the Maybe (Nothing/Just e). I checked also the syntax guide 学习 PureScript,但我无法抓住陷阱并继续获得 Unknown data constructor Nothing

import Prelude    
import Data.AddressBook
import Control.Plus (empty)
import Data.List (List(..), (:), filter, head, foldl, tail)
import Data.Maybe (Maybe, isJust)
import Data.Newtype (overF)

skipIfDup :: AddressBook -> AddressBook -> AddressBook
skipIfDup newBook (Nil : book) = newBook
skipIfDup newBook (entry : book) =
    skipIfDup newerBook book
    where
        newerBook :: AddressBook
        newerBook = 
            case findEntry entry.firstName entry.lastName newerBook of
                Nothing -> newBook
                Just e -> insertEntry e newBook

"Unknown data constructor Nothing" 意思就是它所说的:编译器不知道 Nothing 是什么,它在哪里定义。

你如何让它知道它的定义位置?与您在程序中使用的所有其他内容相同 - 使用 import!

您已经有了 import Data.Maybe (Maybe),但这还不够:这只导入了类型 Maybe,而不是它的构造函数。

要导入 Nothing 构造函数,请将其添加到括号中的类型之后,如下所示:

import Data.Maybe (Maybe(Nothing), isJust)

或者您可以使用两个点来导入所有存在的构造函数:

import Data.Maybe (Maybe(..), isJust)

后者是更容易接受的模式。