小编mrq*_*ion的帖子

当月和每月的数量天数

我有两个问题:

我怎样才能获得haskell的当前年份(不是日期)?

我怎样才能在某个月某个月获得数量天数?例如04.2011已经有30天了.

time haskell date

6
推荐指数
1
解决办法
1532
查看次数

无法匹配预期类型IO t

你能告诉我为什么我有错误'无法将预期类型IO t与推断类型字符串匹配' - 请参阅下面的内容以查看错误行:

data RectangleType = Rectangle Int Int Int deriving(Show)

menuRectangles :: [RectangleType] -> IO [RectangleType]
menuRectangles rs = do
    putStrLn "Please choose option:"
    putStrLn "3 - Show all rectangles"
    putStrLn "4 - Quit"
    putStr "Number: "
    n <- getLine
    case n of
        "3"         ->  do { showRectangles rs; menuRectangles rs }  -- this line is wrong
        "4"         ->  do { putStrLn "Quitting"; return rs }
        otherwise   ->  do { putStrLn "The End"; return rs }

showRectangles :: …
Run Code Online (Sandbox Code Playgroud)

io monads haskell types

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

在Haskell程序中键入错误

用户可以给出id,width,height和description矩形,然后将其写入文件.现在我想将这个内容从文件加载到我的程序,但是我有错误:

无法将预期类型[RectangleType]与推断类型IO [Rectangletype]匹配.在menuRectangles的第一个参数中,即db.在表达式menuRectangles db中.在do表达式menuRectangles db中.

到底是怎么回事 ?这是我的文件的内容:[矩形2 5 6"abcabc",矩形1 2 4"abcabc"]

这是代码:

import IO
import Char
import System.Exit
import Maybe


data RectangleType = Rectangle Int Int Int deriving(Show, Read)


loadFile :: FilePath -> IO [RectangleType]
loadFile fname =
    catch (do fileContent <- readFile fname
              return (read fileContent)
    ) errorHandler
    where
        errorHandler e = do putStrLn ("Error file")
                            exitFailure

db = loadFile "db.txt"


main = do
    putStrLn "Choose option:"
    n <- getLine
    case n of
        "1"         -> do menuRectangles db; main …
Run Code Online (Sandbox Code Playgroud)

io monads haskell

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

标签 统计

haskell ×3

io ×2

monads ×2

date ×1

time ×1

types ×1