jstolarek / slicer

Companion code for paper "Imperative Functional Programs that Explain their Work", Wilmer Ricciotti, Jan Stolarek, Roly Perera and James Cheney, ICFP 2017, Oxford, UK
http://dl.acm.org/citation.cfm?id=3110258
GNU General Public License v3.0
6 stars 0 forks source link

Improve pretty-printing #64

Closed jstolarek closed 7 years ago

jstolarek commented 7 years ago

Pretty-printing for larger programs is far from "pretty":

Running examples/gauss.tml
val it = let n = 4
in let as = array(n, _)
   in set(as, 0, array(n, _)) ;; set(as, 1, array(n, _)) ;; set(as, 2, array(n, _)) ;; _ ;; set(get(as, 0), 0, 3.0) ;; set(get(as, 0), 1, -1.0) ;; _ ;; _ ;; set(get(as, 1), 0, 3.0) ;; set(get(as, 1), 1, -1.0) ;; _ ;; _ ;; set(get(as, 2), 0, 1.0) ;; set(get(as, 2), 1, 2.0) ;; _ ;; _ ;; _ ;; _ ;; _ ;; _ ;; let bs = _
                                                                                                                                                                                                                                                                                                                  in _ ;; _ ;; _ ;; _ ;; let gauss = (fun gauss a
                                                                                                                                                                                                                                                                                                                                                                b => let dia = ref 0
                                                                                                                                                                                                                                                                                                                                                                     in (while !dia < n do let row = ref (!dia + 1)
                                                                                                                                                                                                                                                                                                                                                                                           in (while !row < n do let tmp = (get(get(a, !row), !dia)) / (get(get(a, !dia), !dia))
                                                                                                                                                                                                                                                                                                                                                                                                                 in let col = ref (!dia + 1)
                                                                                                                                                                                                                                                                                                                                                                                                                    in (while !col < n do let x = get(get(a, !row), !col)
                                                                                                                                                                                                                                                                                                                                                                                                                                          in set(get(a, !row), !col, x - (tmp * (get(get(a, !dia), !col)))) ;; _) ;; _ ;; let b_row = _
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          in _ ;; row := !row + 1) ;; dia := !dia + 1) ;; _)
                                                                                                                                                                                                                                                                                                                                         in let xs = gauss
                                                                                                                                                                                                                                                                                                                                                     as
                                                                                                                                                                                                                                                                                                                                                     _
                                                                                                                                                                                                                                                                                                                                            in _ : trace((double * (double * (double * double))))

Need to do something about those indentations.

jstolarek commented 7 years ago

Reported example now pretty prints as:

Running ../../examples/gauss.tml
val it = let n = 4 in
let as = _ in
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
let bs = _ in
_ ;;
_ ;;
_ ;;
_ ;;
let as' = array(n, _) in
set(as', 0, array(n, _)) ;;
set(as', 1, array(n, _)) ;;
set(as', 2, array(n, _)) ;;
_ ;;
set(get(as', 0), 0, 3.0) ;;
set(get(as', 0), 1, -1.0) ;;
_ ;;
_ ;;
set(get(as', 1), 0, 3.0) ;;
set(get(as', 1), 1, -1.0) ;;
_ ;;
_ ;;
set(get(as', 2), 0, 1.0) ;;
set(get(as', 2), 1, 2.0) ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
_ ;;
let bs' = _ in
_ ;;
_ ;;
_ ;;
_ ;;
let gauss = (fun gauss a b =>
             let dia = ref 0 in
             (while !dia < n do
                let row = ref (!dia + 1) in
                (while !row < n do
                   let tmp = (get(get(a, !row), !dia)) / (get(get(a, !dia), !dia)) in
                   let col = ref (!dia + 1) in
                   (while !col < n do
                      let x = get(get(a, !row), !col) in
                      set(get(a, !row), !col, x - (tmp * (get(get(a, !dia), !col)))) ;;
                      _)
                   ;;
                   _ ;;
                   let b_row = _ in
                   _ ;; row := !row + 1)
                ;; dia := !dia + 1)
             ;; _) in
map (fun f x => gauss fst x _) Cons (_, Cons ((as', _), _)) : trace(reslist)
rolyp commented 7 years ago

This is looking pretty nice ;)

On 20 March 2017 at 17:45, Jan Stolarek notifications@github.com wrote:

Reported example now pretty prints as:

Running ../../examples/gauss.tml val it = let n = 4 in let as = in ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; let bs = in ;; ;; ;; ;; let as' = array(n, ) in set(as', 0, array(n, )) ;; set(as', 1, array(n, )) ;; set(as', 2, array(n, )) ;; ;; set(get(as', 0), 0, 3.0) ;; set(get(as', 0), 1, -1.0) ;; ;; ;; set(get(as', 1), 0, 3.0) ;; set(get(as', 1), 1, -1.0) ;; ;; ;; set(get(as', 2), 0, 1.0) ;; set(get(as', 2), 1, 2.0) ;; ;; ;; ;; ;; ;; ;; let bs' = in ;; ;; ;; ;; let gauss = (fun gauss a b => let dia = ref 0 in (while !dia < n do let row = ref (!dia + 1) in (while !row < n do let tmp = (get(get(a, !row), !dia)) / (get(get(a, !dia), !dia)) in let col = ref (!dia + 1) in (while !col < n do let x = get(get(a, !row), !col) in set(get(a, !row), !col, x - (tmp * (get(get(a, !dia), !col)))) ;; ) ;; ;; let brow = in ;; row := !row + 1) ;; dia := !dia + 1) ;; ) in map (fun f x => gauss fst x ) Cons (, Cons ((as', ), )) : trace(reslist)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jstolarek/slicer/issues/64#issuecomment-287840886, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHY8pFhAWrSO_gbp1LuuGXgva_EXt7Zks5rnrtXgaJpZM4MNuLJ .