相关疑难解决方法(0)

Haskell"where"缩进:为什么必须缩进标识符?

这段代码:

import Data.Char (digitToInt)

myInt :: String -> Int
myInt [] = error "bad input: empty string"
myInt (x:xs)
  | x == '-'  = -1 * myInt xs
  | otherwise = foldl convert 0 (x:xs)
  where convert acc x
        | x `elem` ['0'..'9'] = 10 * acc + digitToInt x
        | otherwise           = error ("bad input: not an int - " ++ [x])
Run Code Online (Sandbox Code Playgroud)

失败:

import Data.Char (digitToInt)

myInt :: String -> Int
myInt [] = error "bad input: empty string" …
Run Code Online (Sandbox Code Playgroud)

haskell indentation

22
推荐指数
3
解决办法
7807
查看次数

标签 统计

haskell ×1

indentation ×1