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

Victor Nazarov asviraspossible at gmail.com
Fri Dec 7 09:30:13 EST 2007


On Dec 7, 2007 4:46 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Dec 7, 2007 6:27 AM, Victor Nazarov <asviraspossible at gmail.com> wrote:
> >
> > nary 0 x [] = x
> > nary n f (x:xs) | n > 0 = nary (n-1) (f $ read x) xs
>
> Sometimes it helps to write type signatures for functions.  As in this
> case, where you'll find you won't be able to...  :-)
>
> Luke
>

Ok :)

> {-# OPTIONS -fglasgow-exts #-}
> {-# OPTIONS -fallow-undecidable-instances #-}

data Zero
data Succ a

class Nary n x y | n x -> y where
  nary :: n -> x -> [String] -> y

instance Nary Zero x x where
  nary _ x [] = x

instance (Nary n y z, Read x) => Nary (Succ n) (x->y) z where
  nary _ f (x:xs) = nary (undefined::n) (f $ read x) xs

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


More information about the Haskell-Cafe mailing list