F # type obj but i want 'a

I determined the type

type 'a sexp =
| E of 'a
| T of ( sexp<'a> * sexp<'a> );;

Example:

("this". (("is". "a"). ("s". "expression")))

is the string sex.

((1. 5). 2)

is int sex.


And I made a tolist function, which, given the expression, returns a list in the format.

let rec tolist expr =
match expr with
| Null -> [" "]
| E(x) -> [string x]
| T(l,r) -> 
    let l = tolist l
    let r = tolist r
    ["("]@(l)@[" . "]@(r)@[")"];;

val tolist: expr: obj sexp -> list of strings

My problem is that I want "sexp" and "obj sexp" to tell me. Where am I wrong?

The call is like tolist (T (E ("this"), E ("is"))) ;;

+4
source share
1 answer

string F # obj -> string, x E(x) obj. ( : , . "string , .ToString(). , , , : obj, obj." ) , , tolist sexp<obj> ( obj sexp - , ).

string sprintf "%A", . , , :

type 'a sexp =
| E of 'a
| T of ( sexp<'a> * sexp<'a> )

let rec tolist expr =
    match expr with
    | Null -> [" "]
    | E(x) -> [sprintf "%A" x]
    | T(l,r) -> 
        let l = tolist l
        let r = tolist r
        ["("]@(l)@[" . "]@(r)@[")"]
+5

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


All Articles