on master help sign in
Merge pull request #4187 from jfdm/fix-wl-laziness
4f94132Jan de Muijnck-Hughes
libs/contrib/Text/PrettyPrint/WL/Core.idr+5−4
@@ -16,7 +16,7 @@ data Doc : Type where
16
16
17 Cat : (x : Doc) -> (y : Doc) -> Doc
17 Cat : (x : Doc) -> (y : Doc) -> Doc
18 Nest : (lvl : Int) -> (x : Doc) -> Doc
18 Nest : (lvl : Int) -> (x : Doc) -> Doc
19− Union : (x : Doc) -> (y : Doc) -> Doc
19+ Union : (x : Doc) -> (y : Lazy Doc) -> Doc
20
20
21 Column : (f : Int -> Doc) -> Doc
21 Column : (f : Int -> Doc) -> Doc
22 Nesting : (f : Int -> Doc) -> Doc
22 Nesting : (f : Int -> Doc) -> Doc
@@ -162,11 +162,12 @@ render rfrac w doc = best w 0 0 doc (const Empty)
162 nicest : (lvl : Int)
162 nicest : (lvl : Int)
163 -> (col : Int)
163 -> (col : Int)
164 -> (x : PrettyDoc)
164 -> (x : PrettyDoc)
165− -> (y : PrettyDoc)
165+ -> (y : Lazy PrettyDoc)
166 -> PrettyDoc
166 -> PrettyDoc
167 nicest n k x y =
167 nicest n k x y =
168− let width = min (w - k) (rwidth - k + n)
168+ if fits (min (w - k) (rwidth - k + n)) x
169− in if fits width x then x else y
169+ then x
170+ else y
170
171
171 best : (lvl : Int)
172 best : (lvl : Int)
172 -> (col : Int)
173 -> (col : Int)
test/TestData.hs+2
@@ -84,6 +84,8 @@ testFamiliesData = [
84 [ ( 1, ANY )]),
84 [ ( 1, ANY )]),
85 ("buffer", "Buffer",
85 ("buffer", "Buffer",
86 [ ( 1, C_CG )]),
86 [ ( 1, C_CG )]),
87+ ("contrib", "Contrib",
88+ [ ( 1, C_CG )]),
87 ("corecords", "Corecords",
89 ("corecords", "Corecords",
88 [ ( 1, ANY ),
90 [ ( 1, ANY ),
89 ( 2, ANY )]),
91 ( 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