Haskell novice here. I know from type classes that =>
means "in the context of". Yet, I can't read the following type, found in module Statistics.Sample
(Vector v (Double, Double), Vector v Double) => v (Double, Double) -> Double
What constraints are being applied on v
left of =>
?
Adjective The word 'this' can be called an adjective when it describes a noun. It's most commonly used as an adjective to emphasise the noun that's being referred to in the sentence.
type. [ tīp ] n. A number of people or things having in common traits or characteristics that distinguish them as a group or class. The general character or structure held in common by a number of people or things considered as a group or class.
When the noun that follows "types" is a countable one, the noun has to be plural. And when the noun that follows "types" is uncountable, the noun has to be singular. And "type" is followed by either an uncountable noun or a singular noun.
The definition of a type means people, places or things that share traits which allow them to belong to the same group. An example of type is men with blond hair. A perfect example; model; pattern; archetype. Printed or typewritten characters; print.
The Data.Vector.Generic.Vector
typeclass takes two type arguments, v
and a
where v :: * -> *
is the type of the container and a :: *
is the type of the elements in the container. This is simply a generic interface for the vector types defined in the vector
package, notably Data.Vector.Unboxed.Vector
.
This is essentially saying that the type v
must be able to hold (Double, Double)
and Double
, although not simultaneously. If you were to use v ~ Data.Vector.Unboxed.Vector
then this works just fine. The reason is due to the implementation of correlation
, which uses unzip
. This function splits a v (a, b)
into (v a, v b)
. Since correlation
is working on v (Double, Double)
, it needs the additional constraint that v
can hold Double
s.
This generic type is meant to make the correlation
function work with more types than Data.Vector.Vector
, including any vector style types that might be implemented in other libraries.
I want to stress that these constraints
Data.Vector.Generic.Vector v (Double, Double)
Data.Vector.Generic.Vector v Double
State that whatever type you choose for v
is capable of holding (Double, Double)
and is also capable of holding Double
. This is specifying certain prerequisites for your vector type, not the actual contents of the vector. The actual contents of the vector is specified in the first argument to the correlation
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With