on master help sign in
Merge pull request #4187 from jfdm/fix-wl-laziness

Fix wl laziness

commit4f941321bf3176bc282931be94fab878a0220ae3 authorJan de Muijnck-Hughes <jfdm@users.noreply.github.com> dateThu 9 Nov 2017, 13:16 (9 years ago) parent5e7d01ce3a5c14
5 files changed+37−4
libs/contrib/Text/PrettyPrint/WL/Core.idr+5−4 test/TestData.hs+2 test/contrib001/contrib001.idr+14 test/contrib001/expected+12 test/contrib001/run+4
libs/contrib/Text/PrettyPrint/WL/Core.idr+5−4
@@ -16,7 +16,7 @@ data Doc : Type where
1616
1717 Cat : (x : Doc) -> (y : Doc) -> Doc
1818 Nest : (lvl : Int) -> (x : Doc) -> Doc
19− Union : (x : Doc) -> (y : Doc) -> Doc
19+ Union : (x : Doc) -> (y : Lazy Doc) -> Doc
2020
2121 Column : (f : Int -> Doc) -> Doc
2222 Nesting : (f : Int -> Doc) -> Doc
@@ -162,11 +162,12 @@ render rfrac w doc = best w 0 0 doc (const Empty)
162162 nicest : (lvl : Int)
163163 -> (col : Int)
164164 -> (x : PrettyDoc)
165− -> (y : PrettyDoc)
165+ -> (y : Lazy PrettyDoc)
166166 -> PrettyDoc
167167 nicest n k x y =
168− let width = min (w - k) (rwidth - k + n)
169− in if fits width x then x else y
168+ if fits (min (w - k) (rwidth - k + n)) x
169+ then x
170+ else y
170171
171172 best : (lvl : Int)
172173 -> (col : Int)
test/TestData.hs+2
@@ -84,6 +84,8 @@ testFamiliesData = [
8484 [ ( 1, ANY )]),
8585 ("buffer", "Buffer",
8686 [ ( 1, C_CG )]),
87+ ("contrib", "Contrib",
88+ [ ( 1, C_CG )]),
8789 ("corecords", "Corecords",
8890 [ ( 1, ANY ),
8991 ( 2, ANY )]),
test/contrib001/contrib001.idrnew file+14
@@ -0,0 +1,14 @@
1+module Main
2+
3+import Text.PrettyPrint.WL
4+
5+%default total
6+
7+myDoc : Doc
8+myDoc = fold (|//|) $ map text $ words "this is a long sentence with a lot of words that I can use for testing the performance of the prettier printer implementation. I need a few more words to prove my point, though."
9+
10+myString : String
11+myString = toString 0 15 $ myDoc
12+
13+main : IO ()
14+main = putStrLn myString
test/contrib001/expectednew file+12
@@ -0,0 +1,12 @@
1+thisisalong
2+sentencewitha
3+lotofwordsthatI
4+canusefor
5+testingthe
6+performanceof
7+theprettier
8+printer
9+implementation.
10+Ineedafewmore
11+wordstoprovemy
12+point,though.
test/contrib001/runnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ contrib001.idr -o contrib001 -p contrib
3+./contrib001
4+rm -f contrib001 *.ibc