Haskell缩进问题

问题描述 投票:1回答:1

我使用Visual Studio Code作为chice的文本编辑器并且以下Haskell代码无法编译。显然是由于缩进或缺少括号错误。由于没有括号,我想知道问题出在哪里

safeSqrt :: Either String Doubble -> Either String | Doubble
safeSqrt sx =
     case sx of
         Left str -> Left str
         Right x -> if x < 0
             then Left "Error"
             else Right $ sqrt x

GHCi引发以下错误消息:

Main.hs:51:1: error:
    parse error (possibly incorrect indentation or mismatched brackets)
   |
51 | safeSqrt sx =    | ^

可以帮助他人

谢谢

汤姆

haskell indentation
1个回答
0
投票

问题不在于缩进。它带有类型签名。您在|的签名中使用了竖线字符(Either)。您应该删除它。此外,您拼写了Doubble。带有双b的双精度很好,但不幸的是,它不是Double

的名称
safeSqrt :: Either String Double -> Either String Double
safeSqrt sx =
     case sx of
         Left str -> Left str
         Right x -> if x < 0
             then Left "Error"
             else Right $ sqrt x
© www.soinside.com 2019 - 2024. All rights reserved.