Non so come esprimere bene il problema per poi magari cercare una soluzione da me. Quindi faccio un esempio:
- Codice:
import Control.Conditional
import System.IO
-- In realtà non è importante sapere cosa fanno le funzioni...
slurp :: (String -> a) -> FilePath -> IO [a]
slurp f fp = withFile fp ReadMode helper
where
helper :: Handle -> IO [a]
helper hdl = ifM (hIsEOF hdl) (return []) $ do
ln <- hGetLine hdl
fmap (f ln :) (helper hdl)
L'errore che il compilatore mi mostra è questo:
- Codice:
[...] error:
• Couldn't match type ‘a1’ with ‘a’
‘a1’ is a rigid type variable bound by
the type signature for:
helper :: forall a1. Handle -> IO [a1]
at sand.hs:30:5-30
‘a’ is a rigid type variable bound by
the type signature for:
slurp :: forall a. (String -> a) -> FilePath -> IO [a]
at sand.hs:27:1-44
Expected type: IO [a1]
Actual type: IO [a]
[...]
Mi ha distinto le due a in pratica. Come faccio a dire al compilatore "per helper voglio proprio quella a del tipo di slurp"?