As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [mercury]

Mercury is a purely declarative logical/functional language. It features a strong, static, polymorphic type system, as well as a strong mode and determinism systems. The type system is similar to that of Haskell, while the syntax is derived from Prolog's.

Filter by
Sorted by
Tagged with
5 votes
1 answer
244 views

How to generate lists of fresh variables in Mercury like I can in Prolog?

In SWI Prolog, list(Xs) :- length(Xs, _). is "pure" in that I can pass it a variable with any sort of instantiatedness and it will nondeterministically unify it with all most general ...
GeoffChurch's user avatar
3 votes
1 answer
77 views

Mercury "undefined reference" compilation error when using local module

I have a module exporting nat/1 to test/generate natural numbers: :- module nat. :- interface. :- import_module int. :- pred nat(int). :- mode nat(in) is det. :- mode nat(out) is multi. :- ...
GeoffChurch's user avatar
1 vote
1 answer
97 views

Can I add predicates at runtime?

The context is a system of predicates: rules and facts, that together determine an amount to be paid to a client, depending on his situation. Most rules and facts are known at compile time, but facts ...
Rudi Angela's user avatar
  • 1,463
5 votes
2 answers
210 views

What is a "strongly moded" programming language?

I was looking through the Mercury programming language's about page when I found a part where it said: Mercury is a strongly moded language What does this mean!? I've search all over the internet, ...
xilpex's user avatar
  • 3,047
0 votes
1 answer
79 views

Find number of successes from a list of terms/goals

I have written the following predicate exactly/2 that succeeds if exactly N of the numbers in the list L are equal to 1: :- pred exactly(int, list(int)). :- mode exactly(in, in) is semidet. :- mode ...
Zehanort's user avatar
  • 428
0 votes
2 answers
134 views

Mercury nondet in det

In Mercury, suppose you're in a det predicate, and you want to call a nondet predicate, as follows. If there are no solutions, you want Result = []; if there's one or more, you just want the first ...
Erhannis's user avatar
  • 4,176
2 votes
1 answer
249 views

Mercury Constraint Solving

I know a little Prolog, and frequently use CLP(FD) etc. This paper (written in 2006, apparently) indicates that Mercury now has constraint solving, too. I've found a few mentions of it in the ...
Erhannis's user avatar
  • 4,176
0 votes
1 answer
33 views

What causes type error in argument(s) of functor `field_name/1' in Mercury?

When I compile my source , I get the following error: type error in argument(s) of functor `source/1' The compiler correctly determines the types of the arguments, but keeps trying to use a field ...
Charles Shuller's user avatar
1 vote
1 answer
56 views

How do I specify compile time defines in Mercury?

How do I specify compile time defines in Mercury? I would like to have the build system read the version number out of a configuration file and pass it into the module for access by predicates and ...
Charles Shuller's user avatar
2 votes
1 answer
141 views

Mercury: This predicate works if declared at the top level, but not as a lambda

(The excerpt below is from this test suite, which is half of the two-file program found here.) I've defined an auxiliary predicate in two ways: once at the top level (called helper), and once as a ...
Jeffrey Benjamin Brown's user avatar
2 votes
1 answer
145 views

Mercury List Unification

I'm trying to learn Mercury. I've been messing around with lists, but I can't get a seemingly-simple unification to work. Here's my reduced example case: main(!IO) :- [X,Y] = List, List = [1,2],...
Erhannis's user avatar
  • 4,176
0 votes
1 answer
113 views

Windows mistakes mmc for Microsoft Management Console when it should be Melbourne Mercury Compiler

