on 364af08 help sign in
streamly/src/Streamly/Strict.hs
59 lines 2.0 kB history raw
1-- |
2-- Module : Streamly.Strict
3-- Copyright : (c) 2019 Composewell Technologies
4-- (c) 2013 Gabriel Gonzalez
5-- License : BSD3
6-- Maintainer : harendra.kumar@gmail.com
7-- Stability : experimental
8-- Portability : GHC
9--
10-- | Strict data types to be used as accumulator for strict left folds and
11-- scans. For more comprehensive strict data types see
12-- https://hackage.haskell.org/package/strict-base-types . The names have been
13-- suffixed by a prime so that programmers can easily distinguish the strict
14-- versions from the lazy ones.
15--
16-- One major advantage of strict data structures as accumulators in folds and
17-- scans is that it helps the compiler optimize the code much better by
18-- unboxing. In a big tight loop the difference could be huge.
19--
20module Streamly.Strict
21 (
22 Tuple' (..)
23 , Tuple3' (..)
24 , Tuple4' (..)
25 , Maybe' (..)
26 , fromStrictMaybe
27 , Either' (..)
28 )
29where
31-------------------------------------------------------------------------------
32-- Tuples
33-------------------------------------------------------------------------------
34--
35data Tuple' a b = Tuple' !a !b
36data Tuple3' a b c = Tuple3' !a !b !c
37data Tuple4' a b c d = Tuple4' !a !b !c !d
39-------------------------------------------------------------------------------
40-- Maybe
41-------------------------------------------------------------------------------
42--
43-- | A strict 'Maybe'
44data Maybe' a = Just' !a | Nothing'
46-- XXX perhaps we can use a type class having fromStrict/toStrict operations.
47--
48-- | Convert strict Maybe' to lazy Maybe
49{-# INLINABLE fromStrictMaybe #-}
50fromStrictMaybe :: Monad m => Maybe' a -> m (Maybe a)
51fromStrictMaybe Nothing' = return $ Nothing
52fromStrictMaybe (Just' a) = return $ Just a
54-------------------------------------------------------------------------------
55-- Either
56-------------------------------------------------------------------------------
57--
58-- | A strict 'Either'
59data Either' a b = Left' !a | Right' !b