From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ce0900b60ca3f616 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-07 02:24:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!151.189.0.75!newsfeed.germany.net!newsfeed.arcor-online.net!newsfeed2.easynews.net!easynews.net!news.cid.net!news.enyo.de!news1.enyo.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: Side-Effects in Functions [Rosen Trick] Date: Wed, 07 Nov 2001 11:46:58 +0100 Organization: Enyo's not your organization Message-ID: <87k7x2oo2l.fsf@deneb.enyo.de> References: <9rti6v$hcu$1@news.huji.ac.il> <1EyE7.10050$xS6.13527@www.newsranger.com> <9rue9f$j4t$1@nh.pace.co.uk> <9ruiet$kqg$1@nh.pace.co.uk> <3BE3235D.E292B890@boeing.com> <3BE35498.9F6381A2@acm.org> <9s230d$107b5a$2@ID-25716.news.dfncis.de> <5ee5b646.0111040507.5ca7ea23@posting.google.com> <9s3tl3$111hco$1@ID-25716.news.dfncis.de> <5ee5b646.0111041846.93f3e07@posting.google.com> <9s5eub02j61@drn.newsguy.com> <3be666fe.6426140@News.CIS.DFN.DE> <9s7bfb$11boa1$1@ID-25716.news.dfncis.de> <87itcn8xxx.fsf@deneb.enyo.de> <9s9pc2$125kn6$1@ID-25716.news.dfncis.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cancel-Lock: sha1:pLUfDHxamVl2hgTqmjelTXoiNSE= Xref: archiver1.google.com comp.lang.ada:15980 Date: 2001-11-07T11:46:58+01:00 List-Id: "Nick Roberts" writes: > "Florian Weimer" wrote in message > news:87itcn8xxx.fsf@deneb.enyo.de... >> "Nick Roberts" writes: >> >> > From a pedagogical point of view, care needs to be taken not to give the >> > impression that a function in a procedural programming language (most >> > programming languages, really) is the same thing as a mathematical > function. >> > Clearly it isn't: a mathematical function is a kind of relation called a >> > 'bijection' (and is nowadays specifically defined as such, I think); >> >> A function f : M -> N are two sets M, N and a subset G_f of the >> Cartesian product M x N with the following property: for all m in M, >> there exists exactly one n in N such that (m, n) in G_f. > > That actually sounds like an injection to me (1 to 1), Actually, it's many to one. The uniqueness constraint is only there to ensure that for each value m in M, there is only one value of the function at m (usually denoted by "f(m)" or "m f", if you write functions from the right). > whereas I get the impression mathematicians (discrete ones anyway > ;-) tend to insist nowadays on the definition of a function as a > bijection (both 1 to 1 and 'onto', i.e. both an injection and a > surjection, so that f' is also a bijection). I've yet to meet a mathematician who claims that functions are always bijective. Quite the contrary, in almost all the set-based categories I've seen so far, morphisms weren't generally bijective. >> However, there are programming languages which use only mathematical >> functions, and a special construct for I/O, Haskell for example. > > I'm not a Haskell expert, but functional languages in general do fix the > order of evaluation of their functions (or some of their functions) > precisely because of the side-effect problem. Haskell functions do not have side effects. Side effects are introduced by a special construct call a "monad", which essentially introduces explicit machine state parameters. There's a construct ("do") which makes them implicit again, too. > I presume lazy evaluation can be a serious hazard, if used without > care, nevertheless. Lazy evaluation is a nice thing, as long as functions have no side effects.