Skip to Content.
Sympa Menu

maude-help - Re: [Maude-help] Type synonyms

maude-help AT lists.cs.illinois.edu

Subject: Maude-help mailing list

List archive

Re: [Maude-help] Type synonyms


Chronological Thread 
  • From: Steven Eker <eker AT csl.sri.com>
  • To: maude-help AT peepal.cs.uiuc.edu
  • Cc: maude-help AT peepal.cs.uiuc.edu
  • Subject: Re: [Maude-help] Type synonyms
  • Date: Tue, 11 Aug 2009 12:21:14 -0700
  • List-archive: <http://maude.cs.uiuc.edu/pipermail/maude-help>
  • List-id: Maude help list <maude-help.maude.cs.uiuc.edu>

You can import FLOAT multiple times as long as both sorts in the [Float] kind
are renamed to keep the kinds from the two imports separate:

fmod TEST is
inc FLOAT * (sort FiniteFloat to FiniteFloat1, sort Float to Float1) .
inc FLOAT * (sort FiniteFloat to FiniteFloat2, sort Float to Float2) .
endfm

*** floating point numbers are now ambiguous
red 6.0 .

*** only one number in an expression need be disambiguated
red (6.0).Float1 + 5.0 .
red (6.0).Float2 + 5.0 .

*** adding floats from different sorts does not parse
red (6.0).Float1 + (5.0).Float2 .

I can't recommend this style of programming since you will need to be careful
never to bash the two kinds together in a big program.

Steven

On Tuesday 11 August 2009 11:34, Cezar Ionescu wrote:
> Hello everybody,
>
> I'm trying to write a small three-agents program in Maude. The agents
> have stocks of goods, they work, they get paid in goods per labour,
> etc. I've already implemented this in Haskell, and I've found it useful
> to use type synonyms, i.e., although goods and labour are represented as
> floats, I'd like the operators to act on sorts called GoodsStocks and
> LabourFlow, and the like. Is there a simple way to do that in Maude?
>
> I've already written things like
>
> sorts GoodsStock LabourFlow .
> op gs_ : Float -> GoodsStock [ctor] .
> op toFloat : GoodsStock -> Float .
> var F : Float .
> eq toFloat (gs F) = F .
>
> and so on. This corresponds to Haskell's ``newtype'' mechanism, and I
> find the resulting program ugly. I've also tried renaming Float, but
> that only seems to work once per module...
>
> Anyway, thanks for the help. I have to say I find Maude the strangest
> language I've programmed in so far, and I like it!
>
> Best,
> Cezar.
> _______________________________________________
> Maude-help mailing list
> Maude-help AT maude.cs.uiuc.edu
> http://maude.cs.uiuc.edu/cgi-bin/mailman/listinfo/maude-help




Archive powered by MHonArc 2.6.16.

Top of Page