Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Require Import Utf8 String ZArith.
  2.  
  3. (* IO is done through this JSON inductive type *)
  4. Inductive JSON :=
  5.   | JObject : list (string * JSON) → JSON
  6.   | JArray : list JSON → JSON
  7.   | JString : string → JSON
  8.   | JNumber : Z → JSON
  9.   | JBool : bool → JSON
  10.   | JNull : JSON.
  11.  
  12. (* for your specific project you need to provide two functions,
  13.    from and to your datastructure
  14.  
  15.    TODO: use lens
  16. *)
  17.  
  18. Definition to_bool (input:JSON) : option bool :=
  19.   match input with
  20.   | JBool a => Some a
  21.   | _ => None
  22.   end.
  23.  
  24. Definition to_json (input: bool) : JSON := JBool input.
  25.  
  26. (* once safely in your domain, you can do what you want with the thing. *)
  27. Definition f : bool → bool := negb.
  28.  
  29.  
  30. (* This function is called by the python wrapper *)
  31. Definition process (input:JSON) : JSON :=
  32.   match to_bool input with
  33.   | Some a => to_json (f a)
  34.   | None => JNull
  35.   end.
  36.  
  37.  
  38. Eval compute in (process (JBool false)).