小编nar*_*ama的帖子

Purescript - 无法统一类型

我是Purescript(以及Haskell)的新手,我遇到了一个无法统一的错误.最初我有:

newtype Domain = Domain String

newtype Keyword = Keyword String

type Result = {
        domain    :: Domain,
        occurred   :: Boolean,
        position  :: Number,
        quality   :: Number
    }

is_min_pos :: Maybe Result -> Maybe Result -> Maybe Result
is_min_pos Nothing Nothing = Nothing
is_min_pos Nothing y = y
is_min_pos x Nothing = x
is_min_pos x y = if y.position < x.position then y else x     
Run Code Online (Sandbox Code Playgroud)

这给了我错误

Cannot unify type
  Prim.Object
with type
  Data.Maybe.Maybe
Run Code Online (Sandbox Code Playgroud)

我以为是因为期待x和y是Maybe Record类型.所以要明确我将代码改为,按类型进行模式匹配.

data Result = Result { …
Run Code Online (Sandbox Code Playgroud)

unify purescript

3
推荐指数
1
解决办法
301
查看次数

标签 统计

purescript ×1

unify ×1