Reputation: 520
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
Upvotes: 3
Views: 2407
Reputation: 1826
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
Upvotes: 7
Reputation: 5944
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.
Upvotes: 1