hawk
hawk copied to clipboard
Merge Renderable and Rows
Renderable
is the hsl class for types that can be shown as output. Rows
is the hsp class for types that can be shown as output. This two classes are the same thing. I propose to merge the two files by unify the two concepts behind. I'm the author of Rows
, so I would like to expose the idea behind it and I would like to understand how it differs from Renderable
.
In hsp there were three different level of representation for a type a
:
-
Rows a
: in this casea
should be convertible to a list ofRow
and it declares how to do it. It is similar to hslRenderable
. The result ofrepr
is then printed usingprintRows
. For example
> printRows False (repr 1)
1
> printRows False (repr (1,2))
1
2
> printRows False (repr [1,2,3])
1
2
3
> printRows False (repr "Test")
test
> printRows False (repr (Just 1))
1
-
Row a
:a
is a single row. It is similar to hslDatum
. The result ofrepr'
is then printed usingprintRow
. For example:
> printRow False (repr' 1)
1
> printRow False (repr' (1,2))
1 2
> printRow False (repr' [1,2,3])
1 2 3
> printRow False (repr' "test")
test
> printRow False (repr' (Just 1))
1
>
-
Show a
:a
is a single value inside a collectionc
that instantiateRow
. No example, you know how it works :).
I follow this rule
-
Rows
: if the type is not a collection then just print it in one line, else print one element of the collection per line. Note that tuples are considered like collections, sorepr (1,2) == repr [1,2]
-
Row
: if the type is not a collection then just print it in one line, else print one element per column. A row is composed by column separated by some separator (in this case the space, in hsl is tab). - Maybe and other optional types: by default Representable prints "" for Nothing and the value inside Just for Just. I would like to use functions that returns Maybe but I don't want the constructor to be printed. Same for Either. My major concern about this is that the user doesn't see them.
(printRow
needs a boolean as first value that tells it if it must stop at the first error or ignore it and continue)
One major improvement could be to let the user fallback to show for debugging purpose (to see what is happening). I think this is very important, in particular if we want to keep this king of representation of Maybe. I'm a great supporter of this.
One note: I don't want necessary to separate rows usigng newline and Row values using space. That should be the standard way but I'd like to let the user configure it. I don't know how to do that, but I think it is possible, for the sake of customizability of hawk.
@ssadler's Renderable
is displaying Maybe 1
as Maybe 1
, while my experimental branch is displaying "1", like yours. In addition to Rows (which I call RenderableFile) and Row (which I call RenderableLine), I have RenderableItem, which deals with the above special case for Maybe and also for the special case for string.
Both Renderable and RenderableItem treat strings specially, by writing the raw string instead of the quoted string. I see hsp does that too, even though that's not what I would have inferred from
Show a: a is a single value inside a collection c that instantiate Row.
The only other difference I notice between the two systems is that both versions of hsl always render tuples as a tab-separated line, while you sometimes interpret them as multiple lines. Also, we use tabs, not spaces.
I understand @ssadler 's point of view about Maybe
, it can be misleading to render it as the value that it contains. But the show
output of containers like Maybe
and Either
is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam 's branch of hsl do, but also give an option -r
to the user that shows the "real form" of the output.
> hawk -e "Just 1"
1
> hawk -r -e "Just 1"
Just 1
By the way, the user can always fallback to show
to get the common representation of that value:
> hawk -e "Just 1"
1
> hawk -e "show (Just 1)"
Just 1
BTW I don't want to render Maybe a as "Maybe a", so don't worry about that :).
On 8 August 2013 14:31, Mario Pastorelli [email protected] wrote:
I understand @ssadler https://github.com/ssadler 's point of view about Maybe, it can be misleading to render it as the value that it contains. But the show output of containers like Maybe and Either is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam https://github.com/gelisam 's branch of hsl do, but also give an option -r to the user that shows the "real form" of the output.
hawk -e "Just 1" 1 hawk -r -e "Just 1" Just 1
By the way, the user can always fallback to show to get the common representation of that value:
hawk -e "Just 1" 1 hawk -e "show (Just 1)" Just 1
— Reply to this email directly or view it on GitHubhttps://github.com/ssadler/hawk/issues/17#issuecomment-22323454 .
I'm up for:
Either types should print Right to stdout and Left to stderr.
If the user wants to use 'show' then he should do that, no need for a command line option.
On 8 August 2013 16:05, Scott Sadler [email protected] wrote:
BTW I don't want to render Maybe a as "Maybe a", so don't worry about that :).
On 8 August 2013 14:31, Mario Pastorelli [email protected] wrote:
I understand @ssadler https://github.com/ssadler 's point of view about Maybe, it can be misleading to render it as the value that it contains. But the show output of containers like Maybe and Either is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam https://github.com/gelisam's branch of hsl do, but also give an option -r to the user that shows the "real form" of the output.
hawk -e "Just 1" 1 hawk -r -e "Just 1" Just 1
By the way, the user can always fallback to show to get the common representation of that value:
hawk -e "Just 1" 1 hawk -e "show (Just 1)" Just 1
— Reply to this email directly or view it on GitHubhttps://github.com/ssadler/hawk/issues/17#issuecomment-22323454 .
(printRow needs a boolean as first value that tells it if it must stop at the first error or ignore it and continue)
What recoverable error can it encounter?
For example head []
throws an exception and if the exception is not caught then the program is killed. Error are then printed on stderr but the execution continues.
As a bash scripter who always uses "set -e", I would find that really annoying. If anything fails, I want my script to stop promptly and as noisily as possible! By printing an error message to stderr, and especially by exiting with a non-zero error code.
I admit that it was an experiment to follow awk rules. In practices, when you write 'awk '{print $i}'' with i > number of words, it prints empty line. I didn't have the possibility to test this.
I didn't have the possibility to test this.
Because you don't have awk
on your machine? I do, and I confirm awk
's behaviour:
> seq 3 | tr '\n' ' ' | awk '{print $4}'
> seq 5 | tr '\n' ' ' | awk '{print $4}'
4
No I meant I didn't test hsp with this behaviour, ignoring user errors. I prefer to correct errors when I see them instead of ignoring them.
For now hawk
has exactly the awk
behaviour:
> seq 3 | tr '\n' ' ' | hsp -m '(L.!! 3) . words'
Prelude.(!!): index too large
> seq 5 | tr '\n' ' ' | hsp -m '(L.!! 3) . words'
4
The error on the first expression is printed to stderr and the empty line is printed to stdout. So it is coherent with awk
(that is not necessarily what we want).