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