let sprite = pipe4 sprite_start blanks (manyTill attribute newline) blanks (fun abc _ -> Sprite(a,c)) let sprites = let rec yfx = f (yf) x // The Y Combinator //let rec sprites_up = many1Indents sprite sprites_up |>> (fun x -> SubSprites x) // Does not work. let sprites_up = y (fun f -> many1Indents sprite f |>> (fun x -> SubSprites x)) many1Indents sprite sprites_up
Here is an example from the compiler for a small game library that I am making in F #. More specifically, in the above case, I need sprites_up to call itself recursively differently, the indentation parser will not work correctly.
Without Y Combinator, I could not correctly process the parser and resort to writing something like this:
let sprites_up4 = many1Indents sprite error |>> (fun x -> SubSprites x) let sprites_up3 = many1Indents sprite sprites_up4 |>> (fun x -> SubSprites x) let sprites_up2 = many1Indents sprite sprites_up3 |>> (fun x -> SubSprites x) let sprites_up1 = many1Indents sprite sprites_up2 |>> (fun x -> SubSprites x) let sprites_up = many1Indents sprite sprites_up1 |>> (fun x -> SubSprites x)
It would not be a great solution, Y Combinator really saved me there. This, of course, is not the first thing that came to mind though.
Marko Grdinic Feb 14 '16 at 10:13 2016-02-14 10:13
source share