<div>Mercury types get Haskell's <span style="background-color:rgb(252, 252, 252)"><span style="color:rgb(64, 64, 64)"><span style="font-family:Lato, proxima-nova, "Helvetica Neue", Arial, sans-serif"><span style="font-size:16px">Eq, Show, Read, and Ord by default.</span></span></span></span><br></div><div><br></div><div>:- module stringex.<br></div><div>:- interface.<br></div><div>:- import_module io.<br></div><div>:- pred main(io::di, io::uo) is det.<br></div><div>:- implementation.<br></div><div>:- import_module string, list.<br></div><div><br></div><div>:- type char_type ---> ws; chr; op; cp; ol; cl; om; cm; sq; dq; tk.<br></div><div>:- type tokstate<br></div><div>        --->    skip_ws<br></div><div>        ;       eat_token.<br></div><div><br></div><div>main(!IO) :-<br></div><div>    S1 = string.string(skip_ws),<br></div><div>    X = om,<br></div><div>    io.format("%s %s\n", [s(S1), s(string(X))], !IO).<br></div><div><br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div> On Tuesday, May 11, 2021 3:10 PM, Sean Charles (emacstheviking) <objitsu@gmail.com> wrote:<br></div><div> <br></div><blockquote class="protonmail_quote" type="cite"><div>How do you convert a discriminated union to a printable string? I have this:<br></div><div class><br></div><div class><span style="font-family:Courier">    % Character classification types.<br class>:- type char_type ---> ws; chr; op; cp; ol; cl; om; cm; sq; dq; tk.<br class>:- type tokstate<br class>        --->    skip_ws<br class>        ;       eat_token.</span></div><div class><br></div><div class>Do I have to explicitly code a predicate for each type I define or not? In Haskell I can just add (show) to the definition and it does the write(!) thing. Can Mercury do that other than using io.print_line, sometimes I don’t want a new line!<br></div><div class><br></div><div class>Thanks<br></div><div class>Sean<br></div><div class><br></div><div class><br></div></blockquote><div><br></div>