GHC Parametric Types Performance Indicators

I will motivate the general question more specific:

In GHC Haskell, if a Cofree [] ahas the same performance as containers-style Data.Tree a? Or does extra polymorphism lead to some kind of run-time overhead?

Generally speaking, are there any additional run-time costs associated with increasing the "arity" of a type type?

+4
source share
1 answer

I think a more classic concrete example would be something like vectors or arrays. the vector package exports both boxed and unpacked vectors. While nested vectors can contain any Haskell type (including functions), non-positioned vectors require that its elements be an instance of a type class Unbox. Although this implies a more efficient representation of packed memory without pointers, you can no longer define an instance Functorfor decompressed vectors, so it has a loss of generality.

If you used

fmap :: (a -> b) -> Vector a -> Vector b

in function type

f :: Functor f => f SomeType -> f SomeOtherType

a "", fmap . , "Core", GHC, -ddump-simpl. , arity f .

GHC , . SPECIALIZE/INLINABLE/... pragmas, , , .

, , , . 100 ( SPECIALIZE), . , , , .

+1

Source: https://habr.com/ru/post/1690531/


All Articles