Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this type?

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 => ?

like image 406
Vorac Avatar asked Jul 20 '17 16:07

Vorac


People also ask

What word type is this?

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.

What is mean by a type?

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.

What types and what type?

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.

What are examples of types?

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.


Video Answer


1 Answers

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 Doubles.

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.

like image 168
bheklilr Avatar answered Oct 15 '22 00:10

bheklilr