on master help sign in
4 files changed+323−62
since splitsnapshots
unifiedsplit
MemoTrie.cabal+29−8 examples/Generic.hs+25 src/Data/MemoTrie.hs+262−54 stack.yaml+7
MemoTrie.cabal+29−8
@@ -1,20 +1,20 @@
11Name: MemoTrie
2−Version: 0.6.1
3−Cabal-Version: >= 1.6
2+Version: 0.6.10
3+Cabal-Version: >= 1.10
44Synopsis: Trie-based memo functions
55Category: Data
66Description:
77 MemoTrie provides a basis for memoized functions over some domains,
88 using tries. It's based on ideas from Ralf Hinze and code from
9− Spencer Janssen.
9+ Spencer Janssen. Generic support thanks to Sam Boosalis.
1010 .
1111 Project wiki page: <http://haskell.org/haskellwiki/MemoTrie>
1212 .
13− &#169; 2008-2012 by Conal Elliott; BSD3 license.
14−Homepage: http://haskell.org/haskellwiki/MemoTrie
13+ &#199; 2008-2019 by Conal Elliott; BSD3 license.
14+Homepage: https://github.com/conal/MemoTrie
1515Author: Conal Elliott
1616Maintainer: conal@conal.net
17−Copyright: (c) 2008-2012 by Conal Elliott
17+Copyright: (c) 2008-2019 by Conal Elliott
1818License: BSD3
1919License-File: COPYING
2020Stability: experimental
@@ -24,10 +24,31 @@ source-repository head
2424 type: git
2525 location: git://github.com/conal/MemoTrie.git
2626
27+Flag examples
28+ Description: "examples"
29+ Default: False
30+ Manual: True
31+
2732Library
2833 hs-Source-Dirs: src
29− Extensions:
30− Build-Depends: base < 5, void
34+
35+ if impl(ghc >= 7.10.0)
36+ Build-Depends: base >=4.8.0.0 && <5, newtype-generics >= 0.5.3
37+ else
38+ Build-Depends: base <4.8.0.0, void, newtype-generics >= 0.5.3
39+
3140 Exposed-Modules:
3241 Data.MemoTrie
42+ Other-Modules:
43+
44+ default-language: Haskell2010
45+
46+executable generic
47+ if !flag(examples)
48+ buildable: False
49+ main-is: Generic.hs
50+ ghc-options: -Wall
51+ hs-source-dirs: examples
52+ default-language: Haskell2010
53+ build-depends: base, MemoTrie
3354
examples/Generic.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE DeriveGeneric, TypeOperators, TypeFamilies #-}
2+import Data.MemoTrie
3+import GHC.Generics (Generic)
4+
5+data Color = RGB Int Int Int
6+ | NamedColor String
7+ deriving (Generic)
8+
9+instance HasTrie Color where
10+ newtype (Color :->: b) = ColorTrie { unColorTrie :: Reg Color :->: b }
11+ trie = trieGeneric ColorTrie
12+ untrie = untrieGeneric unColorTrie
13+ enumerate = enumerateGeneric unColorTrie
14+
15+runColor (RGB r g b) = r + g + b
16+runColor (NamedColor s) = length [1..10e7]
17+
18+runColorMemoized = memo runColor
19+
20+main =
21+ do putStrLn "first call (should take a few seconds): "
22+ print$ runColorMemoized (NamedColor "")
23+ putStrLn "cached call (should be instantaneous): "
24+ print$ runColorMemoized (NamedColor "")
25+
src/Data/MemoTrie.hs+262−54
@@ -1,13 +1,15 @@
11{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, ScopedTypeVariables, CPP #-}
2−{-# LANGUAGE StandaloneDeriving, FlexibleInstances #-}
2+{-# LANGUAGE StandaloneDeriving, FlexibleInstances #-}
3+{-# LANGUAGE DefaultSignatures, FlexibleContexts, LambdaCase #-}
34{-# OPTIONS_GHC -Wall -fenable-rewrite-rules #-}
5+
46-- ScopedTypeVariables works around a 6.10 bug. The forall keyword is
57-- supposed to be recognized in a RULES pragma.
68
79----------------------------------------------------------------------
810-- |
911-- Module : Data.MemoTrie
10−-- Copyright : (c) Conal Elliott 2008-2012
12+-- Copyright : (c) Conal Elliott 2008-2016
1113-- License : BSD3
1214--
1315-- Maintainer : conal@conal.net
@@ -15,9 +17,35 @@
1517--
1618-- Trie-based memoizer
1719--
18−-- Adapted from sjanssen's paste: \"a lazy trie\" <http://hpaste.org/3839>,
20+-- Adapted from sjanssen's paste: <http://hpaste.org/3839 \"a lazy trie\">,
1921-- which I think is based on Ralf Hinze's paper "Memo Functions,
2022-- Polytypically!".
23+--
24+-- You can automatically derive generic instances. for example:
25+--
26+-- @
27+-- {-# LANGUAGE <https://ocharles.org.uk/blog/posts/2014-12-16-derive-generic.html DeriveGeneric>, TypeOperators, TypeFamilies #-}
28+-- import Data.MemoTrie
29+-- import GHC.Generics (Generic)
30+--
31+-- data Color = RGB Int Int Int
32+-- | NamedColor String
33+-- deriving ('Generic')
34+--
35+-- instance HasTrie Color where
36+-- newtype (Color :->: b) = ColorTrie { unColorTrie :: 'Reg' Color :->: b }
37+-- trie = 'trieGeneric' ColorTrie
38+-- untrie = 'untrieGeneric' unColorTrie
39+-- enumerate = 'enumerateGeneric' unColorTrie
40+-- @
41+--
42+-- see @examples/Generic.hs@, which can be run with:
43+--
44+-- @
45+-- cabal configure -fexamples && cabal run generic
46+-- @
47+--
48+--
2149----------------------------------------------------------------------
2250
2351module Data.MemoTrie
@@ -27,21 +55,31 @@ module Data.MemoTrie
2755 , memo, memo2, memo3, mup
2856 , inTrie, inTrie2, inTrie3
2957 -- , untrieBits
58+ , trieGeneric, untrieGeneric, enumerateGeneric, Reg
59+ , memoFix
3060 ) where
3161
3262-- Export the parts of HasTrie separately in order to get the associated data
3363-- type constructors, so I can define instances of other classes on them.
3464
65+import Data.Function (fix)
3566import Data.Bits
3667import Data.Word
3768import Data.Int
69+#if !MIN_VERSION_base(4,8,0)
3870import Control.Applicative
71+#endif
3972import Control.Arrow (first,(&&&))
73+#if !MIN_VERSION_base(4,8,0)
4074import Data.Monoid
75+#endif
4176import Data.Function (on)
77+import GHC.Generics
4278
43−import Data.Void
79+import Control.Newtype.Generics
4480
81+import Data.Void (Void)
82+
4583-- import Prelude hiding (id,(.))
4684-- import Control.Category
4785-- import Control.Arrow
@@ -98,7 +136,13 @@ untrie3 tt = untrie2 . untrie tt
98136-}
99137
100138
101−{-# RULES "trie/untrie" forall t. trie (untrie t) = t #-}
139+-- {-# RULES "trie/untrie" forall t. trie (untrie t) = t #-}
140+
141+-- warning: [-Winline-rule-shadowing] …
142+-- Rule "trie/untrie" may never fire
143+-- because rule "Class op untrie" for ‘untrie’ might fire first
144+-- Probable fix: add phase [n] or [~n] to the competing rule
145+
102146
103147-- Don't include the dual rule:
104148-- "untrie/trie" forall f. untrie (trie f) = f
@@ -126,6 +170,42 @@ mup mem f = memo (mem . f)
126170memo2 = mup memo
127171memo3 = mup memo2
128172
173+-- | Memoizing recursion. Use like `fix`.
174+memoFix :: HasTrie a => ((a -> b) -> (a -> b)) -> (a -> b)
175+memoFix h = fix (memo . h)
176+
177+#if 0
178+-- Equivalently,
179+
180+memoFix h = fix (\ f' -> memo (h f'))
181+
182+memoFix h = f'
183+ where f' = memo (h f')
184+
185+memoFix h = f'
186+ where
187+ f' = memo f
188+ f = h f'
189+#endif
190+
191+#if 0
192+-- Example
193+
194+fibF :: (Integer -> Integer) -> (Integer -> Integer)
195+fibF _ 0 = 1
196+fibF _ 1 = 1
197+fibF f n = f (n-1) + f (n-2)
198+
199+fib :: Integer -> Integer
200+fib = fix fibF
201+
202+fib' :: Integer -> Integer
203+fib' = memoFix fibF
204+
205+-- Try fib 30 vs fib' 30
206+#endif
207+
208+
129209-- | Apply a unary function inside of a trie
130210inTrie :: (HasTrie a, HasTrie c) =>
131211 ((a -> b) -> (c -> d))
@@ -149,16 +229,27 @@ inTrie3 = untrie ~> inTrie2
149229
150230instance HasTrie Void where
151231 -- As suggested by Audun Skaugen
152− data Void :->: a = VoidTrie
232+ data Void :->: a = VoidTrie
153233 trie _ = VoidTrie
154− untrie VoidTrie = absurd
234+ untrie VoidTrie = \ _ -> error "untrie VoidTrie"
235+ -- \case -- needs EmptyCase
155236 enumerate VoidTrie = []
156237
238+instance Newtype (Void :->: a) where
239+ type O (Void :->: a) = ()
240+ pack () = VoidTrie
241+ unpack VoidTrie = ()
242+
157243instance HasTrie () where
158− newtype () :->: a = UnitTrie a
159− trie f = UnitTrie (f ())
160− untrie (UnitTrie a) = \ () -> a
161− enumerate (UnitTrie a) = [((),a)]
244+ newtype () :->: a = UnitTrie a
245+ trie f = UnitTrie (f ())
246+ untrie (UnitTrie a) = \ () -> a
247+ enumerate (UnitTrie a) = [((),a)]
248+
249+instance Newtype (() :->: a) where
250+ type O (() :->: a) = a
251+ pack a = UnitTrie a
252+ unpack (UnitTrie a) = a
162253
163254-- Proofs of inverse properties:
164255
@@ -190,10 +281,15 @@ memoizing hyper-strict functions.
190281
191282
192283instance HasTrie Bool where
193− data Bool :->: x = BoolTrie x x
194− trie f = BoolTrie (f False) (f True)
195− untrie (BoolTrie f t) = if' f t
196− enumerate (BoolTrie f t) = [(False,f),(True,t)]
284+ data Bool :->: x = BoolTrie x x
285+ trie f = BoolTrie (f False) (f True)
286+ untrie (BoolTrie f t) = if' f t
287+ enumerate (BoolTrie f t) = [(False,f),(True,t)]
288+
289+instance Newtype (Bool :->: a) where
290+ type O (Bool :->: a) = (a,a)
291+ pack (a,a') = BoolTrie a a'
292+ unpack (BoolTrie a a') = (a,a')
197293
198294-- | Conditional with boolean last.
199295-- Spec: @if' (f False) (f True) == f@
@@ -219,12 +315,27 @@ if' _ e True = e
219315 BoolTrie f t
220316-}
221317
318+instance HasTrie a => HasTrie (Maybe a) where
319+ data (:->:) (Maybe a) b = MaybeTrie b (a :->: b)
320+ trie f = MaybeTrie (f Nothing) (trie (f . Just))
321+ untrie (MaybeTrie nothing_val a_trie) = maybe nothing_val (untrie a_trie)
322+ enumerate (MaybeTrie nothing_val a_trie) = (Nothing, nothing_val) : enum' Just a_trie
323+
324+instance Newtype (Maybe a :->: x) where
325+ type O (Maybe a :->: x) = (x, a :->: x)
326+ pack (a,f) = MaybeTrie a f
327+ unpack (MaybeTrie a f) = (a,f)
222328
223329instance (HasTrie a, HasTrie b) => HasTrie (Either a b) where
224− data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)
225− trie f = EitherTrie (trie (f . Left)) (trie (f . Right))
226− untrie (EitherTrie s t) = either (untrie s) (untrie t)
227− enumerate (EitherTrie s t) = enum' Left s `weave` enum' Right t
330+ data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)
331+ trie f = EitherTrie (trie (f . Left)) (trie (f . Right))
332+ untrie (EitherTrie s t) = either (untrie s) (untrie t)
333+ enumerate (EitherTrie s t) = enum' Left s `weave` enum' Right t
334+
335+instance Newtype (Either a b :->: x) where
336+ type O (Either a b :->: x) = (a :->: x, b :->: x)
337+ pack (f,g) = EitherTrie f g
338+ unpack (EitherTrie f g) = (f,g)
228339
229340enum' :: (HasTrie a) => (a -> a') -> (a :->: b) -> [(a', b)]
230341enum' f = (fmap.first) f . enumerate
@@ -259,11 +370,16 @@ as `weave` [] = as
259370
260371
261372instance (HasTrie a, HasTrie b) => HasTrie (a,b) where
262− newtype (a,b) :->: x = PairTrie (a :->: (b :->: x))
263− trie f = PairTrie (trie (trie . curry f))
264− untrie (PairTrie t) = uncurry (untrie . untrie t)
265− enumerate (PairTrie tt) =
266− [ ((a,b),x) | (a,t) <- enumerate tt , (b,x) <- enumerate t ]
373+ newtype (a,b) :->: x = PairTrie (a :->: (b :->: x))
374+ trie f = PairTrie (trie (trie . curry f))
375+ untrie (PairTrie t) = uncurry (untrie . untrie t)
376+ enumerate (PairTrie tt) =
377+ [ ((a,b),x) | (a,t) <- enumerate tt , (b,x) <- enumerate t ]
378+
379+instance Newtype ((a,b) :->: x) where
380+ type O ((a,b) :->: x) = a :->: b :->: x
381+ pack abx = PairTrie abx
382+ unpack (PairTrie abx) = abx
267383
268384{-
269385 untrie (trie f)
@@ -292,10 +408,10 @@ instance (HasTrie a, HasTrie b) => HasTrie (a,b) where
292408-}
293409
294410instance (HasTrie a, HasTrie b, HasTrie c) => HasTrie (a,b,c) where
295− newtype (a,b,c) :->: x = TripleTrie (((a,b),c) :->: x)
296− trie f = TripleTrie (trie (f . trip))
297− untrie (TripleTrie t) = untrie t . detrip
298− enumerate (TripleTrie t) = enum' trip t
411+ newtype (a,b,c) :->: x = TripleTrie (((a,b),c) :->: x)
412+ trie f = TripleTrie (trie (f . trip))
413+ untrie (TripleTrie t) = untrie t . detrip
414+ enumerate (TripleTrie t) = enum' trip t
299415
300416trip :: ((a,b),c) -> (a,b,c)
301417trip ((a,b),c) = (a,b,c)
@@ -305,10 +421,10 @@ detrip (a,b,c) = ((a,b),c)
305421
306422
307423instance HasTrie x => HasTrie [x] where
308− newtype [x] :->: a = ListTrie (Either () (x,[x]) :->: a)
309− trie f = ListTrie (trie (f . list))
310− untrie (ListTrie t) = untrie t . delist
311− enumerate (ListTrie t) = enum' list t
424+ newtype [x] :->: a = ListTrie (Either () (x,[x]) :->: a)
425+ trie f = ListTrie (trie (f . list))
426+ untrie (ListTrie t) = untrie t . delist
427+ enumerate (ListTrie t) = enum' list t
312428
313429list :: Either () (x,[x]) -> [x]
314430list = either (const []) (uncurry (:))
@@ -319,10 +435,10 @@ delist (x:xs) = Right (x,xs)
319435
320436#define WordInstance(Type,TrieType)\
321437instance HasTrie Type where \
322− newtype Type :->: a = TrieType ([Bool] :->: a);\
323− trie f = TrieType (trie (f . unbits));\
324− untrie (TrieType t) = untrie t . bits;\
325− enumerate (TrieType t) = enum' unbits t
438+ newtype Type :->: a = TrieType ([Bool] :->: a);\
439+ trie f = TrieType (trie (f . unbits));\
440+ untrie (TrieType t) = untrie t . bits;\
441+ enumerate (TrieType t) = enum' unbits t
326442
327443WordInstance(Word,WordTrie)
328444WordInstance(Word8,Word8Trie)
@@ -331,10 +447,10 @@ WordInstance(Word32,Word32Trie)
331447WordInstance(Word64,Word64Trie)
332448
333449-- instance HasTrie Word where
334−-- newtype Word :->: a = WordTrie ([Bool] :->: a)
335−-- trie f = WordTrie (trie (f . unbits))
336−-- untrie (WordTrie t) = untrie t . bits
337−-- enumerate (WordTrie t) = enum' unbits t
450+-- newtype Word :->: a = WordTrie ([Bool] :->: a)
451+-- trie f = WordTrie (trie (f . unbits))
452+-- untrie (WordTrie t) = untrie t . bits
453+-- enumerate (WordTrie t) = enum' unbits t
338454
339455
340456-- | Extract bits in little-endian order
@@ -353,10 +469,10 @@ unbits [] = 0
353469unbits (x:xs) = unbit x .|. shiftL (unbits xs) 1
354470
355471instance HasTrie Char where
356− newtype Char :->: a = CharTrie (Int :->: a)
357− untrie (CharTrie t) n = untrie t (fromEnum n)
358− trie f = CharTrie (trie (f . toEnum))
359− enumerate (CharTrie t) = enum' toEnum t
472+ newtype Char :->: a = CharTrie (Int :->: a)
473+ untrie (CharTrie t) n = untrie t (fromEnum n)
474+ trie f = CharTrie (trie (f . toEnum))
475+ enumerate (CharTrie t) = enum' toEnum t
360476
361477-- Although Int is a Bits instance, we can't use bits directly for
362478-- memoizing, because the "bits" function gives an infinite result, since
@@ -365,10 +481,10 @@ instance HasTrie Char where
365481
366482#define IntInstance(IntType,WordType,TrieType) \
367483instance HasTrie IntType where \
368− newtype IntType :->: a = TrieType (WordType :->: a); \
369− untrie (TrieType t) n = untrie t (fromIntegral n); \
370− trie f = TrieType (trie (f . fromIntegral)); \
371− enumerate (TrieType t) = enum' fromIntegral t
484+ newtype IntType :->: a = TrieType (WordType :->: a); \
485+ untrie (TrieType t) n = untrie t (fromIntegral n); \
486+ trie f = TrieType (trie (f . fromIntegral)); \
487+ enumerate (TrieType t) = enum' fromIntegral t
372488
373489IntInstance(Int,Word,IntTrie)
374490IntInstance(Int8,Word8,Int8Trie)
@@ -380,10 +496,10 @@ IntInstance(Int64,Word64,Int64Trie)
380496-- extract the sign bit.
381497
382498instance HasTrie Integer where
383− newtype Integer :->: a = IntegerTrie ((Bool,[Bool]) :->: a)
384− trie f = IntegerTrie (trie (f . unbitsZ))
385− untrie (IntegerTrie t) = untrie t . bitsZ
386− enumerate (IntegerTrie t) = enum' unbitsZ t
499+ newtype Integer :->: a = IntegerTrie ((Bool,[Bool]) :->: a)
500+ trie f = IntegerTrie (trie (f . unbitsZ))
501+ untrie (IntegerTrie t) = untrie t . bitsZ
502+ enumerate (IntegerTrie t) = enum' unbitsZ t
387503
388504
389505unbitsZ :: (Num n, Bits n) => (Bool,[Bool]) -> n
@@ -471,7 +587,12 @@ instance HasTrie a => Monad ((:->:) a) where
471587
472588instance (HasTrie a, Monoid b) => Monoid (a :->: b) where
473589 mempty = trie mempty
590+#if !MIN_VERSION_base(4,11,0)
474591 mappend = inTrie2 mappend
592+#else
593+instance (HasTrie a, Semigroup b) => Semigroup (a :->: b) where
594+ (<>) = inTrie2 (<>)
595+#endif
475596
476597instance HasTrie a => Functor ((:->:) a) where
477598 fmap f = inTrie (fmap f)
@@ -495,7 +616,6 @@ infixr 9 @.@
495616(@.@) = inTrie2 (.)
496617
497618
498−
499619-- instance Category (:->:) where
500620-- id = idTrie
501621-- (.) = (.:)
@@ -514,7 +634,6 @@ necessary but disallowed `HasTrie` constraints on the domain type.
514634
515635-}
516636
517−
518637---- To go elsewhere
519638
520639-- Matt Hellige's notation for @argument f . result g@.
@@ -530,3 +649,92 @@ f1 n = n + n
530649
531650f1' = memo f1
532651-}
652+
653+-- | just like @void@
654+instance HasTrie (V1 x) where
655+ data (V1 x :->: b) = V1Trie
656+ trie _ = V1Trie
657+ untrie V1Trie = \ _ -> error "untrie V1Trie"
658+ -- \case -- needs EmptyCase
659+ enumerate V1Trie = []
660+
661+-- | just like @()@
662+instance HasTrie (U1 x) where
663+ data (U1 x :->: b) = U1Trie b
664+ trie f = U1Trie (f U1)
665+ untrie (U1Trie b) = \U1 -> b
666+ enumerate (U1Trie b) = [(U1, b)]
667+
668+-- | wraps @Either (f x) (g x)@
669+instance (HasTrie (f x), HasTrie (g x)) => HasTrie ((f :+: g) x) where
670+ newtype ((f :+: g) x :->: b) = EitherTrie1 (Either (f x) (g x) :->: b)
671+ trie f = EitherTrie1 (trie (f . liftSum))
672+ untrie (EitherTrie1 t) = (untrie t) . dropSum
673+ enumerate (EitherTrie1 t) = enum' liftSum t
674+
675+-- | wraps @(f x, g x)@
676+instance (HasTrie (f x), HasTrie (g x)) => HasTrie ((f :*: g) x) where
677+ newtype ((f :*: g) x :->: b) = PairTrie1 ((f x, g x) :->: b)
678+ trie f = PairTrie1 (trie (f . liftProduct))
679+ untrie (PairTrie1 t) = (untrie t) . dropProduct
680+ enumerate (PairTrie1 t) = enum' liftProduct t
681+
682+-- | wraps @a@
683+instance (HasTrie a) => HasTrie (K1 i a x) where
684+ data (K1 i a x :->: b) = K1Trie (a :->: b)
685+ trie f = K1Trie (trie (f . K1))
686+ untrie (K1Trie t) = \(K1 a) -> (untrie t) a
687+ enumerate (K1Trie t) = enum' K1 t
688+
689+-- | wraps @f x@
690+instance (HasTrie (f x)) => HasTrie (M1 i t f x) where
691+ data (M1 i t f x :->: b) = M1Trie (f x :->: b)
692+ trie f = M1Trie (trie (f . M1))
693+ untrie (M1Trie t) = \(M1 a) -> (untrie t) a
694+ enumerate (M1Trie t) = enum' M1 t
695+
696+-- | the data type in a __reg__ular form.
697+-- "unlifted" generic representation. (i.e. is a unary type constructor).
698+type Reg a = Rep a ()
699+
700+-- | 'Generic'-friendly default for 'trie'
701+trieGeneric :: (Generic a, HasTrie (Reg a))
702+ => ((Reg a :->: b) -> (a :->: b))
703+ -> (a -> b)
704+ -> (a :->: b)
705+trieGeneric theConstructor f = theConstructor (trie (f . to))
706+{-# INLINEABLE trieGeneric #-}
707+
708+-- | 'Generic'-friendly default for 'untrie'
709+untrieGeneric :: (Generic a, HasTrie (Reg a))
710+ => ((a :->: b) -> (Reg a :->: b))
711+ -> (a :->: b)
712+ -> (a -> b)
713+untrieGeneric theDestructor t = \a -> (untrie (theDestructor t)) (from a)
714+{-# INLINEABLE untrieGeneric #-}
715+
716+-- | 'Generic'-friendly default for 'enumerate'
717+enumerateGeneric :: (Generic a, HasTrie (Reg a))
718+ => ((a :->: b) -> (Reg a :->: b))
719+ -> (a :->: b)
720+ -> [(a, b)]
721+enumerateGeneric theDestructor t = enum' to (theDestructor t)
722+{-# INLINEABLE enumerateGeneric #-}
723+
724+dropProduct :: (f :*: g) a -> (f a, g a)
725+dropProduct (a :*: b) = (a, b)
726+{-# INLINEABLE dropProduct #-}
727+
728+liftProduct :: (f a, g a) -> (f :*: g) a
729+liftProduct (a, b) = (a :*: b)
730+{-# INLINEABLE liftProduct #-}
731+
732+dropSum :: (f :+: g) a -> Either (f a) (g a)
733+dropSum s = case s of
734+ L1 x -> Left x
735+ R1 x -> Right x
736+{-# INLINEABLE dropSum #-}
737+
738+liftSum :: Either (f a) (g a) -> (f :+: g) a
739+liftSum = either L1 R1
740+{-# INLINEABLE liftSum #-}
stack.yamlnew file+7
@@ -0,0 +1,7 @@
1+# resolver: lts-9.21 # ghc-8.0.2
2+# resolver: lts-11.22 # ghc-8.2.2
3+# resolver: lts-12.14 # ghc-8.4.3
4+# resolver: lts-12.19 # ghc-8.4.4
5+# resolver: lts-13.0 # ghc-8.6.3
6+# resolver: lts-13.13 # ghc-8.6.4
7+resolver: lts-14.6 # ghc-8.6.5