Haskell has a Data.Map module which includes, among other functions, a !
function.
fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map
fromList [(5,'a'), (3,'b')] ! 5 == 'a'
While I can import other functions from the Data.Map module into my code...
import Data.Map(Map, keys, fromList)
...the following does NOT work...
import Data.Map(Map, keys, fromList, !)
I get the following error:
parse error on input `!'
What is the correct syntax to import items like !
?
The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.
It's a strictness declaration. Basically, it means that it must be evaluated to what's called "weak head normal form" when the data structure value is created.
A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.
A module in Haskell serves the dual purpose of controlling name-spaces and creating abstract data types.
The correct answer is to wrap the function name (really, it's an operator: a special case of a function) in parentheses, like so...
import Data.Map(Map, keys, fromList, (!))
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