# Going from tree structure to set in F#

**URL:** <https://forums.fsharp.org/t/going-from-tree-structure-to-set-in-f/1312>\
**Category:** Uncategorized\
**Tags:** beginners\
**Created:** [May 27, 2020, 9:20am UTC](https://forums.fsharp.org/t/going-from-tree-structure-to-set-in-f/1312 "2020-05-27T09:20:05Z")\
**Posts on this page:** 2\
**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 27, 2020, 9:20am UTC](https://forums.fsharp.org/t/going-from-tree-structure-to-set-in-f/1312/1 "2020-05-27T09:20:05Z")

</div>

If I have the following type declaration in F# how would I go about creating a function that can make it into a set? This is my thoughts so far

```auto
type T<’a> = 
| A of ’a
| B of ’a * T<’a>
| C of ’a * T<’a> * T<’a>

let rec toSetHelp (t,p) acc = 
   match t with 
   | A v -> if p v then v else Set.empty
   | B (v,t1) -> if p v then toSetHelp (t1,p) (Set.add v acc) else toSetHelp (t,p) acc
   | C (v,t1,t2) -> if p v then 

```

---

<div class="post-metadata">

**Author:** ![FoggyFinder](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/foggyfinder/32/136_2.png) [@FoggyFinder](https://forums.fsharp.org/u/FoggyFinder)\
**Post date:** [May 27, 2020, 8:10pm UTC](https://forums.fsharp.org/t/going-from-tree-structure-to-set-in-f/1312/2 "2020-05-27T20:10:26Z")

</div>

Can you provide some test example? I.e simple input and desirable output?
