
The Mercury programming language - panic
https://www.mercurylang.org
======
mikeday
We use Mercury at YesLogic to write Prince, our HTML to PDF formatter! [1]

We chose it because logic/functional languages are great for tree processing,
Mercury was designed for large projects, and because in 2002 there really
weren't many other options around.

Its syntax and semantics are derived from Prolog, it borrows a lot from
Haskell (types, type classes), in spirit it's reminiscent of OCaml (niche,
little weird) and with support for unique modes there is some interesting
overlap with Rust, although this aspect of the language still needs more
compiler support.

All in all, definitely worth checking out.

[1] [https://www.princexml.com/](https://www.princexml.com/)

~~~
mpweiher
I've seen a bunch of these (HTML -> PDF). I've never seen a succinct answer
to: "How is this different/better than taking <random web browser> and hitting
"print", which at least on OS X will produce a nice PDF?"

~~~
lillesvin
I'm not the guy you asked but I've been using PrinceXML to produce PDFs
intended for customers of our client (e.g. invoices, terms and conditions,
itineraries, etc.). Sure, we could just display the HTML and let either the
customer or the sales agent press "Print to PDF" but it's not very user
friendly—non-power users may not know that "print to PDF" is even an
option—nor is it particularly practical for batch processing.

Full disclosure: If I'd had my way we would have used LaTeX templates to
produce the PDFs but the previous developers had already implemented the
HTML->PDF flow, so we just replaced the old, defunct service with Prince,
which did a surprisingly good job, IMO.

~~~
coldtea
> _Sure, we could just display the HTML and let either the customer or the
> sales agent press "Print to PDF" but it's not very user friendly—non-power
> users may not know that "print to PDF" is even an option—nor is it
> particularly practical for batch processing._

It's not just that. Print to PDF for basic stuff it can be an option. For
complex documents, print workflows, etc, it's a non-starter.

------
dotdi
Whenever a language pops up on HN I excitedly look at it.

Unfortunately, the documentation, FAQ and User Guide all failed in succinctly
giving me the information I need: what can it do well, what does a known
snippet look like implemented in <Lang>, how does it compare to other
languages, etc.

I appreciate the fact that the documentation seems extensive and well-
structured, but that is only helpful to persons who already know they are
going to use the language (i.e. University Students in Melbourne?).

~~~
z3t4
You can't simply judge a new language by looking at it's surface, as there are
not only different languages, there are different coding styles. And then
there's probably frame-works on top. So it's very unlikely that the examples
will be in the style you would prefer. I think the only way to judge a
language is to use it full time for at least one year, but even then you will
probably just have scratched the surface. Unless you care for things that can
be measured, like speed and performance. Which in case you could probably bend
and twist most languages using transpilers or meta - to suit your preferred
style.

~~~
bjz_
Marketing and good communication design is important though, if you want to
actually reach new users. If somebody can't get the gist of what you're about
from a glance, they are far less likely to invest a year into giving it a
solid try.

~~~
YeGoblynQueenne
Mercury is probably developed and maintained by a very small, even single-
perrson team, at this point, so there's most likely an issue of how to best
allocate resources. Perhaps the language designers just can't afford a sleek,
web-based documentation system, such as other languages have.

Let's also not forget that, just because someone understands how to design and
implement a really cool programming language, doesn't mean they understand how
to perform "marketing and good communication". And vice-versa. These are often
very different skillsets, like designing a racing car and actually racing it.

Again, it's not a given that a small team will have both those sets of skills
readily at hand. Which of course, can stunt its growth, further compounding
the problem.

~~~
gus_massa
I don't mind that it has or not a sleek documentation or just plain html. I
just want one or two snippets of code in the main page.

I tried reading the docs (in the html version), and the first example is in
the fourth or fifth page.

~~~
YeGoblynQueenne
There is a tutorial in pdf format, that pretty much starts with hello world:

[https://www.mercurylang.org/documentation/papers/book.pdf](https://www.mercurylang.org/documentation/papers/book.pdf)

    
    
      :- module hello.
      :- interface.
      :- import_module io.
      :- pred main(io::di, io::uo) is det.
      :- implementation.
      main(IOState_in, IOState_out) :-
        io.write_string("Hello, World!\n", IOState_in, IOState_out).
    

Is the problem that this is pdf, rather than html?

~~~
gus_massa
I usually try the html version first if available (and I asume that the pdf
version is equal).

------
jlturner
I’ve written quite a bit of Mercury for fun, and I think it’s a great
language. It feels more like writing in a statically-typed functional language
(like OCaml) than a logic language like Prolog, despite the syntax and
presence of relations. I’d love to see more people and companies adopt it;
it’s a shame how important technology popularity is for most companies.

~~~
fithisux
It had caught my eye but never used it. What kind of problems can I use it
for?

~~~
jlturner
Anything, web servers, systems programming, video games, etc. Its more of a
different way of programming and thinking, using logic variables and
unification to solve problems. Once you wrap your head around logic
programming, its pretty easy and very powerful.

Mercury's selling poings are: \- runtime performance (automatic
parallelization, very efficient due to logic programming understanding and
rewriting sequenced operations) \- static typing (in an ml style / like OCaml)
\- logic programming (unification of lvars)

As a language it fills an interesting niche as logic progamming language
typically aren't dyanmically typed or high performance (ie Prolog, most
miniKanren implementations).

