hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Mutual Recursive Definition

Last post 07-03-2008, 21:01 by gneverov. 1 replies.
Sort Posts: Previous Next
  •  07-03-2008, 19:15 6286

    Mutual Recursive Definition

    Is it at all possible or ever be possible to define functions in terms of each other. A simple example is

    let func1 xs = map func2 xs
    let func2 ys = map func1 ys


    I know this is something you wouldn't generally do but something you would probably want to do is

    type 'a Tree = Nd of 'a * 'a Tree List
    type 'a Forest = 'a Tree List
    //fold trees
    let foldt f g (Nd(a,ts)) = f a (foldf f g ts)
    //fold forests
    let foldf f g ts =  g (map (foldt f g) ts)


  •  07-03-2008, 21:01 6287 in reply to 6286

    Re: Mutual Recursive Definition

    Sure, you want to use let rec ... and ....

    let rec func1 xs = map func2 xs
    and func2 ys = map func1 ys

    N.B. This code will have a type error but that's a different issue.

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems