By Alvin Alexander. Last updated: June 6, 2016
I’m relatively new to Haskell, so I don’t know if there are better ways to do this, but if you need to define a function that takes no input parameters and returns a value, this function type signature works:
foo :: [Char] foo = "foo"
I don’t know a good reason for using that specific approach, but I have found in test code that I want to do something with input/output, and so I needed a function that returned an IO String
, but didn’t take any input parameters, and that function definition looks like this:
bar :: IO String bar = return "bar"
Again, this probably shouldn’t be something that you need to do very often, but I have needed it several times in test code, and I can say that this function type declaration works.