Why this function composition is illegal
haskell, syntax
Solution
You left the `map` out of your "superposition" (composition):
h <- fmap (map (read :: String -> Int)) $ fmap lines (readFile "d:\\tmp\\h.txt")
You can simplify that to
h <- fmap (map (read :: String -> Int) . lines) (readFile "d:\\tmp\\h.txt")
If you put an `import Control.Applicative` line at the top of your source file (or enter `:m +Control.Applicative` if you're using ghci interactively), you can use the `<$>` operator instead of `fmap` to make it look cleaner. (They do exactly the same thing, they're just spelled differently.)
h <- map (read :: String -> Int) . lines <$> readFile "d:\\tmp\\h.txt"
Finally, if you do need the type signature, you might find it looks clearer at the end of the line.
h <- map read . lines <$> readFile "d:\\tmp\\h.txt" :: IO [Int]
Problem
This works: ``` c <- fmap lines (readFile "d:\\tmp\\h.txt") let h = map (read :: String -> Int) c ``` while "superposition" of those two lines those not compile `fmap (read :: String -> Int) $ fmap lines (readFile "d:\\tmp\\h.txt")` it generates error: ``` interactive:1:36: Couldn't match expected type `Char' with actual type `[Char]' Expected type: String -> String Actual type: String -> [String] In the first argument of `fmap', namely `lines' In the second argument of `($)', namely `fmap lines (readFile "d:\\tmp\\h.txt") ``` Why it does not compile and how to do this in one line? What I want is achieve a simplicity of python ``` [int(i) for i in open("d:\\tmp\\h.txt")] ```