F# DSL

I wanted to automate reveal from F#  with a DSL that will be available also in C#.

My thought it was to put information( text of picture)  on the left, right, top , bottom and middle .

let example = 
        pages {
           put (Content.TextString "this is string") To Page 2 At POSITION.Middle
           put (Content.TextString "This is text on the left") To Page 1 At POSITION.Left 
           put (Content.Picture "this is picture") To Page 2 At POSITION.Middle
           put (Content.TextString "this is right") To Page 1 At POSITION.Right
           put (Content.TextString "This is wrong") To Page 1 At POSITION.Left 
           put (Content.TextString "This is good") To Page 1 At POSITION.Middle
           
        }

Also , this should take into account the fact that the user could edit and have duplicate information ( e.g. in the above example Page 2 At POSITION.Middle have twice  content.

So I will have something like:

  for item in example.verifyPages do
        printfn "We have %s" (item.ToString())

that lists duplicate items on pages

Without further ado , this is the code in F#

namespace RevealGenObjects
open System
open System.Linq.Expressions
open System.IO

type POSITION =
    | Left 
    | Right
    | Middle
    | Top
    | Bottom
    with
        override this.ToString() =
            match this with
            | Left -> "Left"
            | Right -> "Right"
            | Middle -> "Middle"
            | Top -> "Top"
            | Bottom -> "Bottom"

type Content = 
    | TextString of string
    | Picture of string   

type PageSimple = int
    

[]
module DSL =
    // Dummy tokens
    type To = To
    type At = At
    type Page= Page

    type Items = Items of (PageSimple * POSITION * Content ) list with
            member this.Lines =
                    match this with
                        | Items items -> items

            member this.Pages = 
                    match this with
                        | Items items-> items |> List.sortBy(fun (a,_,b) -> a,b) 

            member this.verifyPages = 
                    match this with 
                        | Items items-> items 
                        |> Seq.groupBy(fun(a,b,_) ->(a,b)) 
                        |> Seq.map snd 
                        |> Seq.filter (fun s ->  s |>Seq.length  > 1) 
                        |> Seq.concat
                        |> Seq.sortBy (fun (a,_,b) -> a,b)
                        

    
    type Lines() =  
        member x.Yield (()) = Items []
        []
        member x.Find (Items sources,c:Content ,  t:To, pg:Page,ps:PageSimple,a:At,  p: POSITION) =
            Items [ yield! sources
                    yield ((ps,p,c)) ]
  
    let pages = Lines()

It is amazing what you can achieve with F# in some lines…