How do I declare a function in the signature for that doesn't take arguments?
I've only seen function signatures with arguments like this: leq:item*item->bool
and I am looking to create a signature for function like this:
initBTree = E (* where empty is of type tree *)
this doesn't work: val initBTree:->tree
You can make a function that takes unit as its parameter, like this:
fun initBTree () = E
And call it like this:
initBTree ()
It has type
fn : unit -> tree
If E has type tree.
That's kinda pointless, though. You might as well just say E, or if you really want it to be called initBTree:
val initBTree = E
As you probably know all functions in SML takes exactly one argument. Thus creating a function that takes no arguments is impossible, as such a "thing" would actually just be a value.
Your code
val initBTree : -> tree
makes absolutely no sense. If you say that you have a value constructor E which is the empty tree, why would you wan't to create an init function that doesn't initialise a tree with any thing? In that case initBTree would be a synonym for E and you could do
val initBTree = E
However this would still be pointless.
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