1

Trying an example from split docs:

$ stack ghci
...
Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 'a' "aXaXaXa"

<interactive>:3:9: error:
    • Couldn't match expected type ‘GHC.Word.Word8’
                  with actual type ‘Char’
    • In the first argument of ‘B.split’, namely ‘'a'’
      In the expression: B.split 'a' "aXaXaXa"
      In an equation for ‘it’: it = B.split 'a' "aXaXaXa"

What am I missing?

levant pied
  • 3,886
  • 5
  • 37
  • 56

1 Answers1

1

The documentation is taken from the split :: Char -> ByteString -> [ByteString] function of the Data.ByteString.Char8 module. This uses the code points 0-255 as Char for the corresponding byte.

You can however use the byte value instead. For example 'a' has as byte value 97, so we can split this with:

Prelude> :set -XOverloadedStrings
Prelude> import qualified RIO.ByteString as B
Prelude B> B.split 97 "aXaXaXa"
["","X","X","X",""]
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555