Playing around with the ReadArgs package, it seems that it does not support single-argument situations.
{-# LANGUAGE ScopedTypeVariables #-}
import ReadArgs (readArgs)
main = do
(foo :: Int) <- readArgs
print foo
The error is (when using version 1.0):
No instance for (ReadArgs.ArgumentTuple Int)
arising from a use of `readArgs'
My question is twofold:
readArgs
work?N.B. version 1.1 of ReadArgs eliminates this "error"; see comments.
From what I can tell, the package uses tuples to emulate type-safe heterogeneous lists. As you noticed, this causes problems when you want only one argument, as there are no one-tuples in Haskell.
However, the package also provides a proper type for heterogeneous lists, which can be used instead of tuples: the :&
type. You use it similar to the :
operator, with the empty tuple ()
as a terminator:
(foo :: Int) :& (bar :: String) :& () <- readArgs
This works trivially with one argument:
(foo :: Int) :& () <- readArgs
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