小编tha*_*var的帖子

从haskell中的stdin读取输入并转换为整数列表

以下代码有什么问题?我只是想在文件中以下列格式转换输入:n - 测试用例的数量// n个数字n1 n2(通过stdin读取)到整数列表并显示它?

socks :: Int -> Int
socks x = x + 1
strToInt = read :: String -> Int
strLToIntL :: [String] -> [Int]
strLToIntL xs = map (strToInt) xs
main = do
    n <- readLn :: IO Int
    mapM_ putStrLn $ map show $ strLToIntL $ fmap (take n . lines) getContents
Run Code Online (Sandbox Code Playgroud)

我运行它时收到编译错误:

Couldn't match expected type `Char' with actual type `[Char]'
Expected type: String -> [Char]
  Actual type: String -> [String]
In the second …
Run Code Online (Sandbox Code Playgroud)

haskell

5
推荐指数
1
解决办法
5253
查看次数

lambda中的非穷举模式

我在lambda中得到了非详尽的模式.我还不确定原因.请任何人如何解决它.代码如下:

import Control.Monad
import Data.List
time_spent h1 h2 = max (abs (fst h1 - fst h2)) (abs (snd h1 - snd h2))
meeting_point xs = foldl' (find_min_time) maxBound xs
where
    time_to_point p = foldl' (\tacc p' -> tacc + (time_spent p p')) 0 xs
    find_min_time min_time p = let x = time_to_point p in if x < min_time  then x else min_time

main = do
  n <- readLn :: IO Int
  points <- fmap (map (\[x,y] -> (x,y)) . map …
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
1
解决办法
2179
查看次数

标签 统计

haskell ×2