Mathematical functions with multiple arguments

Hi everybody, I have a function of type plot :: ([Double] -> Double) -- A function to plot -> [(Double, Double)] -- Range for all arguments -> IO () I want to enforce the fact that ranges for all arguments should be provided. Is there a way to make the type system enforce it? -- Regards Sumit Sahrawat

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/dep...
You'd end up with `plot :: (Vector n Double -> Double) -> Vector n (Double,
Double) -> IO ()' where `n' is the length of the vector.
HTH,
Adam
On Wed, Mar 11, 2015 at 10:45 PM, Sumit Sahrawat, Maths & Computing, IIT
(BHU)
Hi everybody,
I have a function of type
plot :: ([Double] -> Double) -- A function to plot -> [(Double, Double)] -- Range for all arguments -> IO ()
I want to enforce the fact that ranges for all arguments should be provided. Is there a way to make the type system enforce it?
-- Regards
Sumit Sahrawat
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

I was wondering whether it was possible using fixed-vector, ut dependent
types seem to be a new thing I can experiment with.
Thanks for the quick reply.
On 12 March 2015 at 03:26, Adam Bergmark
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/dep...
You'd end up with `plot :: (Vector n Double -> Double) -> Vector n (Double, Double) -> IO ()' where `n' is the length of the vector.
HTH, Adam
On Wed, Mar 11, 2015 at 10:45 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU)
wrote: Hi everybody,
I have a function of type
plot :: ([Double] -> Double) -- A function to plot -> [(Double, Double)] -- Range for all arguments -> IO ()
I want to enforce the fact that ranges for all arguments should be provided. Is there a way to make the type system enforce it?
-- Regards
Sumit Sahrawat
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Regards Sumit Sahrawat

On Wed, Mar 11, 2015 at 5:56 PM, Adam Bergmark
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/dep...
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
participants (3)
-
Adam Bergmark
-
adam vogt
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)