[Haskell-cafe] How to convert a list to a vector encoding its length in its type?

Bas van Dijk v.dijk.bas at gmail.com
Fri Aug 21 10:59:02 EDT 2009


On Fri, Aug 21, 2009 at 2:02 PM, Miguel Mitrofanov<miguelimo38 at yandex.ru> wrote:
>>> {-# LANGUAGE UndecidableInstances #-}
>
> Ouch!
>
> Don't worry, it's just me not liking UndecidableInstances.

Without it, GHC doesn't like the 'Arg f ~ b' constraint not being
smaller than the instance head in:

instance (ModelFunc f, Arg f ~ b) => ModelFunc (b -> f) where ...

>> So instead of passing the parameters as a list I want to pass them as
>> arguments:
>>
>>> \x p1 p2 p3 -> p1*x^2 + p2*x + p3
>
> Why not use tuples?
>
> \x (p1, p2, p3) -> p1 * x^2 + p2 * x + p3
>
> Or a special list-like data type
>
> data a :* b = ($*) a b
>
> func :: Double -> (Double :* Double :* Double) -> Double
> func x (p1 $* p2 $* p3) = p1 * x^2 + p2 * x + p3

What will the type of 'levmarHL' look like using tuples or using your
special list-like type?

Thanks,

Bas


More information about the Haskell-Cafe mailing list