Doubtful code in GHC.Prim

I met the following code in GHC.Prim :

...

negateFloat# :: Float# -> Float#
negateFloat# = let x = x in x

-- |Truncates a @Float#@ value to the nearest @Int#@.
--     Results are undefined if the truncation if truncation yields
--     a value outside the range of @Int#@.

float2Int# :: Float# -> Int#
float2Int# = let x = x in x

expFloat# :: Float# -> Float#
expFloat# = let x = x in x

logFloat# :: Float# -> Float#
logFloat# = let x = x in x

...

In particular:

  • float2Int# shouldn't even check type
  • None of the functions accepts an argument and therefore does not look correct
  • None of the functions apply the mathematical operation that they require.
  • All functions are "infinitely recursive": let x = x

I know that the extension is called "MagicHash", but it cannot be magical. What gives?

(I think I should add a disclaimer that I have no idea what, in fact -XMagicHash, I just assumed that he allowed the syntax #and nothing more.)

+4
source share
1 answer

The key is at the top of the module:

{-
This is a generated file (generated by genprimopcode).
It is not code to actually be used. Its only purpose is to be
consumed by haddock.
-}

, let x = x in x undefined ; x , - , , .

"", , Haskell , , .

+14

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


All Articles