作品: は、実際の型と予想される型 'IOのA0' と一致しませんでした
enumerate = \todos ->
setSGR [SetColor Foreground Vivid Red] >>=
(\_ -> putStrLn $ unlines $ map transform todos) >>
setSGR [Reset]
を動作しません:
enumerate = \todos ->
setSGR [SetColor Foreground Vivid Red] >>
putStrLn . unlines . map transform todos >>
setSGR [Reset]
を限り私はundestandすることができます、>>=
は、その後のラムダ(\_ -> ...)
で無視される変数を渡します。しかし、私はそれを>>
を使って変換し、関数の合成をしても動作しないようです。
2つ目の違いがコンパイルされない原因は何ですか?なぜこれら2つの表現が同じでないのかを知ることは素晴らしいことです。
/Users/atimberlake/Webroot/HTodo/htodo/app/Main.hs:18:25:
Couldn't match expected type ‘IO a0’ with actual type ‘a1 -> IO()’
In the second argument of ‘(>>)’, namely
‘putStrLn . unlines . map transform todos’
In the first argument of ‘(>>)’, namely
‘setSGR [SetColor Foreground Vivid Red]
>> putStrLn . unlines . map transform todos’
In the expression:
setSGR [SetColor Foreground Vivid Red]
>> putStrLn . unlines . map transform todos
>> setSGR [Reset]
/Users/atimberlake/Webroot/HTodo/htodo/app/Main.hs:18:46:
Couldn't match expected type ‘a1 -> [String]’
with actual type ‘[[Char]]’
Possible cause: ‘map’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘map transform todos’
In the second argument of ‘(.)’, namely
‘unlines . map transform todos’
は近くの投票に反対します。これは誤植ではなく、 '.'と' $ 'の仕組みの誤解です。 – amalloy
合意しました...ハスケルで他の出発点として役立つと思います。実際にはわかったはずですが、ハスケルの複雑さに取り組むときは、これらのばかげた間違いをするのが一般的です。 – Wildhoney