[Haskell-cafe] Mathematical functions with multiple arguments

adam vogt vogt.adam at gmail.com
Thu Mar 12 02:58:31 UTC 2015


On Wed, Mar 11, 2015 at 5:56 PM, Adam Bergmark <adam at bergmark.nl> wrote:

> If I understand you correctly you seem to want dependent types, this
> article uses the same example you need, promoting the length of a
> vector/list to the type level:
> https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell
>
> You'd end up with `plot :: (Vector n Double -> Double) -> Vector n
> (Double, Double) -> IO ()' where `n' is the length of the vector.
>

It seems like tuples are more straightforward:

class Plot x where
  plot :: (x -> Double)
    -> x -- ^ lower bound
    -> x -- ^ upper bound
    -> IO ()

instance Plot Double where
 plot = plot2d

instance Plot (Double,Double) where
 plot = plot3d

And then that lets you do something like:

instance Plot (Double, Shingle Double) where
 plot = plot2d_faceted

-- |
https://stat.ethz.ch/R-manual/R-devel/library/lattice/html/shingles.html
data Shingle a = Shingle [(a,a)] a


Regards,
Adam Vogt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150311/35bbd64d/attachment.html>


More information about the Haskell-Cafe mailing list