on da62ada help sign in
48 lines 1.6 kB history raw
1-- |
2-- Module : Streamly.Internal.Data.Maybe.Strict
3-- Copyright : (c) 2019 Composewell Technologies
4-- (c) 2013 Gabriel Gonzalez
5-- License : BSD3
6-- Maintainer : streamly@composewell.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.Internal.Data.Maybe.Strict
21 ( Maybe' (..)
22 , toMaybe
23 , isJust'
24 , fromJust'
25 )
26where
28-- | A strict 'Maybe'
29data Maybe' a = Just' !a | Nothing' deriving Show
31-- | Convert strict Maybe' to lazy Maybe
32{-# INLINABLE toMaybe #-}
33toMaybe :: Maybe' a -> Maybe a
34toMaybe Nothing' = Nothing
35toMaybe (Just' a) = Just a
37-- | Extract the element out of a Just' and throws an error if its argument is
38-- Nothing'.
39{-# INLINABLE fromJust' #-}
40fromJust' :: Maybe' a -> a
41fromJust' (Just' a) = a
42fromJust' Nothing' = error "fromJust' cannot be run in Nothing'"
44-- | Returns True iff its argument is of the form "Just' _".
45{-# INLINABLE isJust' #-}
46isJust' :: Maybe' a -> Bool
47isJust' (Just' _) = True
48isJust' Nothing' = False