[Haskell-cafe] Re: distinguish functions from non-functions in a class/instances

Victor Nazarov asviraspossible at gmail.com
Fri Dec 7 08:27:44 EST 2007


On Dec 7, 2007 2:52 PM,  <oleg at pobox.com> wrote:
>
> In fact, that distinction is possible. The following article
>
>         How to write an instance for not-a-function
>         http://okmij.org/ftp/Haskell/typecast.html#is-function-type
>
> specifically describes a method of writing an instance which is
> selected only when the type in question is NOT a function. The method
> is quite general and has been extensively used (for example, to
> implement deep monadic join).
>

Cool solution and not so complicated and ad-hoc. But I'd like to ask
isn't the following definition is more natural and simple?

nary 0 x [] = x
nary n f (x:xs) | n > 0 = nary (n-1) (f $ read x) xs

--
vir
http://vir.comtv.ru/


More information about the Haskell-Cafe mailing list