# Tail-recursive programs in F#

**URL:** <https://forums.fsharp.org/t/tail-recursive-programs-in-f/1308>\
**Category:** Uncategorized\
**Created:** [May 25, 2020, 10:04pm UTC](https://forums.fsharp.org/t/tail-recursive-programs-in-f/1308 "2020-05-25T22:04:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nferio](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@nferio](https://forums.fsharp.org/u/nferio)\
**Post date:** [May 25, 2020, 10:04pm UTC](https://forums.fsharp.org/t/tail-recursive-programs-in-f/1308/1 "2020-05-25T22:04:10Z")

</div>

Hi I am trying to do this exercise but can’t quite figure it out. I am given the following code in F#

```auto
type A<’a> = | D of ’a * bool
             | E of A<’a> * A<’a>

let rec g acc x = match x with
             | E(y,z) -> g (g acc z) y
             | D(a,true) -> a::acc
             | _ -> acc;;

let h x = g [] x;;

```

The exercise is now to argue if g is a tail-recursive function or not and to provide declarations of continuation-based, tail-recursive variants of both g and h. Hope someone can help!
