Reputation: 1141
I was trying to find a variable for the ord value of a letter (a=97,A=65) to make my code easier to read. I found that the Data.Word8
module defines some variables for characters in the following way:
_a = 0x61
_b = 0x62
_c = 0x63
_d = 0x64
etc.
However, when I try to use these variables I get the following error:
Found hole `_x' with type: t
Where: `t' is a rigid type variable bound by
the inferred type of it :: t at <interactive>:27:1
Relevant bindings include it :: t (bound at <interactive>:27:1)
In the expression: _x
In an equation for `it': it = _x
This is the first time I've encountered typed-holes. After looking at an introduction to typed-holes I still don't understand (a) Why Data.Word8
uses them and (b) How can the typed-holes appear on the LHS of the equals sign. In the introduction I read they only appear on the RHS (c) How can I use these variables in my code?
If anyone has an explanation it would be appreciated.
Edit: I feel a bit stupid now. I was mixing up the Data.Word8
package with the Data.Word
package which contains the Word8
data type.
Upvotes: 1
Views: 89
Reputation: 105905
(a) Why Data.Word8 uses them
It doesn't. You forgot to import Data.Word8
. Therefore, the identifier _x
is unknown:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
ghci> _x
<interactive>:2:1:
Found hole ‘_x’ with type: t
Where: ‘t’ is a rigid type variable bound by
the inferred type of it :: t at <interactive>:2:1
Relevant bindings include it :: t (bound at <interactive>:2:1)
In the expression: _x
In an equation for ‘it’: it = _x
ghci> import Data.Word8
ghci> _x
120
(b) How can the typed-holes appear on the LHS of the equals sign
It does appear on the right hand side, because GHCi uses it = <last-expression>
. Since the last expression was _x
, you suddenly have a typed hole.
(c) How can I use these variables in my code?
Import Data.Word8
.
Upvotes: 5