Talk:Mercury (programming language): Difference between revisions

Content deleted Content added
Examples of difficulties introduced by declarativeness?: "harder to express" needs a reliable source
Line 57:
:It's not very pretty, but it gets the job done, is deterministic, and is friendly to clause indexing (i.e., it can possibly compile to smart code that's more efficient than an if-else cascade). Without the cuts, the "default" rule would have to contain some kind of "not one of the days above" condition. That would mean more---redundant!---code, which might justify the "harder to express" judgement. [[Special:Contributions/77.117.184.155|77.117.184.155]] ([[User talk:77.117.184.155|talk]]) 19:04, 2 December 2009 (UTC)
::I find the Prolog construct cuts-in-all-cases-except-the-last more readable than the Mercury equivalent. But that's just my opinion which of course falls foul of [[WP:OR]]. But there is no issue of expressiveness. The claim "harder to express" needs removing or a reliable source. [[User:Pgr94|pgr94]] ([[User talk:Pgr94|talk]]) 10:57, 3 December 2009 (UTC)
 
What you really want is something like this:
 
(
Day = saturday,
OpenHours = (8 - 15)
;
Day = sunday,
OpenHours = (9 - 13)
;
( Day = monday
; Day = tuesday
; Day = wednesday
; Day = thursday
; Day = friday
),
OpenHours = (8 - 17)
)
 
This is a switch whose third case is a multi-cons-id case, This gets compiled efficiently, expresses the computation clearly and (in the right context) uses the determinism checker to ensure that all days are covered exactly once. It can also be run in reverse where the OpenHours is ground and Day is free, where it would be nondeterministic.
 
== "Good" principles ==