Haskell: 使用 ValTypes 解析错误模式

Haskell: Parse error pattern using ValTypes

谁能解释一下为什么我总是收到这个错误?特别是当不同的模块,在同一台笔记本电脑上,运行 相同的表达式可以吗?

minCompare :: ValType -> ValType -> ValType
minCompare leftSide rightSide
     leftSide == rightSide = leftSide
     leftSide < rightSide = leftSide
     otherwise = rightSide

Haskell code screenshot

在这种情况下,您不必使用模式匹配,if else 就足够了。您的函数和模式匹配语法略有偏差。 (这种情况经常发生在任何 haskell 新手身上)

import Data.Ord


minCompare :: Ord a => a -> a -> a
minCompare left right = if left >= right then left else right

minCompare' :: Ord a => a -> a -> a
minCompare' left right = case (compare left right) of
                            LT -> right
                            EQ -> left
                            GT -> left

minCompare'' :: Ord a => a -> a -> a
minCompare'' left right = case (compare left right) of
                            LT -> right
                            _ -> left

你太亲密了!您只是在条件之前缺少保护符号 |

minCompare :: ValType -> ValType -> ValType
minCompare leftSide rightSide
    | leftSide == rightSide = leftSide
    | leftSide < rightSide = leftSide
    | otherwise = rightSide