File: Utils.hs

package info (click to toggle)
haskell-memory 0.18.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 324 kB
  • sloc: haskell: 3,362; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE CPP #-}
module Utils where

import           Data.Word
import           Data.ByteArray               (Bytes, ScrubbedBytes)

#ifdef WITH_BASEMENT_SUPPORT
import           Basement.Block (Block)
import           Basement.UArray (UArray)
#endif

unS :: String -> [Word8]
unS = map (fromIntegral . fromEnum)

ascii :: [Word8] -> String
ascii = map (toEnum . fromIntegral)

-- | similar to proxy
data Witness a = Witness

withWitness :: Witness a -> a -> a
withWitness _ a = a

withBytesWitness :: Bytes -> Bytes
withBytesWitness = withWitness (Witness :: Witness Bytes)

withScrubbedBytesWitness :: ScrubbedBytes -> ScrubbedBytes
withScrubbedBytesWitness = id

#ifdef WITH_BASEMENT_SUPPORT
withBlockWitness :: Block Word8 -> Block Word8
withBlockWitness = withWitness (Witness :: Witness (Block Word8))

withUArrayWitness :: UArray Word8 -> UArray Word8
withUArrayWitness = withWitness (Witness :: Witness (UArray Word8))
#endif

numberedList :: [a] -> [(Int, a)]
numberedList = zip [1..]