So I've been messing around with Haskell, and I've come across this strange error in my code.
" 'IO' is not applied to enough type arguments
Expected kind '?', but 'IO' has kind '->'
In the type signature for 'loop': loop :: State -> IO"
Here is the Code
import System.IO
data State = State [Int] Int Int deriving (Show)
main = do
loop (State [] 0 0)
loop::State -> IO
loop state = do
putStr "file: "
f <- getLine
handle <- openFile f ReadMode
cde <- hGetContents handle
hClose handle
putStrLn cde
loop state
How do I fix this error? Also, any insight on kinds would be greatly appreciated.
IO
is a type constructor, which means that it needs an argument in order to become a type. So:
IO Int
IO String
IO ()
are types, but IO
by itself is not.
The kind of IO
is * -> *
, which is like saying it is a function that takes a type and returns a type.
I would suggest changing
loop :: State -> IO
to
loop :: State -> IO ()
(()
is the "unit type", it has only one value (also called ()
), and is typically used where void
would be used in C-like languages)
IO
is a type constructor, not a full type. You should declare
loop :: State -> IO ()
where ()
is the unit type; the type with only one value, also spelled ()
. That's the appropriate type for an eternal loop or any other function that does not return a (meaningful) value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With