caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* `This expression is not a function it cannot be applied'
@ 2008-09-02  8:00 Christian Sternagel
  2008-09-02  8:26 ` [Caml-list] " David Baelde
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Sternagel @ 2008-09-02  8:00 UTC (permalink / raw)
  To: caml-list

Is there a way to be able to apply something of an abstract data type 
without knowing the internal representation?

E.g., when having the module
module Parser : sig
  type ('a,'tok) t
  val token : ('tok -> 'a option) -> ('a,'tok) t
end = struct
  type ('a,'tok) t = 'tok list -> ('a * 'tok list)
  let token ... = ...
end

I want to be able to apply the result of (token (function Ident s -> 
Some s | None)) to some further input (since it is a parser), however, 
this is not possible since the result type is not functional.

The only way out I see is to `unabstract' the type and give its internal 
representation. Or is there another possibility?

cheers

christian



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] `This expression is not a function it cannot be applied'
  2008-09-02  8:00 `This expression is not a function it cannot be applied' Christian Sternagel
@ 2008-09-02  8:26 ` David Baelde
  2008-09-02  8:34   ` blue storm
  0 siblings, 1 reply; 4+ messages in thread
From: David Baelde @ 2008-09-02  8:26 UTC (permalink / raw)
  To: Christian Sternagel; +Cc: caml-list

You can provide your own application function, as follows.

On Tue, Sep 2, 2008 at 10:00 AM, Christian Sternagel
<christian.sternagel@uibk.ac.at> wrote:
> E.g., when having the module
> module Parser : sig
>  type ('a,'tok) t
>  val token : ('tok -> 'a option) -> ('a,'tok) t
>  val apply : ('a,'tok) t -> 'tok list -> ('a * 'tok list)
> end = [...]

This amouns to provide a cast from the abstract type to the function
type, while keeping the liberty on how it's implemented.

Cheers,
--
David


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] `This expression is not a function it cannot be applied'
  2008-09-02  8:26 ` [Caml-list] " David Baelde
@ 2008-09-02  8:34   ` blue storm
  2008-09-02  8:46     ` David Teller
  0 siblings, 1 reply; 4+ messages in thread
From: blue storm @ 2008-09-02  8:34 UTC (permalink / raw)
  To: david.baelde; +Cc: Christian Sternagel, caml-list

On Tue, Sep 2, 2008 at 10:26 AM, David Baelde <david.baelde@gmail.com> wrote:
> This amouns to provide a cast from the abstract type to the function
> type, while keeping the liberty on how it's implemented.

If you want even more implementation liberty, you should consider
making the internal "token collection" type abstract : you use a list
for now, but might want to use Streams or lazy lists or what not
someday.

That would give something like that :
module Parser : sig
  type ('a,'tok) t
  type 'tok input
  val token : ('tok -> 'a option) -> ('a,'tok) t
  val apply : ('a,'tok) t -> 'tok input -> ('a * 'tok input)
  val input_of_list : 'tok list -> 'tok input
end = [...]


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] `This expression is not a function it cannot be applied'
  2008-09-02  8:34   ` blue storm
@ 2008-09-02  8:46     ` David Teller
  0 siblings, 0 replies; 4+ messages in thread
From: David Teller @ 2008-09-02  8:46 UTC (permalink / raw)
  To: blue storm; +Cc: david.baelde, caml-list

Or you can use ExtLib's enumerations for the purpose of abstraction.
That's what I'm doing in my parser combinator library.

Cheers,
 David


On Tue, 2008-09-02 at 10:34 +0200, blue storm wrote:
> On Tue, Sep 2, 2008 at 10:26 AM, David Baelde <david.baelde@gmail.com> wrote:
> > This amouns to provide a cast from the abstract type to the function
> > type, while keeping the liberty on how it's implemented.
> 
> If you want even more implementation liberty, you should consider
> making the internal "token collection" type abstract : you use a list
> for now, but might want to use Streams or lazy lists or what not
> someday.
> 
> That would give something like that :
> module Parser : sig
>   type ('a,'tok) t
>   type 'tok input
>   val token : ('tok -> 'a option) -> ('a,'tok) t
>   val apply : ('a,'tok) t -> 'tok input -> ('a * 'tok input)
>   val input_of_list : 'tok list -> 'tok input
> end = [...]
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-02  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-02  8:00 `This expression is not a function it cannot be applied' Christian Sternagel
2008-09-02  8:26 ` [Caml-list] " David Baelde
2008-09-02  8:34   ` blue storm
2008-09-02  8:46     ` David Teller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).