Search code examples
smlsmlnj

How do I define my own mymod function?


I am trying to define my own mymod function where mod is usual 3 mod 2 =1 function. I dont know where to start. Any Suggestion?


Solution

  • Since you don't know where to start, here are a few hints:

    1) mymod should be an infix function. The proper syntax for this is

    infix mymod;
    fun x mymod y = ...
    

    2) You should find out how to implement mymod using -, * and \. I suggest you try out a few examples by hand before writing the function.

    3) It's up to you to handle the division by zero case.