RIO.ByteString.split not working as documented

62 views Asked by At

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?

1

There are 1 answers

1
willeM_ Van Onsem On BEST ANSWER

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",""]