[<<][compsci][>>][..]
Tue Oct 4 20:22:14 EDT 2011

Function arity

{-# LANGUAGE TypeOperators, TypeSynonymInstances #-}

-- Small test for parameterizing over types that represent multi in /
-- multi out functions like:
--   (* -> (* -> (* -> (* :& (* :& (* :& (* :& ())))))))

infixr :&
type (:&) a as = (a, as)
infixr &
(&) :: a -> as -> a :& as
a & as = (a, as)

-- First test is to map the type signature to a pair of numbers
-- representing the I/O arity.

class (NbIO f) where
  nbIO :: f -> (Int, Int)

instance NbIO () where nbIO _ = (0,0)

instance NbIO os => NbIO (o :& os) where
  nbIO os  = (ni, no + 1) where
    (ni, no) = nbIO (snd os)

instance NbIO f => NbIO (i -> f) where
  nbIO f  = (ni + 1, no) where
    (ni, no) = nbIO (f undefined)

# nbIO (\a b c -> (a,(b,(c, ()))))
# => (3,3)




[Reply][About]
[<<][compsci][>>][..]