Paul Bone has some good talks on Mercury if youre interested (heres some
slides from an intro talk to Mercury
[https://paul.bone.id.au/pub/pbone-2015-mercury.pdf](https://paul.bone.id.au/pub/pbone-2015-mercury.pdf))

------
gmfawcett
I happen to co-moderate a tiny little subreddit about Mercury:
[https://www.reddit.com/r/mercury/](https://www.reddit.com/r/mercury/) . It
has a few links to blog articles with examples, slide decks, etc.

New members are more than welcome! Mercury is an interesting language, and it
would be nice to bring enthusiasts a bit closer together.

------
hlieberman
> In the past when working with improper window management I have found that
> reaching for the rodent and lifting my eyes off my FSF emacs block cursor
> can trigger undesired distractions, particularly when I'm working in non-
> Lisp dialects (well except for mercury and Pop-11) because any idle brain
> wave will be spent bitching to yourself silently about the lameness of the
> artificial language you are forced to be thinking in presently.

\- SCWM, Pot and the GPL (the Ratpoison Manifesto)

~~~
skrebbel
> In spite of its lack of popularity, LISP (now "Lisp" or sometimes "Arc")
> remains an influential language in "key algorithmic techniques such as
> recursion and condescension"

\- A Brief, Incomplete, and Mostly Wrong History of Programming Languages

~~~
YeGoblynQueenne
That's very funny - why don't you post it on HN?

~~~
aidenn0
[https://news.ycombinator.com/item?id=11936058](https://news.ycombinator.com/item?id=11936058)

[https://news.ycombinator.com/item?id=5695816](https://news.ycombinator.com/item?id=5695816)

[https://news.ycombinator.com/item?id=1475826](https://news.ycombinator.com/item?id=1475826)

[https://news.ycombinator.com/item?id=16695995](https://news.ycombinator.com/item?id=16695995)

[https://news.ycombinator.com/item?id=16353070](https://news.ycombinator.com/item?id=16353070)

[https://news.ycombinator.com/item?id=17741163](https://news.ycombinator.com/item?id=17741163)

[https://news.ycombinator.com/item?id=6953863](https://news.ycombinator.com/item?id=6953863)

[https://news.ycombinator.com/item?id=17400757](https://news.ycombinator.com/item?id=17400757)

[https://news.ycombinator.com/item?id=6504217](https://news.ycombinator.com/item?id=6504217)

[https://news.ycombinator.com/item?id=5728843](https://news.ycombinator.com/item?id=5728843)

[https://news.ycombinator.com/item?id=12443815](https://news.ycombinator.com/item?id=12443815)

[https://news.ycombinator.com/item?id=1310127](https://news.ycombinator.com/item?id=1310127)

[https://news.ycombinator.com/item?id=599164](https://news.ycombinator.com/item?id=599164)

[https://news.ycombinator.com/item?id=1327746](https://news.ycombinator.com/item?id=1327746)

[https://news.ycombinator.com/item?id=3503896](https://news.ycombinator.com/item?id=3503896)

[https://news.ycombinator.com/item?id=16933760](https://news.ycombinator.com/item?id=16933760)

[https://news.ycombinator.com/item?id=8659818](https://news.ycombinator.com/item?id=8659818)

~~~
YeGoblynQueenne
That's very funny. Why don't you post it on HN?

------
nraynaud
I learned so much reading the papers on this website 15-20 years ago:
[https://www.mercurylang.org/documentation/papers.html](https://www.mercurylang.org/documentation/papers.html)

------
roller
One interesting aspect of mercury is the number of available back-ends
(grades) [1]. I'm curious if anyone has any experience using the FFI [2] for
embedding mercury into a larger Java, C# or Erlang project.

[1]:
[https://www.mercurylang.org/about/backends.html](https://www.mercurylang.org/about/backends.html)

[2]: [https://mercurylang.org/information/doc-
release/mercury_ref/...](https://mercurylang.org/information/doc-
release/mercury_ref/Foreign-language-interface.html#Foreign-language-
interface)

------
equalunique
Very cool to see another active project that draws upon Prolog for
inspiration.

> The benchmarks were run on a Sun SPARCserver 1000 with four 50 MHz TI
> SuperSPARC processors and 256 megabytes of memory running SunOS 5.3 (Solaris
> 2.3). Each processor is rated at 60.3 SPECint92, and has a 4-way associative
> 16 Kb I-cache and a 5-way associative 20 Kb D-cache, backed by 1 Mb of
> unified secondary cache.

What's the rationale behind such antiquated benchmarking system? Interesting.

~~~
mikevin
Could it be designed to limit variance and the impact of clever hardware and
its unpredictable nature? I can imagine benchmarking on a new high-end desktop
machine would require a lot of work to make sure your benchmark isn't impacted
because you ran it Friday at 11:44 and the cron job that runs at 11:45 messed
up a few key caches, made your CPU heat up that extra 1 degree celcius causing
some throttling to kick in, causing your prng to be seeded with a value that
triggers a few worst-case performance scenarios etc.

There are a lot of factors that can influence a modern system and most of them
seem hard to control. For a 8086 you could probably account for all these
factors if you put in the hours and run it in a highly controlled environment
but I doubt its even possible for a modern CPU, let alone the whole system.

Of course this isn't a problem for most benchmarks as most of them are only
useful for demonstrating real world use-cases where the variance is expected
and the goal is not to benchmark the performance of a single element of the
system but the perceived performance you can expect in a real-world scenario.

Or its simply designed by someone who loves this kind of system and found a
good excuse to put one to use.

------
dang
Discussed in 2010:
[https://news.ycombinator.com/item?id=1896219](https://news.ycombinator.com/item?id=1896219)

------
thrwia22
faq in the documentation is mostly useless. but the wikipedia entry on it is
quite succinct and good. but still after reading that wikipedia article and
skimming through the website, i, as a typical average code monkey with a some
grasp of python/js/whateva else among these lines, have no clear idea what and
where mercurylang is useful for. can someone eli5-explain that to me in a few
sentences?

~~~
colanderman
Mercury is the love child of Haskell and Prolog: that is, a _very_ strongly
typed logic language. However, it's not _quite_ as flexible a logic language
as Prolog (owing mostly to its strong typechecking and modality system), so in
practice it's closer to a Haskell with a different I/O containment mechanism
(uniqueness types instead of monads) and the ability to sometimes write
reversible functions if you bang your head against the modality system hard
enough.

Its compiler is impressive, and is capable of acts such as compiling certain
non-tail-recursive functions in a tail-recursive manner, or even transforming
them into tail-recursive equivalents, given the right hints.

All this capability comes at a cost. At least as of ~4 years ago, the error
messages the compiler can spit out over modality errors dwarf even those from
C++ templates. And compiler bugs/unimplemented features are not unheard of.

~~~
astrange
I want to point out that Mercury is an eager language, so it's more like ML
than Haskell. It does have the ability to backtrack and execute in reverse,
which is kind of magical in the way people think Haskell is.

I wanted to learn it recently, but couldn't find enough example programs.

------
rurban
Maybe a (1998) subject tag would be in order here, that's when the current web
page went up. The language is much older though.

Quite influential in those times ("typed prolog" with a better compiler), but
didn't gain that much attention and some mercury projects were rewritten then
in other languages.

------
packetpirate
Maybe I'm just lazy, but from a quick glance, this language seems a little too
wordy for my tastes... why "import_module" instead of just "import"? Or
"write_string" instead of "write"? I prefer a terse programming language that
uses more descriptive keywords in favor of more of them.

But I suppose that's not really the most important factor of a language and
the syntax could be fun to try out.

~~~
astrange
Putting types in the keywords is sensible if you don't have
multimethods/generic functions. I don't remember if Mercury has those or not.

------
mproud
Fairly certain I looked at this back in 2004 while I was in college.

I don’t remember too much, but my prof. thought it was cool.

