Article View: comp.lang.functional
Article #647Re: 3rd order functions
From: Mark Ramaer
Date: Mon, 05 Oct 1992 10:13
Date: Mon, 05 Oct 1992 10:13
53 lines
2594 bytes
2594 bytes
In article <ALTI.92Oct2123450@tanera.dcs.ed.ac.uk>, alti@dcs.ed.ac.uk (Thorsten Altenkirch) writes: |> In article <1992Oct1.174259@cs.utwente.nl> ramaer@cs.utwente.nl (Mark Ramaer) writes: |> |> "alt" chooses between two "a"-parsers. |> |> > alt :: ([t]->Bool) -> Parser t r a -> Parser t r a -> Parser t r a |> > alt test aa bb = \contin input -> |> > if test input |> > then aa contin input |> > else bb contin input |> |> > sequenceOption :: ([*]->bool) -> Parser t r a -> Parser t r [a] |> > sequenceOption test aa = alt test (sequence test aa) (empty []) |> |> "Parser t r a" is a 2nd order type, so "alt" and "sequenceOption" |> are 3rd order functions. |> |> Thanks Mark, this certainly is a 3rd order function. In another |> posting I tried to make the requirements more precise: |> |> If we have polymorphism, it is not clear what level to assign to type |> variables. In fact it is quite easy to get a 3rd order functions just |> by instantiating the type of polymorphic map by a 1st order function |> type for the input list. However, I am interested in *genuine* higher |> order functions, i.e. which do not show up as instantiations of |> polymorphic functions. This means that in this context I consider the |> order of a type variable as 0. |> |> Your function alt can be obtained by instantiating a 2nd order |> polymorphic function to the type Parser, right? In this way it is not |> genuinely higher order. |> Sorry, I have chosen a wrong example. This function is from the same file: cat >Try.lhs <<eoscript > module Try(join) where join :: (a -> b -> c) -> Parser t r a -> Parser t r b -> Parser t r c > join semantic aa bb cont > = aa aCont > where aCont a = bb (bCont a) > bCont a b = cont (semantic a b) eoscript Now hbc derives the type (note that my type specification is a comment): join :: (a -> b -> c) -> ((a -> d) -> e) -> ((b -> f) -> d) -> (c -> f) -> e (N.B. in the entire program d === e === f === [t]->r) That should do, Mark
Technical Details
Message-ID:
<1992Oct5.111323@cs.utwente.nl>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!utrcu1!infnews!infnews!ramaerReferences:
<BvFvEz.7A@dcs.ed.ac.uk> <1992Oct1.153234@cs.utwente.nl> <ALTI.92Oct2123450@tanera.dcs.ed.ac.uk>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.functional Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!utrcu1!infnews!infnews!ramaer From: ramaer@cs.utwente.nl (Mark Ramaer) Subject: Re: 3rd order functions Message-ID: <1992Oct5.111323@cs.utwente.nl> Sender: usenet@cs.utwente.nl Nntp-Posting-Host: utis143 Organization: University of Twente, Dept. of Computer Science References: <BvFvEz.7A@dcs.ed.ac.uk> <1992Oct1.153234@cs.utwente.nl> <ALTI.92Oct2123450@tanera.dcs.ed.ac.uk> Date: Mon, 5 Oct 1992 10:13:23 GMT Lines: 53