2

if I had initialized a datatype dataype dd = DAT of int*int, how do I initialize a type of that for a function.

2 Answers 2

3

The type is called Cint, not CI, so you have to use Cint in places where a type is required:

fun cadd(a:Cint, b:Cint) =

Or you can use a different syntax, involving a pattern, if you want to keep using the datatype constructor CI:

fun cadd(a as CI _, b as CI _) =
Sign up to request clarification or add additional context in comments.

Comments

0

You can also pattern match directly in the function instead of with a case-of:

datatype Cint = CI of int * int

fun get_first_val (CI (a, _)) = a
fun get_second_val (CI (_, b)) = b

fun cadd (CI (a1, b1), CI (a2, b2)) =
  CI (a1+a2, b1+b2)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.