[Haskell-cafe] Is it possible to type a function to accept only literal values?

Daneel Yaitskov dyaitskov at gmail.com
Tue Feb 27 17:32:48 UTC 2024


Hi List,

Recently I was experimenting with a GCC intrinsic functions for x86
SMID instructions to write a fast CSV parser and noticed that some
arguments are required to be literal values (known at compile time),
which makes live hard, e.g. bit shift operation expects number of bits
to shift in such a way.
Nonetheless the intel manual defines function prototypes as normal:

   __m128i _mm_bsrli_si128 (__m128i a, int imm8)

Using a variable as second argument in _mm_bsrli_si128 produces
unclear, but  compilation error with exact line number.
Definitely some magic happens here, because it is not possible to
express this constraint type system of C language.

Haskell is known as one of the best languages in type acrobatics, but
could it beat C here?

-- 

Best regards,
Daniil Iaitskov


More information about the Haskell-Cafe mailing list