/r/mercury

Photograph via snooOG

Mercury is a programming language developed at the University of Melbourne. For the planet, see /r/PlanetMercury.

Mercury integrates the logic programming concepts introduced by Prolog with functional programming idioms and achieves markedly better performance than Prolog (comparable to OCaml) thanks to an advanced type system. It compiles to C as an intermediate language and can interface with C programs with little overhead.

the mercury homepage
mercury-users mailing list archive
Stack Overflow questions about Mercury

/r/mercury

414 Subscribers

2

Need some review and help with my first Mecury code

Hey,

I am really new in logical programming, and for a long long time I wanted to give it a go, so a couple of days ago I have decided to migrate a prolog script: https://github.com/jjd27/ball-sort-puzzle-solution/blob/main/ballsort.pl to mercury. Maybe not the best idea, but I wanted to have this solver and seemed like a good enough start.

Maybe it is a long shot but can someone take a look because the more I debugged the more confused I got :). I have several questions about the modes for find_solution, where I feel it should be out it only works with in, but either way probably a lot of things are wrong here because I just cannot get a solution out of the script even with changing the modes and seeing it started to try solutions.

The code (sorry, it is really the first time I have typed in any code like that. Any improvement points are very welcomed!): https://gist.github.com/kalidasya/9d33173ad9737f455cf4aca3544b7f68 it does not compile because of an instantiatedness problem, but I do not understand why and I think the modes are correct the way they are. To make it compile u need to change the first clause of find_solution to match the original prolog version and have an empty list in the Moves argument (I dont understand why in the original as well), even then it does not return with a solution.

Thank you for the help

0 Comments
2022/04/13
10:30 UTC

3

State of doc and test tooling

Hello mercury community!

I have a relatively mature prolog codebase that I have been working on, but I'm tired of not having types and some other very nice things that I see being provided by mercury.

I'm interested in translating everything and going forward with mercury instead. The problem is that I use pldoc and plunit to do auto documenting and testing. I don't see tools for these things in the mercury ecosystem, but I also haven't really found where that ecosystem is.

So, first, are there tools for testing and documentation?

Second, where might I find a collection of user contributed libraries and such? I would be interested in contributing, too.

Edit: looks like most action is on the mailing list, so perhaps there is an answer there.

1 Comment
2021/11/05
19:15 UTC

2

maturity and licensing of the Java backend

  1. How mature is the Java backend of Mercury? I couldn't find a list of specific missing features.
  2. Does GPL2 with #6 exception mean one can use the Java backend as a dependency without licensing the end-product under GPL?
0 Comments
2021/10/24
21:24 UTC

3

How to instruct mmc to lookup the main file/module in a specific non-current directory?

Subj. I'm looking for a way to integrate mmc into my exisitng Makefile pipelines that reside separate to mercury source code files. I can provide an absolute path to the location where souce files and modules could be found, but unfortunately the current mmc --help output is not very informative on whether that's possible at all. So far I'm getting this error:

