MyNixOS website logo
Description

Array, vector and text.

This package provides array, slice and text operations

Z-Data

Hackage Linux Build Status macOS Build Status Windows Build Status ARM Build Status Gitter chat

This package is part of ZHaskell project, providing basic data structures and functions:

  • Array, vector(array slice), sorting, searching
  • Text based UTF-8, basic unicode manipulating, regex
  • FFI utilties
  • Fast parsing and building monad
  • JSON encoding and decoding

Requirements

  • A working haskell compiler system, GHC(>=8.6), cabal-install(>=2.4), here're some options:
    • Mac users can get them via homebew: brew install ghc cabal-install.
    • Windows users can get them via chocolatey: choco install ghc cabal.
    • Ubuntu users are recommended to use this ppa.
  • A working C/C++ compiler support C++11, here're some options:
    • Mac users can use the clang comes with the XCode or XCode Command Line Tools:
      • You can install XCode from app store, or XCode Command Line Tools with sudo xcode-select --install.
      • If you came across compiling issues like this, consider removing redundant SDKs, e.g. sudo rm -rf /Library/Developer/CommandLineTools/SDKs
    • Windows users can use the mingw's one comes with GHC, you can use it by adding your_path_to_ghc\mingw\bin to your PATH.
    • Ubuntu users can install gcc/g++ by running sudo apt install build-essential.
  • Tests need hspec-discover.

Example usage

> import qualified Z.Data.Vector as V
> import qualified Z.Data.Array as A
>
> -- convert from list
> let v = V.pack [1..10] :: V.PrimVector Int  
> -- vector combinators works on arrays as well
> let a = V.pack [1..10] :: A.Array Int   
> -- slicing vector(slice) is O(1)
> V.take 3 v                              
[1,2,3]
-- slicing array is not O(1)
> V.drop 3 a                              
fromListN 7 [4,5,6,7,8,9,10]
>
> V.intersperse 10 v
[1,10,2,10,3,10,4,10,5,10,6,10,7,10,8,10,9,10,10]
>
> V.mergeSort (V.intersperse 10 v) 
[1,2,3,4,5,6,7,8,9,10,10,10,10,10,10,10,10,10,10]
> -- Generic KMP search on vectors
> V.indices (V.singleton 10) (V.intersperse 10 v) True   
[1,3,5,7,9,11,13,15,17,18]
>
> -- quoter for writing numeric vector literals
> :set -XQuasiQuotes 
> :t [V.vecWord|1,2,3,4,5,4,3,2,1|]                     
[V.vecWord|1,2,3,4,5,4,3,2,1|] :: V.PrimVector Word
>
> import qualified Z.Data.Builder as B
> import qualified Z.Data.Text as T
> :set -XOverloadedStrings 
>
> -- Builders can be used with OverloadedStrings
> B.build $ "builders: " >> B.hex (3 :: Word16) >> B.comma >> B.double 1.2345678
[98,117,105,108,100,101,114,115,58,32,48,48,48,51,44,49,46,50,51,52,53,54,55,56]
> 
> B.buildText $ "builders: " >> B.hex (3 :: Word16) >> B.comma >> B.double 1.2345678
"builders: 0003,1.2345678"
>
> import qualified Z.Data.JSON as JSON
> import GHC.Generics
> 
> JSON.parseValue "[1,2,3,4,5]"
([],Right (Array [Number 1.0,Number 2.0,Number 3.0,Number 4.0,Number 5.0]))
>
> -- JSON module support deriving through Generic
> :set -XDeriveAnyClass -XDeriveGeneric
> data Foo = Foo {foo :: Double} deriving (JSON.JSON, Generic)
> JSON.toValue (Foo 0.01)
Object [("foo",Number 1.0e-2)]
> JSON.encodeText (Foo 0.01)
"{\"foo\":1.0e-2}"

Dev guide

# get code
git clone --recursive [email protected]:ZHaskell/z-data.git 
cd z-data
# build
cabal build
# test
cabal test --test-show-details=direct
# install 
cabal install
# generate document
cabal haddock
Metadata

Version

2.0.0.2

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows