Search code examples
ghci

PrimOps in GHCi


Is it possible to use PrimOps in GHCi? The following does not work:

$ ghci -XMagicHash
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/stefan/.ghci
λ> let x = 42.0# :: Float#

<interactive>:1:18: error:
    Not in scope: type constructor or class ‘Float#’
    Perhaps you meant ‘Float’ (imported from Prelude)

Importing Prelude manually does not solve this error.

Update: After importing GHC.Exts the following error shows up:

$ ghci -XMagicHash
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/stefan/.ghci
λ> import GHC.Exts
λ> let x = 42.0# :: Float#

<interactive>:1:1: error:
    GHCi can't bind a variable of unlifted type: x :: Float#

Solution

  • The MagicHash extension just makes it legal to use # in names. If you want to specify types like Float#, you still need to import them. Do import GHC.Exts and try again.

    Also, you can't bind them with let. You need to immediately use them and rewrap them.