gfngfn / SATySFi

A statically-typed, functional typesetting system
GNU Lesser General Public License v3.0
1.16k stars 83 forks source link

Can I write various types in a dump file? #220

Closed puripuri2100 closed 4 years ago

puripuri2100 commented 4 years ago

I want to write value of int or bool in dump file.

Can you add the following primitives?

gfngfn commented 4 years ago

Thanks for suggestion.

However, at least currently I’m not so willing to add these primitives. It seems to me that they should be implemented as ordinary user- or package-level functions, not provided as primitives; it would be simpler to make users or packages responsible for encoding/decoding values (by using satysfi-base, for example) than to add somewhat duplicated primitives.

Adding these functions as primitive seems to cause a subtle cumbersome problem: assume the functions are added as primitives, and consider the following fragment of a program:

let () = register-cross-reference-int `foo` 42 in
get-cross-reference `foo`

Which of the following behaviors do you expect this program will take on?

I think this is not so trivial. For now, avoiding this kind of problem and keep the language spec smaller seems to be a safer choice IMHO. Do you have nonetheless a strong motivation to add the functions as primitives, not as package-level functions?

puripuri2100 commented 4 years ago

I agree with that point and suggestion. We can implement with these functions. ex.

  val register-cross-reference-int : int -> string -> unit
  val get-cross-reference-int : string -> int option

  let register-cross-reference-int value label =
    register-cross-reference label (Int.to-string value)

  let get-cross-reference-int label =
    match get-cross-reference label with
    | None -> None
    | Some(s) -> Int.of-string-opt s

I sent PR with the same content to satysfi-base.

Please close this issue.