Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write mutually recursive functions within a let binding in SML?

Tags:

sml

smlnj

I would like to do something like this:

fun f () =
    let
      fun a() = b()
    and
      fun b() = a()
    in
      ()
    end

where a and b are sensible mutually recursive functions. However, this gives:

Error: syntax error: replacing  AND with  SEMICOLON

Is there any way to do this?

like image 583
user1339898 Avatar asked Apr 17 '12 22:04

user1339898


People also ask

What is a mutually recursive function?

In mathematics and computer science, mutual recursion is a form of recursion where two mathematical or computational objects, such as functions or datatypes, are defined in terms of each other.

Which keyword is used to define a recursive function?

The rec keyword is used together with the let keyword to define a recursive function.


1 Answers

Declaration of mutually recursive functions in SML is marked by a fun ... and ... block:

fun f () =
  let
    fun a() = b()
    and b() = a() (* There is no 'fun' keyword before b() *)
  in
    ()
  end
like image 74
pad Avatar answered Oct 11 '22 15:10

pad