mutual-recursion

F#: Mutually recursive functions [duplicate]

扶醉桌前 提交于 2019-12-10 02:06:09
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: [F#] How to have two methods calling each other? Hello all, I Have a scenario where I have two functions that would benefit from being mutually recursive but I'm not really sure how to do this in F# My scenario is not as simple as the following code, but I'd like to get something similar to compile: let rec f x = if x>0 then g (x-1) else x let rec g x = if x>0 then f (x-1) else x 回答1: You can also use let rec ..

F#: is mutual recursion between types and functions possible?

白昼怎懂夜的黑 提交于 2019-12-07 02:39:43
问题 I can use the and keyword to set up mutually recursive function definitions. I can also use and for mutually recursive types, but what if there is a mutually recursive relationship between a type and a function? Is my only option to make the function a member of the type or can I use something similar to and here too? Edit: Adding a simplified pseudo-example that I hope illustrates what I'm trying to do // A machine instruction type type Instruction = Add | CallMethod int (* method ID *) | ..

How is this causing an endless loop?

若如初见. 提交于 2019-12-06 03:57:16
问题 Some legacy code I'm stuck maintaining is stuck in an infinite loop (and thus I myself seem to be in one); I can't figure out why/how, though. Here's the app's entry point, where it instantiates the main form (frmCentral): CODE EXHIBIT A public static int Main(string [] args) { try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); string name = Assembly.GetExecutingAssembly().GetName().Name;

Unable to understand a mutual recursion

China☆狼群 提交于 2019-12-05 16:56:54
I am reading Programming In Haskell, in the 8th chapter, the author gives an example of writing parsers. The full source is here: http://www.cs.nott.ac.uk/~gmh/Parsing.lhs I can't understand the following part: many permits zero or more applications of p , whereas many1 requires at least one successful application: many :: Parser a → Parser [a ] many p = many1 p +++ return [ ] many1 :: Parser a → Parser [a ] many1 p = do v ← p vs ← many p return (v : vs) How the recursive call happens at vs <- many p vs is the result value of many p , but many p called many1 p , all many1 has in its definition

Is it possible to define types that depend on each other and are defined in separated files?

扶醉桌前 提交于 2019-12-05 14:23:24
I am trying to implement a library with extended parsing capabilities. I decided that I will use fsyacc because I knew it from the university. Unfortunately I encountered following problem. I defined a class for the head of my grammar ( Head ) and place its implementation in a single file. Then I defined parser as: ... %start head %type <Head> head ... Fsyacc generates seeparated module ( Parser ). In order to succeed it has to be compiled in following order: Head.fs Parser.fs In order to make this library similar to what you can find in .NET I would like to add a static Parse method to Head .

F#: is mutual recursion between types and functions possible?

ぃ、小莉子 提交于 2019-12-05 07:35:47
I can use the and keyword to set up mutually recursive function definitions. I can also use and for mutually recursive types, but what if there is a mutually recursive relationship between a type and a function? Is my only option to make the function a member of the type or can I use something similar to and here too? Edit: Adding a simplified pseudo-example that I hope illustrates what I'm trying to do // A machine instruction type type Instruction = Add | CallMethod int (* method ID *) | ... // A class representing a method definition type MethodDef (fileName : string) = member x.Params with

F#: Mutually recursive functions [duplicate]

家住魔仙堡 提交于 2019-12-05 00:08:18
Possible Duplicate: [F#] How to have two methods calling each other? Hello all, I Have a scenario where I have two functions that would benefit from being mutually recursive but I'm not really sure how to do this in F# My scenario is not as simple as the following code, but I'd like to get something similar to compile: let rec f x = if x>0 then g (x-1) else x let rec g x = if x>0 then f (x-1) else x You can also use let rec ... and form: let rec f x = if x>0 then g (x-1) else x and g x = if x>0 then f (x-1) else x To get mutually recursive functions simply pass one to the other as a parameter

Fixed point combinator for mutually recursive functions?

对着背影说爱祢 提交于 2019-12-04 17:02:38
问题 Is there a fixed point combinator for creating tuples of mutually recursive functions? I.e. I'm looking for something like the Y-Combinator but which takes multiple "recursive"* functions, and will return a tuple of functions? *: not really recursive of course, as they are written to take themselves (and siblings) as arguments, in the usual Y-Combinator way. 回答1: The creature you are looking for is Y* combinator. Basing on this page by oleg-at-okmij.org I ported the Y* to Clojure: (defn Y* [&

How is this causing an endless loop?

偶尔善良 提交于 2019-12-04 08:42:43
Some legacy code I'm stuck maintaining is stuck in an infinite loop (and thus I myself seem to be in one); I can't figure out why/how, though. Here's the app's entry point, where it instantiates the main form (frmCentral): CODE EXHIBIT A public static int Main(string [] args) { try { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); string name = Assembly.GetExecutingAssembly().GetName().Name; MessageBox.Show(string.Format("Executing assembly is {0}", name)); // TODO: Remove after testing <= this

How does python implement mutual recursion?

你说的曾经没有我的故事 提交于 2019-12-04 02:46:32
Moving to python with C/Java background, I recently had to implement a mutual recursion, but something in python is bothering me: since a python program is interpreted line by line, if I have two functions one after another in the same python file: def A(n): B(n-1) # if I add A(1) here, it gives me an error def B(n): if n <= 0: return else: A(n-1) When the interpreter is reading A , B is not yet defined, however this code does not give me an error TL;DR My understanding is that, when def is interpreted, python adds an entry to some local name space locals() with {"function name": function