Re: higher-order functors

John Reppy <[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
The syntax you want is something like

   funsig COROUTINE (type result) = sig ... end

   functor Generator (functor Coroutine : COROUTINE) : GENERATOR =  
struct ... end

see http://smlnj.org/doc/features.html for details.

Of course, this syntax is SML/NJ specific.

	- John

On Jan 22, 2007, at 6:16 PM, Dave Herman wrote:

> I found the need for a higher-order functor like the following:
>
>      functor Generator(functor Coroutine(type result) : COROUTINE)
>                    : GENERATOR =
>      struct
>          datatype signal = ...
>          structure C = Coroutine(type result = signal)
>          ...
>      end
>
> In other words, it takes an implementation of COROUTINE that's itself
> parameterized over the result type, and instantiates that type at
> `signal'. So a use would look like:
>
>      structure G = Generator(functor Coroutine = MyCoroutine)
>
> What's a good workaround for this kind of use case? I'd like the
> Coroutine module to be abstract in the type of values passed between
> coroutines, and I'd like the Generator module to be abstract in the
> implementation of Coroutines.
>
> (Also, it turns out I can't just change the COROUTINE signature to  
> use a
> polymorphic type 'a coroutine for implementation reasons; one of the
> implementations uses continuations in a way that has to be  
> monomorphic.)
>
> Thanks,
> Dave
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.