How to extract data from F # list

Following my previous question , I am slowly getting FParsec freezes (although this is especially hard for me to understand).

My next novice F # question is, how can I extract data from a list created by the parser?

For example, I downloaded the sample code from the previous question into a module called Parser.fs and added a very simple unit test to a separate module (with corresponding links). I am using XUnit:

open Xunit

[<Fact>]
let Parse_1_ShouldReturnListContaining1 () =
    let interim = Parser.parse("1")
    Assert.False(List.isEmpty(interim))

    let head = interim.Head // I realise that I have only one item in the list this time
    Assert.Equal("1", ???) 

Interactively, when I do a parsing of "1" , the answer is:

val it : Element list = [Number "1"]

and by changing the list of valid operators, I can run the syntax "1 + 1" to get:

val it : Element list = [Number "1"; Operator "+"; Number "1"]

What I need to add instead ? , , ..?

+3
1

F # ( ) . , , F #, =, true, .

, Element , F # ( ), :

Assert.Equal(interim, [Number "1"; Operator "+"; Number "1"])

, ;

let expected = [Number "1"]
match interim, expected with
| Number a, Number b when a = b -> true
| _ -> false
+7

Source: https://habr.com/ru/post/1785715/


All Articles