I took these steps: download windows binary Mercury 14.01 (Visual Studio 2013 32bit) (this is near the bottom of http://dl.mercurylang.org/index.html) double click the downloaded file (it's a ....
Illogical Captain's user avatar
4 votes
1 answer
147 views

Are algebraic predicates supported in Mercury?

I'm very new to Mercury and logic programming in general. I haven't found a numeric example like this in the docs or samples... Take the example predicate: :- pred diffThirtyFour(float, float). :- ...
m88's user avatar
  • 93
1 vote
0 answers
228 views

in windows how to compile and run mercury program

I was able to download and unzip mercury file from http://dl.mercurylang.org/index.html . However, i could not figure out how to compile and run one of the programs . I googled to find command '$ ...
Monu's user avatar
  • 2,092
0 votes
1 answer
401 views

Need to install Mercury compiler

I need to install Mercury compiler, the link shared on the website of mercury is not found. Could you please share the link to download the mercury compiler.
Monu's user avatar
  • 2,092
2 votes
3 answers
206 views

How to check if a variable is instantiated in Mercury

I am a complete beginner in Mercury language, although I have learned Prolog before. One of the new aspects of Mercury is dererminism. The main function has to be deterministic. In order to make it so,...
Igor Popov's user avatar
  • 2,588
1 vote
1 answer
58 views

Building a Mercury program with sub-modules in a subdirectory

I have a mercury program that imports a module from another file. I'd like to be able to put this file in a subdirectory. How can I do this? I'm using mmc -E --make --trace deep filename to make the ...
Beornwulf's user avatar
  • 225
4 votes
1 answer
147 views

Need an example of Record Syntax in mercury

I am new to mercury and am trying to wrap my head around Record Syntax, but the Reference Manual is the only place I have encountered it and it leaves me mystified: Term ^ field1(Arg1) ^ field2(...
SourceSimian's user avatar
2 votes
2 answers
159 views

How do I display a list of long integers? (Mercury language)

In io.write_list(List(integer), ",", OutputPred, !IO), what is OutputPred? I'm trying to display a list of type integer. The list is initially never empty.
dogwood's user avatar
  • 371
1 vote
1 answer
75 views

How continue line of text to next line in Mercury?

How do I continue a too-long line to a next line? I tried using a backslash but the Mercury compiler doesn't accept that convention. Have been unable to find an answer to this mundane question.
dogwood's user avatar
  • 371
2 votes
2 answers
85 views

How to declare a pred for a predicate that imports or outputs lists?

Looking for help declaring a pred for a predicate that imports or outputs lists. I tried :- pred name(list::in, integer::out) is multi. and compiler error message says that list/0 isn't recognized. ...
dogwood's user avatar
  • 371
2 votes
1 answer
231 views

How do I compile for debugging in Mercury programming language?

Using Mercury 14.01.1 on Ubuntu 14.04. Have installed four grades, including debugging grades, from source code. Tried each of the following without success (files/directories missing) $ mmc --debug ...
dogwood's user avatar
  • 371
2 votes
2 answers
128 views

Building Multi-Module Mercury Programs

Q. What's a simple template for building a two-module mercury program? Module_1 defines and exports a simple function or predicate. Module_2 imports the function/predicate to compute a useful result ...
dogwood's user avatar
  • 371
1 vote
0 answers
81 views

Why does this variable have an instantiatedness of free?

I've written a Mercury function to calculate the length of a list skeleton, but it doesn't compile and I don't understand why. I'd like to know what's going on here. (In the code below, the inst, func,...
Evan's user avatar
  • 2,400
1 vote
1 answer
101 views

Matching determinism of a lambda and a predicate in Mercury

In Mercury, can I declare a lambda as having the same determinism as the mode of the predicate that contains the lambda? Here's what I'm trying to do. I wrote a fold function (below) that works on ...
Evan's user avatar
  • 2,400
20 votes
1 answer
1k views

How do Rust's ownership semantics relate to uniqueness typing as found in Clean and Mercury?

I noticed that in Rust moving is applied to lvalues, and it's statically enforced that moved-from objects are not used. How do these semantics relate to uniqueness typing as found in Clean and ...
user avatar
2 votes
2 answers
167 views

In Mercury, why can't I use a state variable in a function application?

When describing state variables, the Mercury reference manual says: "!X may not appear as an argument in a function application, since this would not make sense given the usual interpretation of state ...
Evan's user avatar
  • 2,400
8 votes
1 answer
1k views

What benefit does types bring in logic programming languages like Mercury?

I've starting looking at the Mercury language, which seems very interesting. I'm a new to logic programming, but pretty experienced with functional programming in Scala and Haskell. One thing I've ...
Jesper Nordenberg's user avatar
6 votes
3 answers
404 views

Does any version of Prolog support higher order abstraction of accumulators?

I was wondering about a Prolog that could include a built-in call like this: accum(generator, filter, accumulator) Calculates all solutions to generator. For each one, if filter can be proved, ...
Mark Green's user avatar
  • 1,310
2 votes
1 answer
731 views

Creating a deterministic finite automata (DFA) - Mercury

I would like to have a deterministic finite automata (DFA) simulated in Mercury. But I’m s(t)uck at several places. Formally, a DFA is described with the following characteristics: a setOfStates S, ...
Jabba The hut's user avatar
1 vote
2 answers
407 views

Mercury compilation error with Mac OS X 10.8

I've got a problem compiling Mercury on my Mac. I'm running Mac OS X 10.8, got Xcode 4.5 installed and also Command Line Tools. What have I done so far: I downloaded the tar.gz file, extracted it, ...
Novarg's user avatar
  • 7,390
46 votes
6 answers
4k views

What other ways can state be handled in a pure functional language besides with Monads?

So I started to wrap my head around Monads (used in Haskell). I'm curious what other ways IO or state can be handled in a pure functional language (both in theory or reality). For example, there is a ...
James Scourtos's user avatar
3 votes
1 answer
853 views

What is a good data type for representing arbitrary binary data?

I want to read binary data from disk and store it in a Mercury variable. According to the string library, strings don't allow embedded null bytes and store content with UTF-8 encoding so I don't ...
mndrix's user avatar
  • 3,111
5 votes
1 answer
1k views

Mercury installation

I already download Mercury 11.07.1 from http://www.mercury.csse.unimelb.edu.au/download/release.html and also installed cygwin on my Windows 7 PC. However i don't know how to install the mercury. Is ...
Hello_World's user avatar
2 votes
3 answers
246 views

Unrestricted variable name declaration in Mercury

I would like to declare a data type in Mercury that can have a variable number of values and names. For instance : type goal ---> pick; give; come. has three variables/values. I want something ...
Eddy Freeman's user avatar
  • 3,197
4 votes
1 answer
536 views

Mercury: Determinism and pattern matching

I have a semideterministic function. When I re-write it to use pattern matching instead of an if statement, Mercury says it becomes nondeterministic. I'd like to understand why. The original code: :-...
Evan's user avatar
  • 2,400
4 votes
3 answers
285 views

Mercury: How to declare determinism of a higher-order data type?

When I compile the Mercury code below, I get this error from the compiler: In clause for `main(di, uo)': in argument 1 of call to predicate `test_with_anonymous_functions.assert_equals'/5: mode ...
Evan's user avatar
  • 2,400
1 vote
3 answers
373 views

":=" and "=>" in Mercury

I recently came across this code example in Mercury: append(X,Y,Z) :- X == [], Z := Y. append(X,Y,Z) :- X => [H | T], append(T,Y,NT), Z <= [H | NT]. Being a Prolog programmer, I ...
J_Johnson's user avatar
5 votes
3 answers
2k views

IDE or Editor with Support for Mercury [closed]

Are there any IDE's or editors that support Mercury besides emacs?
None's user avatar
  • 3,865
2 votes
1 answer
244 views

Convert List to List of Tuples In Mercury

I am just a total beginner in mercury and finding it hard to solve this problem. I want to convert a list to a list of tupples sorted from smaller to higher frequenties. Eg: string.to_char_list("...
kap's user avatar
  • 107
1 vote
1 answer
238 views

polymorphic instances for typeclasses in Mercury language

Consider next declaration: :- type wrap(T) ---> wrap(T). :- inst wrap(I) ---> wrap(I). :- typeclass infer_wrap(A, B) <= ((A -> B)). :- instance infer_wrap(A, wrap(A)). Mercury (10.04) ...
ony's user avatar
  • 12.2k
3 votes
3 answers
248 views

ADT properties in Mercury

I wander why Mercury (10.04) can't infer determinism of next snippet: :- pred load_freqs(int::in, io.res(list(float))::out, io::di, io::uo) is det. load_freqs(CPU, ResFreqs, !IO):- open_input(...
ony's user avatar
  • 12.2k
21 votes
4 answers
4k views

What is more interesting or powerful: Curry, Mercury or Lambda-Prolog?

I would like to ask you about what formal system could be more interesting to implement from scratch/reverse engineer. I've looked through some existing and open-source projects of logical/...
Bubba88's user avatar
  • 1,900