Oz and Mozart Users Mailing List

RE: Function Composition


From: Alex Peake (apeake@comac.com)
Date: Thu Jul 17 2003 - 18:59:09 CEST


Thank you Fred. I would not have thought of this.

A further question for "the Oz experienced": is this the "Oz idiom" way of doing it

Alex

> -----Original Message-----
> From: owner-oz-users@ps.uni-sb.de [mailto:owner-oz-users@ps.uni-sb.de]On
> Behalf Of Fred Spiessens
> Sent: Thursday, July 17, 2003 12:22 AM
> To: users@mozart-oz.org
> Subject: Re: Function Composition
>
>
> Dear Alex,
>
> I'm learning myself too, so I understand it's not easy, and it's a good
> exercise for me.
> you should check the documentation on Lists (in Oz Base modules)
>
> I'd recommend FoldL or FoldR for your problem.
> Check it out!
> http://www.mozart-oz.org/documentation/base/list.html#section.records.lists
>
> this is what I came up with:
>
> declare
>
> fun{Compose Fns}
> fun{$ X}
> {FoldR Fns fun{$ F X} {F X} end X}
> end
> end
>
> fun{A X} a(X) end
> fun{B X} b(X) end
>
> C = {Compose [A B]}
> {Show {C x}}
>
> will show a(b(x))
> if you want b(a(x)) you'll have to use FoldL but then X and F should
> change places !
>
>
> Cheers,
> Fred.
>
> On Thursday, July 17, 2003, at 06:34 AM, Alex Peake wrote:
>
> > Can someone help please?
> >
> > I am learning Oz. I am trying to implement function composition, but
> > cannot get it.
> >
> > I try:
> >
> > declare
> > fun {Compose Fns}
> > case Fns of
> > [Fn] then Fn
> > [] Fn|FnTail then
> > fun {$ Args}
> > {Procedure.apply Fn {Procedure.apply {Compose FnTail} Args}}
> > end
> > end
> > end
> >
> >
> > But alas, it will not compile, and I do not understand the error.
> >
> > %********************** static analysis error *******************
> > %**
> > %** illegal arity in application
> > %**
> > %** Arity found: 3
> > %** Expected: 2
> > %** Argument names: {Procedure.apply _ Args _}
> > %** Argument values: {<P/2 Procedure.apply> _<optimized>
> > Args<optimized> _<optimized>}
> > %** in file "C:/Test/Experiment.Oz", line 57, column 22
> >
> > %********************** static analysis error *******************
> > %**
> > %** illegal arity in application
> > %**
> > %** Arity found: 3
> > %** Expected: 2
> > %** Argument names: {Procedure.apply Fn _ _}
> > %** Argument values: {<P/2 Procedure.apply> Fn<optimized> _<optimized>
> > _<optimized>}
> > %** in file "C:/Test/Experiment.Oz", line 57, column 2
> > %** ------------------ rejected (2 errors)
> >
> > Alex
> > -
> > Please send submissions to users@mozart-oz.org
> > and administriva mail to users-request@mozart-oz.org.
> > The Mozart Oz web site is at http://www.mozart-oz.org/.
> > Please send bug reports to bugs@mozart-oz.org.
> >
> >
> _______________________________________
> Fred Spiessens
> Researcher software security
> UCL university
> Louvain-la-Neuve Belgium
>
> Mobile: +32476788893
> Email: fsp@info.ucl.ac.be
> URL: http://www.info.ucl.ac.be/people/fsp/fred.html
>
> -
> Please send submissions to users@mozart-oz.org
> and administriva mail to users-request@mozart-oz.org.
> The Mozart Oz web site is at http://www.mozart-oz.org/.
> Please send bug reports to bugs@mozart-oz.org.
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
Please send bug reports to bugs@mozart-oz.org.



This archive was generated by hypermail 2b29.