[Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Sat Mar 14 18:11:45 UTC 2015


Hi everybody, I have landed on a small problem.

I have a list of length n, and a function ([Double] -> Double) that
requires a list of length n.
I want to use them with a my plotting function that takes a function
(Vector n Double -> Double) and a (Vector n Double) where both n represent
same length.

I convert the known function to a new function

    newFunc = f . toList :: Vec pn Double -> Double
    -- Where pn is the peano encoding of n

I then convert the list to a vector using fromList, but then I cannot pass
them both to my plotting function.

In other words, how can I convince the type system that the length of
provided vector is the same as that required by the function.

On 12 March 2015 at 14:12, Sumit Sahrawat, Maths & Computing, IIT (BHU) <
sumit.sahrawat.apm13 at iitbhu.ac.in> wrote:

> Yeah, Data.Vector.Fixed.toList worked. I had found it previously, but it
> didn't work for Vec imported from Data.Fixed.Vector.Primitive (as (Double,
> Double) doesn't have a Prim instance).
> Then I had to switch to Data.Fixed.Vector.Unboxed, and it works now.
>
> Also, those shingles look interesting too. Thanks everybody.
>
> On 12 March 2015 at 12:35, Konstantine Rybnikov <k-bx at k-bx.com> wrote:
>
>> Is `Data.Vector.Fixed.toList` is what you're looking for?
>>
>> On Thu, Mar 12, 2015 at 1:16 AM, Sumit Sahrawat, Maths & Computing, IIT
>> (BHU) <sumit.sahrawat.apm13 at iitbhu.ac.in> wrote:
>>
>>> The fixed-vector package uses a similar technique. The only trouble I'm
>>> having is with converting Vec v (Double, Double) to [(Double, Double)] for
>>> further use. I don't want to change all the code, but only the part where
>>> the user provides me with arguments.
>>>
>>> I'll keep looking into it. Thanks for the help.
>>>
>>> On 12 March 2015 at 04:44, David Feuer <david.feuer at gmail.com> wrote:
>>>
>>>> There are a lot of ways to do this sort of thing, and which one you
>>>> choose will depend on exactly what you're trying to do. For example, you
>>>> can write something vaguely like
>>>>
>>>> data Nat = Z | S Nat
>>>> data SL (n :: Nat) a where
>>>>   Nil :: SL Z
>>>>   Cons :: a -> SL n a -> SL (S n) a
>>>>
>>>> plot :: forall (n::Nat) . (SL n Double -> Double) ->
>>>>                                         SL n (Double, Double) -> IO ()
>>>> On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
>>>> <sumit.sahrawat.apm13 at iitbhu.ac.in> 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 at haskell.org
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>>>>
>>>>>
>>>
>>>
>>> --
>>> Regards
>>>
>>> Sumit Sahrawat
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>>
>
>
> --
> Regards
>
> Sumit Sahrawat
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150314/5c859514/attachment.html>


More information about the Beginners mailing list