/Users/user/projects/mercury-playground/src/main.m
/nix/store/781y33icqqb7cs02r6qymlk8rbbsis82-mercury-20.06.1/bin/mkinit: error opening output file `Mercury/cs//Users/user/projects/mercury-playground/.local/x86_64-darwin/build/main-exe_init.c.tmp': No such file or directory
make: *** [Makefile:33: /Users/user/projects/mercury-playground/.local/x86_64-darwin/build/main-exe] Error 1

Here's the build template:

$(BUILD_DIR):
	install -dm0755 $(BUILD_DIR)

$(BUILD_NAME): $(BUILD_DIR)
	mmc	--output-file	$(BUILD_NAME) \
		--use-subdirs \
		$(SRC_DIR)/main.m

UPD: seems like the error progressed to another one, as soon as I added --use-subdirs. I updated the post.

1 Comment
2021/10/06
22:04 UTC

2

Help with build failure related to using fact tables on OSX

Hi there.i have a relatively small project that I'm playing with that builds fine on Linux (Ubuntu 18) with the current stable version of mmc, but is producing the following error on OSX 10.14.6 with the same version of mmc (installed through Homebrew):

➜ MercuryCreate git:(createActionUpdates) ✗ ./build.sh Making Mercury/cs/create.c Uncaught Mercury exception: Software Error: predicate ml_backend.ml_foreign_proc_gen.ml_gen_foreign_proc'/12: Unexpected: unexpected code model ** Error making Mercury/cs/create.c'.

I have traced tis to bring related to using a fact table, as when I move the fact code into the file where the predicates are defined and remove the fact table pragma it builds fine. Other local module imports work fine. Does anyone have any insights into what may be causing this? Thanks for the help!

0 Comments
2020/04/22
21:03 UTC

8

What is mercury used for?

What are the areas where mercury can be used or applications that can be developed with it?

3 Comments
2019/06/16
13:03 UTC

1

Are there any project based resources to learn mercury?

Hi, I have been wanting to learn Mercury for quite some time. I wanted to know if there are any project based tutorials that a member of the community has written. Something that also highlights the benefits of using Mercury. Something like the articles on this site http://howistart.org/posts/erlang/1/index.html

0 Comments
2019/06/15
16:29 UTC

6

Mercury `fact_table` utils

To get to grips with Mercury I wrote a set of typeclasses and supporting functions that I think would be useful to the general community.

https://github.com/sheganinans/fact_table_utils

It's a start, there are a few low hanging fruit.

One I see is switching from string concatenation to string.builder.

Also maybe sending strings directly to a `io.text_output_stream` instead of using `io.write_strings`.

Also, it's very likely someone else has written something similar to my work.

5 Comments
2018/11/05
20:41 UTC

3

Going to start learning Mercury, where should I post my questions?

Hi,

I'm looking forward to converting a small project I started from Prolog to Mercury. I already know I'm going to have a lot of questions. I can (eventually) answer these questions myself, but it might be helpful for future learners if I post these questions publicly.

Is there a preferred place for me to ask these questions? I was planning on using Stack Overflow.

Thanks, and looking forward to diving in.

1 Comment
2018/05/04
21:00 UTC

1

Paul Bone interviewed about Mercury on Playing with Prolog

0 Comments
2017/04/02
23:53 UTC

3

I've been looking at Mercury this evening, and it looks pretty cool! Is it accurate to say that Mercury is like a statically-typed Prolog?

I heard from the Strange Loop presentation "Prolog in Production" that Mercury is like a baby of Prolog and Haskell. But from what I've read it seems like Prolog + predicates + modes (sorry I am more familiar with Prolog though than Haskell). Is that accurate? The claims of speedup on the Mercury website are nice, but I could not find any outside benchmarking tests. Something else I am trying to understand is that do large Mercury projects have the conciseness of Prolog with the speed of, say, Python or Java or other popular interpreted languages?

3 Comments
2016/10/21
03:25 UTC

1

Understanding existential types.

Given a grasp of the concepts behind Prolog/Logic Programming, Mercury has proven itself to be a surprisingly easy language to wrap my head around. There's a purity and elegance that Prolog lacks (the cut operator). So far the one aspect of the language that I've had a difficult time understanding: Existential types. Reading the documentation suggests that the type checking/inference is reversed with existentially typed variables, for a existentialy typed variable in a predicate call, the predicate determines the type of the type variable, not the caller. What I struggle with is how this fits semantically with propositional/predicate logic. When I code

:- pred afoo(T).
afoo(Something) :- bar(Something).

I read it in my head as 'All afoo somethings are bar somethings', or more formally, 'For all Somethings where 'verb afoo' then there exists something where 'verb bar''. The head of the horn clause is implicitly Universally quantified, wheas the body is Existentially quantified. But what about

:- pred some [T] foo(T).
efoo(Var) :- bar(Var).

In this, bar is telling me what type Var really is, not efoo, right? I'm just really struggling to put this into plainly spoken semantics. And that's all without broaching the subject of

:- type widget ---> some [t] polymorphic(T).

I'd also like to more properly grasp existential type constructors, but I get the feeling that I'm better off understanding the predicate and function declarations first. Note: I've omitted mode and determinism from my declarations for brevity.

0 Comments
2014/05/30
23:55 UTC

6

How does Mercury compare to ATS (applied type system)?

0 Comments
2014/03/15
16:55 UTC

Back To Top