h,M1            !" # $ %&'()*+,-. /01234 5 6 7 89: ; <= >?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                                                                                                                                                                                      !!"""""""#################$$$%%%%%%%%%%%%&&&&&&&&&&&&&&&&&&&&&&&&&&''''(())))))******++++++++,,-----------------------------..///00111121.2.2.09 (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3 Shorter alias for pure ().pass :: Maybe ()Just ()*Useful shortcut when need an empty action: printJust :: Maybe Int -> IO () printJust mInt = case mInt of Just i -> putStrLn $ "Number: " ++ show i Nothing -> pass reludeNamed version of the  operator, which is " but flipped. It is helpful for chaining applicative operations in forward applications using 3.Just (+ 1) & appliedTo (Just 2)Just 32Just (+) & appliedTo (Just 1) & appliedTo (Just 2)Just 3Nothing & appliedTo (Just 2)Nothing5$"#5"#$(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortable Trustworthy"3Dq382Rp9-abc`deHD]^\S>QPG=>D\]^-`abcdemijklnoHPQG3829SRpq(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3 fhgStablePortable Trustworthy"3 (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3}<6767(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3Renamed version of 45. identity 1010fmap identity [1,2,3][1,2,3]  (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3&++(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3M Alias for  fmap . fmap%. Convenient to work with two nested +s.negate <<$>> Just [1,2,3]Just [-1,-2,-3]reludeTakes a function in a +* context and applies it to a normal value.flap (++) "relude" "P" "Prelude"reludeOperator version of the  function.[(+2), (*3)] ?? 5[7,15]Just (+3) ?? 5Just 8667(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3 ;*+(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3( relude1Creates a tuple by pairing something with itself. dup "foo" ("foo","foo")dup ()((),())reludeApply a function, with the result in the fst slot, and the value in the other. A dual to .toFst length [3, 1, 0, 2] (4,[3,1,0,2]) toFst (+5) 10(15,10)reludeApply a function, with the result in the snd slot, and the value in the other. A dual to .toSnd length [3, 1, 0, 2] ([3,1,0,2],4) toSnd (+5) 10(10,15)reludeLike 7, but also keep the original value in the snd position. A dual to .fmapToFst show [3, 10, 2][("3",3),("10",10),("2",2)]reludeLike 7, but also keep the original value in the fst position. A dual to .fmapToSnd show [3, 10, 2][(3,"3"),(10,"10"),(2,"2")]reludeApply a function, with the result in the fst slot, and the value in the other. A dual to mapToFst (+1) 10(11,10)reludeApply a function, with the result in the second slot, and the value in the other. A dual to .mapToSnd (+1) 10(10,11)reludeApply a function that returns a value inside of a functor, with the output in the first slot, the input in the second, and the entire tuple inside the functor. A dual to traverseToFst (Just . (+1)) 10 Just (11,10) traverseToFst (const Nothing) 10NothingreludeApply a function that returns a value inside of a functor, with the output in the second slot, the input in the first, and the entire tuple inside the functor. A dual to .traverseToSnd (Just . (+1)) 10 Just (10,11) traverseToSnd (const Nothing) 10NothingMaps a function that returns a value inside of an applicative functor over both elements of a tuple, with the entire tuple inside the applicative functor.4traverseBoth (Just . ("Hello " <>)) ("Alice", "Bob") Just ("Hello Alice","Hello Bob")-traverseBoth (const Nothing) ("Alice", "Bob")Nothing  (c) 2021-2023 KowainikMITKowainik StablePortableSafe"32treludeReturns all values of some % & in ascending order.universe :: [Bool] [False,True]universe @Ordering [LT,EQ,GT]data TrafficLight = Red | Blue | Green deriving (Show, Enum, Bounded)universe :: [TrafficLight][Red,Blue,Green]9data Singleton = Singleton deriving (Show, Enum, Bounded)universe @Singleton [Singleton]reludeLike , but returns O list of some enumeration!universeNonEmpty :: NonEmpty BoolFalse :| [True]universeNonEmpty @Ordering LT :| [EQ,GT]data TrafficLight = Red | Blue | Green deriving (Show, Eq, Enum, Bounded))universeNonEmpty :: NonEmpty TrafficLightRed :| [Blue,Green]=data Singleton = Singleton deriving (Show, Eq, Enum, Bounded)universeNonEmpty @SingletonSingleton :| []relude inverseMap f< creates a function that is the inverse of a given function f. It does so by constructing 89 internally for each value f a). The implementation makes sure that the 899 is constructed only once and then shared for every call.Memory usage note:. don't inverse functions that have types like Int* as their input. In this case the created 89 will have huge size.&The complexity of reversed mapping is \mathcal{O}(\log n).Performance note: make sure to specialize monomorphic type of your functions that use  to avoid 89 reconstruction.One of the common  use-case is inverting the show or a show-like function.>data Color = Red | Green | Blue deriving (Show, Enum, Bounded)0parse = inverseMap show :: String -> Maybe Color parse "Red"Just Red parse "Black"NothingCorrectness note:  expects injective function as its argument, i.e. the function must map distinct arguments to distinct values./Typical usage of this function looks like this: data GhcVer = Ghc802 | Ghc822 | Ghc844 | Ghc865 | Ghc881 deriving (Eq, -, Show, &, %) showGhcVer :: GhcVer -> Text showGhcVer = \case Ghc802 -> "8.0.2" Ghc822 -> "8.2.2" Ghc844 -> "8.4.4" Ghc865 -> "8.6.5" Ghc881 -> "8.8.1" parseGhcVer :: Text -> C GhcVer parseGhcVer =  showGhcVer %& & %(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"35Lifted version of :;.exitWith (ExitFailure 3)*** Exception: ExitFailure 3exitWith ExitSuccess*** Exception: ExitSuccessLifted version of :<. exitFailure*** Exception: ExitFailure 1Lifted version of :=. exitSuccess*** Exception: ExitSuccessLifted version of :>.die "Goodbye!"Goodbye!*** Exception: ExitFailure 1(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3 a + 6) readIORef ref48To avoid space-leaks, see  for stricter updatesFor atomic updates, see Lifted version of ?D.ref <- newIORef 42modifyIORef' ref (\a -> a + 3) readIORef ref45For lazier updates, see For atomic updates, see Lifted version of ?E.ref <- newIORef 42(atomicModifyIORef ref (\a -> (a, a + 3))45 readIORef ref42To avoid space-leaks, see  for stricter updates3If you are not interested in the return value, see Lifted version of ?F.ref <- newIORef 42)atomicModifyIORef' ref (\a -> (a, a + 3))45 readIORef ref42For lazier updates, see 3If you are not interested in the return value, see relude Version of < that discards return value. Useful when you want to update , but not interested in the returning result.ref <- newIORef 42 atomicModifyIORef_ ref (`div` 2) readIORef ref21relude Version of < that discards return value. Useful when you want to update , but not interested in the returning result.ref <- newIORef 42!atomicModifyIORef'_ ref (`div` 2) readIORef ref21Lifted version of ?G.ref <- newIORef 42atomicWriteIORef ref 45 readIORef ref45  (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortable Trustworthy"3>Creates an infinite list from a finite list by appending the list to itself infinite times (i.e. by cycling the list). Unlike cycle from  Data.List, this implementation doesn't throw error on empty lists, but returns an empty list instead.cycle [][]take 10 $ cycle [1,2,3][1,2,3,1,2,3,1,2,3,1]--(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3@!*NZ[CXW*!CXWNZ[(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3H Similar to  but with flipped arguments.readMaybe "True" ?: FalseTruereadMaybe "Tru" ?: FalseFalseSpecialized version of HI for C!. It's used for code readability.!Also helps to avoid space leaks:  http://www.snoyman.com/blog/2017/01/foldable-mapm-maybe-and-recursive-functionsFoldable.mapM_ space leak.&whenJust Nothing $ \b -> print (not b)*whenJust (Just True) $ \b -> print (not b)FalseMonadic version of ..whenJustM (pure Nothing) $ \b -> print (not b)2whenJustM (pure $ Just True) $ \b -> print (not b)FalsePerforms default 5 action if W( is given. Otherwise returns content of X pured to 5.!whenNothing Nothing [True, False] [True,False]%whenNothing (Just True) [True, False][True]Performs default 5 action if W is given. Do nothing for X. Convenient for discarding X content.+whenNothing_ Nothing $ putTextLn "Nothing!"Nothing!/whenNothing_ (Just True) $ putTextLn "Nothing!"Monadic version of .>whenNothingM (pure $ Just True) $ True <$ putTextLn "Is Just!"True>whenNothingM (pure Nothing) $ False <$ putTextLn "Is Nothing!" Is Nothing!FalseMonadic version of .7whenNothingM_ (pure $ Just True) $ putTextLn "Is Just!"6whenNothingM_ (pure Nothing) $ putTextLn "Is Nothing!" Is Nothing!reludeThe monadic version of the JK function.:{#evenInHalf :: Int -> IO (Maybe Int) evenInHalf n& | even n = pure $ Just $ n `div` 2 | otherwise = pure Nothing:}mapMaybeM evenInHalf [1..10] [1,2,3,4,5]L(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortable Trustworthy"3P $Shorter and more readable alias for flip runReaderT.usingReaderT 42 $ asks (+5)47$Shorter and more readable alias for flip runReader.usingReader 42 $ asks (+5)47reludeThis function helps with optimizing performance when working with the  transformer. If you have code like below, that is called in a loop step :: Instruction -> % Config IO Result step instruction = case instruction of Add -> do stuff ... Del -> do stuff ... you can improve performance of your Haskell applications by using  in the following way: step :: Instruction -> % Config IO Result step instruction =  $ case instruction of Add -> do stuff ... Del -> do stuff ... =For a detailed explanation, refer to the following blog post: https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT> pure False (False,42)$Shorter and more readable alias for  flip runState. Alias for flip evalStateT. It's not shorter but sometimes more readable. Done by analogy with using* functions family. Alias for flip evalState. It's not shorter but sometimes more readable. Done by analogy with using* functions family. Alias for flip execStateT. It's not shorter but sometimes more readable. Done by analogy with using* functions family. Alias for flip execState. It's not shorter but sometimes more readable. Done by analogy with using* functions family.reludeLift a C to the  monadreludeLift a N to the  monad   (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3=TD Extracts ; value from C returning  if HM.+maybeToMonoid (Just [1,2,3] :: Maybe [Int])[1,2,3]&maybeToMonoid (Nothing :: Maybe [Int])[]reludeReturns the given value in case of the given predicate is satisfied (is Y). Otherwise, it returns .!memptyIfFalse True (Just "Hello") Just "Hello"$memptyIfFalse False "Doesn't matter"""reludeReturns the given value in case of the given predicate is unsatisfied (is U). Otherwise, it returns . memptyIfTrue True (Just "Hello")Nothing memptyIfTrue False "Does matter" "Does matter"/; :8; :(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3ZRemoves duplicate elements from a list, keeping only the first occurrence of the element.Like 4N but runs in  O(n \log n)  time and requires -.ordNub [3, 3, 3, 2, 2, -1, 1] [3,2,-1,1]relude Similar to  but performs nub through the mapped list on the given function.3ordNubOn (`div` 10) [3, 3, 3, 13, 2, 22, -1, 1, 66][3,13,22,-1,66]Like 4N but runs in  O(n \log_{16} n)  time and requires .hashNub [3, 3, 3, 2, 2, -1, 1] [3,2,-1,1]Like  runs in  O(n \log n)  but also sorts a list.sortNub [3, 3, 3, 2, 2, -1, 1] [-1,1,2,3]Like  runs in  O(n \log_{16} n) 7 but has better performance; it doesn't save the order."unstableNub [3, 3, 3, 2, 2, -1, 1] [1,2,3,-1]reludeRemoves duplicate elements from a list, keeping only the first occurance of the element.Like 4N but runs in  O (n \min (n, int\_bits ))  time and requires -.intNub [3, 3, 3, 2, 2, -1, 1] [3,2,-1,1]relude Similar to  but works on lists of any types by performing "nubbing" through s.!intNubOn fromEnum "ababbbcdaffee""abcdfe" (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"/13f,For tracking usage of Text instead of String takes OP& and splits it into the list by lines..Actual type of this function is the following:  lines :: OP -> [OP] but it was given a more complex type to provide friendlier compile time errors.lines ""[]lines "one line" ["one line"]lines "line 1\nline 2"["line 1","line 2"]lines ("string line" :: String)...,... 'lines' works with 'Text', not 'String'. Possible fixes:> 1. Make sure OverloadedStrings extension is enabled.. 2. Apply 'toText' to a single value.2 3. Apply 'map toText' to the list value.... lines True...... 'lines' works with 'Text' But given: 'Bool'... takes list of OP+ values and joins them with line separator..Actual type of this function is the following:  unlines :: [OP] -> OP but it was given a more complex type to provide friendlier compile time errors. unlines []""unlines ["line 1"] "line 1\n"%unlines ["first line", "second line"]"first line\nsecond line\n"*unlines (["line 1", "line 2"] :: [String])....... 'unlines' works with 'Text', not 'String'. Possible fixes:> 1. Make sure OverloadedStrings extension is enabled.. 2. Apply 'toText' to a single value.2 3. Apply 'map toText' to the list value....unlines [True, False]...... 'unlines' works with 'Text' But given: 'Bool'... takes OP& and splits it into the list by words..Actual type of this function is the following:  words :: OP -> [OP] but it was given a more complex type to provide friendlier compile time errors.words ""[]words "one line"["one","line"]words " >_< "[">_<"] words ("string words" :: String)...,... 'words' works with 'Text', not 'String'. Possible fixes:> 1. Make sure OverloadedStrings extension is enabled.. 2. Apply 'toText' to a single value.2 3. Apply 'map toText' to the list value.... words True...... 'words' works with 'Text' But given: 'Bool'... takes list of OP, values and joins them with space character..Actual type of this function is the following:  unwords :: [OP] -> OP but it was given a more complex type to provide friendlier compile time errors. unwords []""unwords ["singleWord"] "singleWord"unwords ["word", "another"]"word another")unwords (["word", "another"] :: [String])....... 'unwords' works with 'Text', not 'String'. Possible fixes:> 1. Make sure OverloadedStrings extension is enabled.. 2. Apply 'toText' to a single value.2 3. Apply 'map toText' to the list value....unwords [True, False]...... 'unwords' works with 'Text' But given: 'Bool'...4.=4=.(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"13 relude'Type class for lazy-strict conversions.,Helper type family to produce error messages+Type class for converting other strings to =.+Type class for converting other strings to QP.+Type class for converting other strings to RP.9Type class for conversion to utf8 representation of text.Encode as utf8 string (usually ST).$encodeUtf8 @Text @ByteString ""*"\208\191\208\176\209\130\208\176\208\186"Decode from utf8 string.decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186""\1087\1072\1090\1072\1082"putTextLn $ decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186"Decode as utf8 string but returning execption if byte sequence is malformed.decodeUtf8 @Text @ByteString "\208\208\176\209\130\208\176\208\186""\65533\1072\1090\1072\1082"decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"9Left Cannot decode byte '\xd0': ...: Invalid UTF-8 streamType synonym for UT.Type synonym for VP. Version of WX that returns  in case of the parse error.readEither @Int "123" Right 123readEither @Int "aa"Left "Prelude.read: no parse"Generalized version of 4Y . Unlike 4Y this function is polymorphic in its result type. This makes it more convenient to work with data types like  P or %. However, if you pass the result of  to a function that expects polymorphic argument, this can break type inference, so use -XTypeApplications( to specify the textual type explicitly.show (42 :: Int)"42"show (42 :: Double)"42.0"print (show @Text True)"True" Alias for  function. Alias for  function.reludereluderelude Converting = to ZT might be a slow operation. Consider using lazy bytestring at first place.reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:+toString ("some string" :: ShortByteString)...?... Type 'ShortByteString' doesn't have instance of 'ToString'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:7 decodeUtf8 :: ShortByteString -> String decodeUtf8Strict :: ShortByteString -> Either UnicodeException String...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:'toString ("some string" :: LByteString)...;... Type 'LByteString' doesn't have instance of 'ToString'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:3 decodeUtf8 :: LByteString -> String decodeUtf8Strict :: LByteString -> Either UnicodeException String...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:&toString ("some string" :: ByteString)...:... Type 'ByteString' doesn't have instance of 'ToString'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:2 decodeUtf8 :: ByteString -> String decodeUtf8Strict :: ByteString -> Either UnicodeException String...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:*toLText ("some string" :: ShortByteString)...>... Type 'ShortByteString' doesn't have instance of 'ToLText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:6 decodeUtf8 :: ShortByteString -> LText decodeUtf8Strict :: ShortByteString -> Either UnicodeException LText...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:&toLText ("some string" :: LByteString)...:... Type 'LByteString' doesn't have instance of 'ToLText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:2 decodeUtf8 :: LByteString -> LText decodeUtf8Strict :: LByteString -> Either UnicodeException LText...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:%toLText ("some string" :: ByteString)...9... Type 'ByteString' doesn't have instance of 'ToLText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:1 decodeUtf8 :: ByteString -> LText decodeUtf8Strict :: ByteString -> Either UnicodeException LText...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:)toText ("some string" :: ShortByteString)...=... Type 'ShortByteString' doesn't have instance of 'ToText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:5 decodeUtf8 :: ShortByteString -> Text decodeUtf8Strict :: ShortByteString -> Either UnicodeException Text...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:%toText ("some string" :: LByteString)...9... Type 'LByteString' doesn't have instance of 'ToText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:1 decodeUtf8 :: LByteString -> Text decodeUtf8Strict :: LByteString -> Either UnicodeException Text...reludeMCAUTION2M This instance is for custom error display only.7You should always specify encoding of bytes explicitly.?In case it is used by mistake, the user will see the following:$toText ("some string" :: ByteString)...8... Type 'ByteString' doesn't have instance of 'ToText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:0 decodeUtf8 :: ByteString -> Text decodeUtf8Strict :: ByteString -> Either UnicodeException Text...[(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3*)4.=(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3&Lifted version of R\.putText "Hello, world!" Hello, world!Lifted version of R].putTextLn "Hello, world!" Hello, world!Lifted version of ^\.putLText "Hello, world!" Hello, world!Lifted version of ^].putLTextLn "Hello, world!" Hello, world!reludeLifted version of _\.%putBS ("Hello, world!" :: ByteString) Hello, world!reludeLifted version of _].'putBSLn ("Hello, world!" :: ByteString) Hello, world!reludeLifted version of `\.'putLBS ("Hello, world!" :: LByteString) Hello, world!reludeLifted version of `].)putLBSLn ("Hello, world!" :: LByteString) Hello, world!(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3Lifted version of ab.reludeLifted version of ac. Strict version of .Lifted version of ad.Lifted version of ae.(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3q reludeLifted version of Rb.reludeLifted version of Rd.reludeLifted version of Re.reludeLifted version of Qb.reludeLifted version of Qd.reludeLifted version of Qe.reludeLifted version of _b.reludeLifted version of _d.reludeLifted version of _e.reludeLifted version of `b.reludeLifted version of `d.reludeLifted version of `e.   (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortable Trustworthy"/0138=U  Similar to  but data type.Prints the given =. message and returns the passed value of type a.increment l = map (+1) lincrement [2, 3, 4][3,4,5]increment l = trace ("incrementing each value of: " ++ show l) (map (+1) l)increment [2, 3, 4]#incrementing each value of: [2,3,4][3,4,5]If you want to print a 2able value instead of =, use .+If you want to print the value itself, use .If you want to print by specifying a custom formatting function, use . Similar to # but prints a given value with the 2 instance instead of a =.increment l = map (+1) lincrement [2, 3, 4][3,4,5]&increment l = traceShow l (map (+1) l)increment [2, 3, 4][2,3,4][3,4,5] If you want to print a specific = instead, use 4If you want to print and return the same value, use 7If you want to specify a custom printing function, use  Similar to ? but prints the given value itself instead of a separate value.'traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld")(6,"helloworld")2If you to specify a different value to print, use  or 4If you want to have more control over printing, use reludeSimilar , but uses a provided function to convert the argument to a value with the 2 constraint.traceShowWith fst (1, "ABC")1 (1,"ABC")In other words,  D  id.>This function is useful for debugging values that do not have 2 instance:fst $ traceShowWith fst (1, id)110If you don't need such flexibility, use simpler ,  or Trace function to print values while working a pure monad (e.g. Maybe, State, etc.):{ let action :: Maybe Int action = do x <- Just 3 traceM ("x: " ++ show x) y <- pure 12 traceM ("y: " ++ show y) pure (x*2 + y) in action:}x: 3y: 12Just 18&If you want to print a value with the 2 instance instead, use Like  , but uses HY$ on the argument to convert it to a =.:{ let action :: Maybe Int action = do x <- Just 3 traceShowM x y <- pure 12 traceShowM y pure (x*2 + y) in action:}312Just 18 Similar to  but specialised for =.traceId "hello""hellohello"Throw pure errors. Use this function only to when you are sure that this branch of code execution is not possible.  DO NOT USE & as a normal error handling mechanism. error "oops"*** Exception: oopsCallStack (from HasCallStack):4 error, called at src/Relude/Debug.hs:296:11 in ......MCAUTION M Unlike Prelude version,  takes HP as an argument. In case it used by mistake, the user will see the following:error ("oops" :: String)...2... 'error' expects 'Text' but was given 'String'. Possible fixes:< * Make sure OverloadedStrings extension is enabled; * Use 'error (toText msg)' instead of 'error msg'... error False...... 'error' works with 'Text' But given: Bool...4f, that leaves warning in code on every usage.  (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3W Maps left part of N to C.leftToMaybe (Left True) Just TrueleftToMaybe (Right "aba")NothingMaps right part of N to C.rightToMaybe (Left True)NothingrightToMaybe (Right "aba") Just "aba"Maps C to N wrapping default value into Z.maybeToRight True (Just "aba") Right "aba"maybeToRight True Nothing Left TrueMaps C to N wrapping default value into [.maybeToLeft True (Just "aba") Left "aba"maybeToLeft True Nothing Right TrueApplies given action to N content if Z- is given and returns the result. In case of [$ the default value will be returned.6whenLeft "bar" (Left 42) (\a -> "success!" <$ print a)42 "success!"7whenLeft "bar" (Right 42) (\a -> "success!" <$ print a)"bar"Applies given action to N content if Z is given.whenLeft_ (Right 42) putTextLn whenLeft_ (Left "foo") putTextLnfooMonadic version of .>whenLeftM "bar" (pure $ Left 42) (\a -> "success!" <$ print a)42 "success!"?whenLeftM "bar" (pure $ Right 42) (\a -> "success!" <$ print a)"bar"Monadic version of .&whenLeftM_ (pure $ Right 42) putTextLn(whenLeftM_ (pure $ Left "foo") putTextLnfooApplies given action to N content if [- is given and returns the result. In case of Z$ the default value will be returned.:whenRight "bar" (Left "foo") (\a -> "success!" <$ print a)"bar"8whenRight "bar" (Right 42) (\a -> "success!" <$ print a)42 "success!"Applies given action to N content if [ is given.whenRight_ (Left "foo") printwhenRight_ (Right 42) print42Monadic version of .whenRightM "bar" (pure $ Left "foo") (\a -> "success!" <$ print a)"bar"whenRightM "bar" (pure $ Right 42) (\a -> "success!" <$ print a)42 "success!"Monadic version of .%whenRightM_ (pure $ Left "foo") print#whenRightM_ (pure $ Right 42) print42reludeFor convenient work with .!(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3relude>For chaining monadic operations in forward applications using (&) Named version of .0Just [ 1 :: Int ] & chainedTo (viaNonEmpty head)Just 1&Nothing & chainedTo (viaNonEmpty head)Nothingrelude%Repeat a monadic action indefinitely.$This is a more type safe version of ), which has a convenient but unsafe type.,Consider the following two examples. In the  getIntForever functions, it falsely expects Int as the result of the  function. But it would need to wait *forever* to get that, and this mistake won't be caught by the type system and compiler: getIntForever :: IO Int getIntForever = do i <- forever $ do ... pure i In contrast, using  instead of  in foo is a type error.!*NZ[CXW(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"/13^)For tracking usage of ordinary list with head-like functions.relude-For safe work with lists using functions for O.viaNonEmpty head [1]Just 1viaNonEmpty head []NothingPerforms given action over O! list if given list is non empty.+whenNotNull [] $ \(b :| _) -> print (not b)5whenNotNull [False,True] $ \(b :| _) -> print (not b)TrueMonadic version of .O(1)". Extracts the first element of a O list..Actual type of this function is the following: head :: O a -> a but it was given a more complex type to provide friendlier compile time errors.head ('a' :| "bcde")'a'head [0..5 :: Int] ...5... 'head' works with 'NonEmpty', not ordinary lists. Possible fix: Replace: [Int] With: NonEmpty Int...: However, you can use 'head' with the ordinary lists./ Apply 'viaNonEmpty' function from relude:% viaNonEmpty head (yourList)- Note, that this will return 'Maybe Int' therefore it is a safe function unlike 'head' from the standard Prelude...head (Just 'a')...+... 'head' works with 'NonEmpty Char' lists But given: Maybe Char...O(n). Return all the elements of a O" list except the last one element..Actual type of this function is the following: init :: O a -> [a] but it was given a more complex type to provide friendlier compile time errors.init ('a' :| "bcde")"abcd"init [0..5 :: Int] ...5... 'init' works with 'NonEmpty', not ordinary lists. Possible fix: Replace: [Int] With: NonEmpty Int...: However, you can use 'init' with the ordinary lists./ Apply 'viaNonEmpty' function from relude:% viaNonEmpty init (yourList)/ Note, that this will return 'Maybe [Int]' therefore it is a safe function unlike 'init' from the standard Prelude...init (Just 'a')...+... 'init' works with 'NonEmpty Char' lists But given: Maybe Char...O(n)!. Extracts the last element of a O list..Actual type of this function is the following: last :: O a -> a but it was given a more complex type to provide friendlier compile time errors.last ('a' :| "bcde")'e'last [0..5 :: Int] ...5... 'last' works with 'NonEmpty', not ordinary lists. Possible fix: Replace: [Int] With: NonEmpty Int...: However, you can use 'last' with the ordinary lists./ Apply 'viaNonEmpty' function from relude:% viaNonEmpty last (yourList)- Note, that this will return 'Maybe Int' therefore it is a safe function unlike 'last' from the standard Prelude...last (Just 'a')...+... 'last' works with 'NonEmpty Char' lists But given: Maybe Char...O(1). Return all the elements of a O list after the head element..Actual type of this function is the following: tail :: O a -> [a] but it was given a more complex type to provide friendlier compile time errors.tail ('a' :| "bcde")"bcde"tail [0..5 :: Int] ...5... 'tail' works with 'NonEmpty', not ordinary lists. Possible fix: Replace: [Int] With: NonEmpty Int...: However, you can use 'tail' with the ordinary lists./ Apply 'viaNonEmpty' function from relude:% viaNonEmpty tail (yourList)/ Note, that this will return 'Maybe [Int]' therefore it is a safe function unlike 'tail' from the standard Prelude...tail (Just 'a')...+... 'tail' works with 'NonEmpty Char' lists But given: Maybe Char... O O(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe "(3PType that represents exceptions used in cases when a particular codepath is not meant to be ever executed, but happens to be executed anyway.Pattern synonym to easy pattern matching on exceptions. So instead of writing something like this: isNonCriticalExc :: SomeException -> Bool isNonCriticalExc e | Just (_ :: NodeAttackedError) <- fromException e = True | Just DialogUnexpected{} <- fromException e = True | otherwise = False  you can use  pattern synonym: isNonCriticalExc :: SomeException -> Bool isNonCriticalExc = case Exc (_ :: NodeAttackedError) -> True -- matching all exceptions of type NodeAttackedError Exc DialogUnexpected{} -> True _ -> False +This pattern is bidirectional. You can use Exc e instead of  toException e.Generate a pure value which, when forced, will throw the given exceptionGenerate a pure value which, when forced, will synchronously throw the exception wrapped into  data type. rr(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3Lifted alias for gh with a clearer name.let list = [1..5] :: [Int] :sprint listlist = _() <$ evaluateWHNF list :sprint list list = 1 : _Like  but discards value.let list = [1..5] :: [Int] :sprint listlist = _evaluateWHNF_ list :sprint list list = 1 : _ Alias for evaluateWHNF . force with a clearer name.let list = [1..5] :: [Int] :sprint listlist = _() <$ evaluateNF list :sprint listlist = [1,2,3,4,5] Alias for evaluateWHNF . rnf . Similar to " but discards the resulting value.let list = [1..5] :: [Int] :sprint listlist = _evaluateNF_ list :sprint listlist = [1,2,3,4,5]  "(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3Monadic version of -. Conditionally executes the provided action.+whenM (pure False) $ putTextLn "No text :(",whenM (pure True) $ putTextLn "Yes text :)" Yes text :)whenM (Just True) (pure ())Just ()whenM (Just False) (pure ())Just ()whenM Nothing (pure ())NothingMonadic version of  . Reverse of 2. Conditionally don't execute the provided action.-unlessM (pure False) $ putTextLn "No text :(" No text :(-unlessM (pure True) $ putTextLn "Yes text :)"Monadic version of  if-then-else.ifM (pure True) (putTextLn "True text") (putTextLn "False text") True textifM (pure False) (putTextLn "True text") (putTextLn "False text") False textMonadic version of & that help to check that a condition (<) holds inside. Works with *s that are also .guardM (Just True)Just ()guardM (Just False)NothingguardM NothingNothing(Here some complex but real-life example: findSomePath :: IO (Maybe FilePath) somePath :: MaybeT IO FilePath somePath = do path <- MaybeT findSomePath guardM $ liftIO $ doesDirectoryExist path return path reludeEither lifts a value into an alternative context or gives a minimal value depending on a predicate. Works with s.guarded even 3 :: [Int][]guarded even 2 :: [Int][2],guarded (const True) "hello" :: Maybe String Just "hello"-guarded (const False) "world" :: Maybe StringNothingYou can use this function to implement smart constructors simpler: newtype HttpHost = HttpHost { unHttpHost :: Text } mkHttpHost :: Text -> Maybe HttpHost mkHttpHost host = HttpHost <$>  (not . Text.null) host reludeMonadic version of ij operator..It is lazy by the second argument (similar to ik)), meaning that if the first argument is U, the function will return U( without evaluating the second argument.Just False &&^ Just True Just FalseJust True &&^ Just True Just TrueJust True &&^ NothingNothingJust False &&^ Nothing Just False-Just False &&^ error "Shouldn't be evaluated" Just FalsereludeMonadic version of ik operator..It is lazy by the second argument (similar to ik)), meaning that if the first argument is Y, the function will return Y( without evaluating the second argument.Just False ||^ Just True Just TrueJust False ||^ Just False Just FalseJust False ||^ NothingNothingJust True ||^ Nothing Just True,Just True ||^ error "Shouldn't be evaluated" Just Truel(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3fhgStablePortable Trustworthy"3relude?Transforms an integer number to a bounded integral. It returns W3 for integers outside the bound of the return type.integerToBounded @Int 42Just 42integerToBounded @Int8 1024Nothing3integerToBounded @Int (toInteger (minBound :: Int))Just (-9223372036854775808)9integerToBounded @Int $ (toInteger (minBound :: Int)) - 1Nothing3integerToBounded @Int (toInteger (maxBound :: Int))Just 92233720368547758079integerToBounded @Int $ (toInteger (maxBound :: Int)) + 1NothingIf you want to convert  or I# to a bounded type, take a look at  function instead.reludeTransforms an integer number to a natural. Only non-negative integers are considered natural, everything else will return W.integerToNatural (-1)NothingintegerToNatural 0Just 0integerToNatural 10Just 10'0,tsuv( ){~|y}zEF/1KLMJAB?T@VIJIMLK@V?T'0A,stuvwx( )yz{|}~/1EFB#(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe "3gTypeclass for data types that can be created from one element. E.g. lists, non-empty containers, maps.one True :: [Bool][True]one 'a' :: Text"a"&one (3, "hello") :: HashMap Int StringfromList [(3,"hello")]Laws: single-size: D x . size (one x) D 1(where size is a specific function for each container that returns the size of this container)*Type of a single element of the structure.Create a list, map, RP, etc from a single element.Create singleton .one 42 :: IntSet fromList [42] law> mn ( x) D 1 Create singleton .one 42 :: HashSet Int fromList [42] law> Ho ( @( a) x) D 1 Create singleton .one 42 :: Set Int fromList [42] law> Ho ( @( a) x) D 1 Create singleton  from key-value pair.one (3, "foo") :: IntMap TextfromList [(3,"foo")] law> Ho ( @( a) x) D 1 Create singleton  from key-value pair."one (3, "foo") :: HashMap Int TextfromList [(3,"foo")] law> Ho ( @( k v) (k, v)) D 1 Create singleton  from key-value pair.one (3, "foo") :: Map Int TextfromList [(3,"foo")] law> Ho ( @( k v) (k, v)) D 1 Create singleton pq.one 97 :: ShortByteString"a" law> po ( x) D 1 Create singleton lazy rT.one 97 :: LByteString"a" law> ro ( x) D 1 Create singleton strict _T.one 97 :: ByteString"a" law> _o ( x) D 1 Create singleton lazy ^P.one 'a' :: LText"a" law> Vo ( x) D 1 Create singleton strict RP.one 'a' :: Text"a" law> Oo ( x) D 1 Create singleton st.one 42 :: Seq Int fromList [42] law> Ho ( @(st a) x) D 1 Allows to create singleton uv+ list. You might prefer function with name  instead of Hw or (:|[]).one 42 :: NonEmpty Int42 :| [] law> Ho ( @(uv a) x) D 1 Allows to create a singleton list. You might prefer function with name  instead of Hw or (:[]).one 42 :: [Int][42] law> Ho ( @[a] x) D 1 x(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3E$(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3JreludeSafer version of y, returns a Maybe.:Get element from list using index value starting from `0`.[] !!? 0Nothing["a", "b", "c"] !!? 3Nothing[1, 2, 3] !!? (-1)Nothing["a", "b", "c"] !!? 2Just "c"relude with its arguments flipped.:Get element from list using index value starting from `0`. maybeAt 0 []NothingmaybeAt 3 ["a", "b", "c"]NothingmaybeAt (-1) [1, 2, 3]NothingmaybeAt 2 ["a", "b", "c"]Just "c"reludePartitions a list based on the result of function which produces an Either value. List of all elements producing Left are extracted, in order, to the first element of the output tuple. Similarly, a list of all elements producing Right are extracted to the second element of output.:{- divideEvenOrShow :: Int -> Either Int String divideEvenOrShow n | even n = Left $ n `div` 2, | otherwise = Right $ "Odd: " <> show n :}'partitionWith divideEvenOrShow [1 .. 6]&([1,2,3],["Odd: 1","Odd: 3","Odd: 5"]):Oz (c) 2020-2023 KowainikMITKowainik StablePortableSafe"3reludeLifted version of a{.reludeLifted version of a|.reludeLifted version of a}.reludeLifted version of a~. _ _(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3 Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of . Lifted to  version of .##%(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"013 3Type family that produces compile-time errors when  and  functions are used with  and . Similar to 1 but takes a function with its arguments flipped."flipfoldl' (/) 5 [2,3] :: Rational15 % 2This function can be useful for constructing containers from lists.reludeAlternative version of H# that takes a function to map over.8asumMap (\x -> if x > 2 then Just x else Nothing) [1..4]Just 3reludePolymorphic version of the H function.+foldMapA @[Int] (Just . replicate 3) [1..3]Just [1,1,1,2,2,2,3,3,3]reludePolymorphic version of the H function.+foldMapM @[Int] (Just . replicate 3) [1..3]Just [1,1,1,2,2,2,3,3,3]Stricter version of . sum [1..10]55Stricter version of .product [1..10]3628800Like  but doesn't work on  and  for performance reasons.elem 'x' ("abc" :: String)False!elem False (one True :: Set Bool) ...... Do not use 'elem' and 'notElem' methods from 'Foldable' on Set Suggestions: Instead of< elem :: (Foldable t, Eq a) => a -> t a -> Bool use3 member :: Ord a => a -> Set a -> Bool... Instead of? notElem :: (Foldable t, Eq a) => a -> t a -> Bool use not . member...Like  but doesn't work on  and  for performance reasons.notElem 'x' ("abc" :: String)True$notElem False (one True :: Set Bool) ...... Do not use 'elem' and 'notElem' methods from 'Foldable' on Set Suggestions: Instead of< elem :: (Foldable t, Eq a) => a -> t a -> Bool use3 member :: Ord a => a -> Set a -> Bool... Instead of? notElem :: (Foldable t, Eq a) => a -> t a -> Bool use not . member...Monadic version of .andM [Just True, Just False] Just FalseandM [Just True] Just True%andM [Just True, Just False, Nothing] Just FalseandM [Just True, Nothing]NothingandM [putTextLn "1" >> pure True, putTextLn "2" >> pure False, putTextLn "3" >> pure True]12FalseMonadic version of .orM [Just True, Just False] Just TrueorM [Just True, Nothing] Just TrueorM [Nothing, Just True]NothingMonadic version of .,allM (readMaybe >=> pure . even) ["6", "10"] Just True-allM (readMaybe >=> pure . even) ["5", "aba"] Just False.allM (readMaybe >=> pure . even) ["aba", "10"]NothingMonadic version of .,anyM (readMaybe >=> pure . even) ["5", "10"] Just True.anyM (readMaybe >=> pure . even) ["10", "aba"] Just True.anyM (readMaybe >=> pure . even) ["aba", "10"]Nothing  (c) 2018-2023 KowainikMITKowainik StablePortableSafe"367&(c) 2018-2023 KowainikMITKowainik StablePortable Trustworthy "35reludeModifiable Map.reludeRead-only map or set. Contains polymorphic functions which work for both sets and maps.reludeOperator version of  function.=let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]myHashMap !? 'b' Just "yyy"myHashMap !? 'd'Nothingrelude Inverse of  function.=let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]notMember 'b' myHashMapFalsenotMember 'c' myHashMapTruereludeReturn the value to which the specified key is mapped, or the default value if this map contains no mapping for the key.=let myHashMap = HashMap.fromList [('a', "xxx"), ('b', "yyy")]!lookupDefault "zzz" 'b' myHashMap"yyy"!lookupDefault "zzz" 'c' myHashMap"zzz"relude:Converts the structure to the list of the key-value pairs.7toPairs (HashMap.fromList [('a', "xxx"), ('b', "yyy")])[('a',"xxx"),('b',"yyy")]relude/Converts the structure to the list of the keys.4keys (HashMap.fromList [('a', "xxx"), ('b', "yyy")])"ab"relude1Converts the structure to the list of the values.5elems (HashMap.fromList [('a', "xxx"), ('b', "yyy")]) ["xxx","yyy"]reludereludereludereludereludereludereludereludereludeDefault value to return. Key to searchContainer to searchz '(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3xLifted version of O.Lifted version of 4.Lifted version of a\.Lifted version of a].((c) 2020-2023 KowainikMITKowainik StablePortableSafe"3YreludeLifted version of .reludeLifted version of .(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"34_H(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableSafe"3!qfhg5$"#+*; O:NZ[6473%& r'08_,tsuv.( ){~|y}zEF/12Rp9KLMJ-abc`deHD]^\AB=CXWSQ?T@VPIG)(c) 2018-2023 KowainikMITKowainik StablePortableSafe"013 7relude*Check that a type is an element of a list::kind! Elem String '[]Elem String '[] :: Bool= 'False!:kind! Elem String '[Int, String]"Elem String '[Int, String] :: Bool= 'True:kind! Elem String '[Int, Bool] Elem String '[Int, Bool] :: Bool= 'Falserelude0Returns second element of tuple type (with kind *!) or type-level tuple (with kind (k1, k2), marked by prefix quote).:kind! Maybe (Snd '(Int, Text))Maybe (Snd '(Int, Text)) :: * = Maybe Text:kind! Maybe (Snd (Int, Text))Maybe (Snd (Int, Text)) :: * = Maybe Textrelude/Returns first element of tuple type (with kind *!) or type-level tuple (with kind (k1, k2), marked by prefix quote).:kind! Maybe (Fst '(Int, Text))Maybe (Fst '(Int, Text)) :: * = Maybe Int:kind! Maybe (Fst (Int, Text))Maybe (Fst (Int, Text)) :: * = Maybe IntreludeBuilds combined Q by applying Constraint constructor to all elements of type-level list.(:kind! AllHave Show '[Int, Text, Double]/AllHave Show '[Int, Text, Double] :: Constraint:= (Show Int, (Show Text, (Show Double, () :: Constraint)))which is equivalent to: 1(Show Int, Show Text, Show Double) :: Constraint reludeConcatenates type-level lists.>:kind! '[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1]'[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1] :: [Maybe Natural]3= '[ 'Just 5, 'Nothing, 'Just 3, 'Nothing, 'Just 1],:kind! '[] ++ '[ 'Just 3, 'Nothing, 'Just 1]8'[] ++ '[ 'Just 3, 'Nothing, 'Just 1] :: [Maybe Natural] = '[ 'Just 3, 'Nothing, 'Just 1] # 91 "srcReludeExtra/Type.hs"relude'Gets a string representation of a type.NOTE: This must be used with TypeApplications language extension. typeName @()"()" typeName @Int"Int"typeName @String"[Char]"typeName @(Maybe Int) "Maybe Int"*(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3reludeUnwraps value from newtype.%newtype Size = Size Int deriving Showun @Int (Size 5)5%un (Size 5) == length ['a', 'x', 'b']FalsereludeWraps value to newtype. Behaves exactly as  but has more meaningful name in case you need to convert some value to newtype.,newtype Flag = Flag Bool deriving (Show, Eq)wrap False == Flag TrueFalserelude#Applies function to the content of newtype.. This function is not supposed to be used on newtype7s that are created with the help of smart constructors.$newtype Foo = Foo Bool deriving Showunder not (Foo True) Foo False&newtype Bar = Bar String deriving Show'under (filter (== 'a')) (Bar "abacaba") Bar "aaaa"reludeLift binary function for newtypes to work over underlying newtype representation.#under2 @(Sum Int) (<>) (3 :: Int) 47under2 @All (<>) True FalseFalserelude Version of  that works on newtypes parametrized by their representation. Provided for convenience.underF2 @Sum (<>) (3 :: Int) 47underF2 @Max (<>) 'p' 't''t'reludeCoercible composition. This function allows to write more efficient implementations of function compositions over newtypes.+(c) 2012-2016 Edward Kmett (c) 2019-2023 KowainikMITKowainik StablePortableSafe"3reludeThe monomorphic lenses which don't change the type of the container (or of the value inside). It has a + constraint, and since both  and  are functors, it can be used whenever a getter or a setter is needed.a- is the type of the value inside of structures# is the type of the whole structurereludeCreates  from the getter and setter.relude/Gets a value out of a structure using a getter.relude5Sets the given value to the structure using a setter.relude)Applies the given function to the target.reludeThe operator form of  with the arguments flipped.reludeThe operator form of .reludeThe operator form of .66,(c) 2018-2023 KowainikMITKowainik StablePortableSafe "3reludeStablePortableSafe"13!?)For tracking usage of ordinary list with  functions.relude;The class of foldable data structures that cannot be empty.Map each element of the non-empty structure to a semigroup, and combine the results. foldMap1 SG.Sum (1 :| [2, 3, 4])Sum {getSum = 10}$foldMap1 show (123 :| [456, 789, 0]) "1234567890"Combine the elements of a non-empty structure using a semigroup.$fold1 (1 :| [2, 3, 4 :: SG.Sum Int])Sum {getSum = 10}&fold1 (4 :| [5, 10 :: SG.Product Int])Product {getProduct = 200}reludeCombines the elements of a non-empty structure using a binary function f.foldr1 (+) 0 (1 :| [2, 3])6foldr1 (+) 1 $ Identity 346Convert a non-empty data structure to a NonEmpty list.toNonEmpty (Identity 2)2 :| []0The first element of a non-empty data structure.head1 (1 :| [2, 3, 4])1/The last element of a non-empty data structure.last1 (1 :| [2, 3, 4])42The largest element of a non-empty data structure.!maximum1 (32 :| [64, 8, 128, 16])1283The smallest element of a non-empty data structure.!minimum1 (32 :| [64, 8, 128, 16])8reludeThe largest element of a non-empty data structure with respect to the given comparison function.$maximumOn1 abs (0 :| [2, 1, -3, -2])-3reludeThe smallest element of a non-empty data structure with respect to the given comparison function.$minimumOn1 abs (0 :| [2, 1, -3, -2])0relude7Strictly folds non-empty structure with given function f: 0foldl1' f [x0, x1, x2 ...] = f (f x0 x1) x2 ... &foldl1' (++) ([1,2] :| [[3,4], [5,6]]) [1,2,3,4,5,6]reludeGiven a  of ( elements, computes the average if possible and returns the resulting element.average1 (42 :| [])42.0average1 (1 :| [2,3,4])2.5reludereludereludereludereludereludereludeMCAUTION2M This instance is for custom error display only.+ is not supposed to be used with the lists.?In case it is used by mistake, the user will see the following:head1 [1, 2, 3] ...... The methods of the 'Foldable1' type class work with non-empty containers. However, one of the 'Foldable1' functions is applied to the List.... Possible fixes: * Replace [] with one of the: 'NonEmpty', 'Identity', '(c,)', 'Compose f g', 'Product f g', 'Sum f g'4 * Or use 'Foldable' class for your own risk....  .(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3$reludeA left-associative fold that's tail-recursive but can still short-circuit. Returning a Z short-circuits and immediately returns the value inside. Returning a [3 continues the fold as usual with the value inside.foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 [1..6]720foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 (0:error "Short-circuiting should keep this from happening")0reludeGiven a 6 of (8 elements, computes the average if possible and returns C element. average [42] Just 42.0average @Double [1, 2, 3, 4]Just 2.5average @Float [1.5, 2.5, 3 ,4] Just 2.75 average []Nothing/(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3'reludeLike , but doesn't fail on . Instead it returns . next FalseTrue next TrueFalse succ True3*** Exception: Prelude.Enum.Bool.succ: bad argumentreludeLike , but doesn't fail on . Instead it returns . prev TrueFalse prev FalseTrue pred False3*** Exception: Prelude.Enum.Bool.pred: bad argumentreludeReturns W if given  outside range.safeToEnum @Bool 0 Just FalsesafeToEnum @Bool 1 Just TruesafeToEnum @Bool 2NothingsafeToEnum @Bool (-1)Nothing0(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3+6reludeThis function returns the name of its caller function, but it requires that the caller function has p# constraint. Otherwise, it returns " unknown".,foo :: HasCallStack => String; foo = ownNamefoo"foo"(bar :: HasCallStack => String; bar = foobar"foo"reludeThis function returns the name of its caller of the caller function, but it requires that the caller function and caller of the caller function have p# constraint. Otherwise, it returns " unknown". It's useful for logging:log :: HasCallStack => String -> IO (); log s = putStrLn $ callerName ++ ":" ++ sgreeting :: HasCallStack => IO (); greeting = log "Starting..." >> putStrLn "Hello!" >> log "Ending..."greetinggreeting:Starting...Hello!greeting:Ending...1(c) 2018-2023 KowainikMITKowainik StablePortableSafe"3-relude2Maps a function over both elements of a bifunctor.(bimapBoth length ([True], [False, True])(1,2),map (bimapBoth not) [Left True, Right False][Left False,Right True]relude0Fmaps functions for nested bifunctor. Short for fmap (bimap f g).,bimapF not length $ Just (False, ['a', 'b']) Just (True,2)relude Short for  fmap . first.%firstF not $ Just (False, ['a', 'b'])Just (True,"ab")relude Short for  fmap . second.*secondF length $ Just (False, ['a', 'b'])Just (False,2)(c) 2019-2023 KowainikMITKowainik StablePortable Safe-Inferred"3.g(c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 KowainikMITKowainik StablePortableUnsafe"30 Similar to  but with flipped arguments. get element from list using index value starting from `0`.at 2 ["a", "b", "c"]"c"it is also useful when used in a partially applied position like:8map (at 1) [["a","b","c"], ["a","b","c"], ["a","b","c"]] ["b","b","b"]wavMQjk5Ky3oIqTt9P  ;<=>@ABCDEFG       XYbcde           f        !!"""""""#################$$${|}~%%%%%%%%%%%%&&&&&&&&&n&&&&&&&&&&&&&&&&&'''\'](())))))******++++++++,,-----------------------------..///001111                 % - relude-1.2.2.0-inplaceRelude.List.Reexport Relude.BaseRelude.Bool.ReexportRelude.FunctionRelude.Numeric Relude.EnumRelude.Monad.ReexportRelude.Functor.ReexportRelude.String.ReexportRelude.Container.Reexport Relude.MonoidRelude.ApplicativeRelude.Foldable.ReexportRelude.List.NonEmptyRelude.Lifted.HandleRelude.Exception Relude.UnsafeRelude.Functor.FmapRelude.Lifted.ConcurrentRelude.Monad.EitherRelude.Lifted.IORefRelude.DeepSeqRelude.Extra.TupleRelude.Lifted.ExitRelude.Monad.MaybeRelude.Monad.Trans Relude.NubRelude.String.Conversion Relude.PrintRelude.Lifted.File Relude.File Relude.Debug Relude.MonadRelude.Bool.GuardRelude.Container.One Relude.ListRelude.Foldable.FoldRelude.Extra.MapRelude.Lifted.TerminalRelude.Lifted.EnvRelude.Extra.TypeRelude.Extra.NewtypeRelude.Extra.LensRelude.Extra.GroupRelude.Extra.Foldable1Relude.Extra.FoldableRelude.Extra.EnumRelude.Extra.CallStackRelude.Extra.Bifunctorrelude&Preludeid4Relude.FunctorMMap System.ExitexitWith exitFailure exitSuccessdieRefnewIORef readIORef writeIORef modifyIORef modifyIORef'atomicModifyIORefatomicModifyIORef'atomicWriteIORefReludefor_ Data.MaybemapMaybe0Nothingnub Data.TextTextLTTB ByteStringData.ByteString.LazyData.Text.Lazy Text.Read readEithershowLB Relude.StringputStrputStrLnTLBSLBSIOreadFile readFile' writeFile appendFile undefinedControl.Exception.Baseevaluate Data.Bool&&|| Relude.Bool Data.IntSetsizelengthSBSShortByteStringBSLSEQSeqNENonEmptypureRelude.Container!!9hFlushhIsEOF hSetBuffering hGetBufferingCCM newEmptyMVarnewMVarputMVarreadMVarswapMVartakeMVar tryPutMVar tryReadMVar tryTakeMVarSTM atomically newTVarIO readTVarIO newTMVarIOnewEmptyTMVarIOasum concatMapA concatMapMFsumproductelemnotElemandorallanyRelude.FoldablegetLineprintSystem.EnvironmentgetArgs lookupEnv Relude.Lifted58$dmfold1 $dmfoldr1$dmhead1$dmlast1 $dmmaximum1 $dmmaximumOn1 $dmminimum1 $dmminimumOn1 $dmtoNonEmpty Relude.Extra ghc-internalGHC.Internal.Base++ghc-primGHC.PrimseqGHC.Internal.Listfilterzip otherwisemap$GHC.Internal.Num fromInteger-GHC.Internal.Real fromRationalGHC.Internal.EnumenumFrom enumFromThen enumFromToenumFromThenTo GHC.Classes>=negate>>=>>fmapreturnGHC.Internal.Data.String fromString fromIntegral realToFrac toInteger toRationalGHC.Internal.Control.MonadguardGHC.Internal.IsListIsListfromList fromListN<>memptymappendmconcatjoin<*>*>BoundedEnumGHC.Internal.FloatFloating FractionalIntegralMonadFunctorNumOrdGHC.Internal.ReadReadReal RealFloatRealFracGHC.Internal.ShowShow#GHC.Internal.Data.Typeable.InternalTypeableIsString ApplicativeGHC.Internal.Data.FoldableFoldableGHC.Internal.Data.Traversable TraversableGHC.Internal.GenericsGenericGHC.Internal.TypeNatsKnownNat SemigroupMonoid GHC.TypesBoolStringCharDoubleFloat ghc-bignumGHC.Num.IntegerIntegerGHC.Num.NaturalNaturalGHC.Internal.MaybeMaybeOrderingRatioRational~WordGHC.Internal.WordWord8Word16Word32Word64GHC.Internal.Data.EitherEitherType ConstraintGHC.Internal.Stack.Types CallStackGHC.Internal.TypeNats.InternalCmpNatD#FalseF#JustTrueLeftRightEQGTGHC.Internal.IO.Handle.TypesHandlecompare<<=>maxminnot $dmcompare$dm<$dm<=$dm>$dm>=$dmmax$dmmin HasCallStack getCallStackGHC.Internal.Exception.Type SomeException+*abssignum$dm- $dmnegatequotremdivmodquotRemdivMod$dmquot$dmrem$dmdiv$dmmod $dmdivMod:| MonadPlusmzeromplus Alternativeempty<|>somemanyliftA2<*<$sconcatstimes<**>liftA3=<<whenordminIntmaxIntconst.flip$!asTypeOf$dm<$$dm<*> $dmliftA2$dm*>$dm<*$dm>> $dmreturn$dmsome$dmmany$dmmzero$dmmplus$dm<> $dmsconcat $dmstimes $dmmempty $dmmappend $dmmconcatGHC.Internal.Stack.CCScurrentCallStackGHC.Internal.Stack prettySrcLocprettyCallStacksubtractGHC.Internal.Data.MaybemaybeisJust isNothingfromJust fromMaybe maybeToList listToMaybe catMaybesheadunconstaillastinitscanlscanl1scanl'scanrscanr1iteraterepeat replicate takeWhile dropWhiletakedropsplitAtspanbreakreversezip3zipWithunzipunzip3GHC.Internal.CharchrsuccpredtoEnumfromEnumminBoundmaxBoundboundedEnumFromboundedEnumFromThen$dmsucc$dmpred $dmenumFrom$dmenumFromThen $dmenumFromTo$dmenumFromThenToproperFractiontruncateroundceilingfloor/recip numerator denominatorevenodd^^^gcdlcm$dm/$dmrecip $dmtruncate$dmround $dmceiling$dmfloorGHC.Internal.BitsxortoIntegralSized byteSwap16 byteSwap32 byteSwap64 floatRadix floatDigits floatRange decodeFloat encodeFloatisNaN isInfiniteisDenormalizedisNegativeZeroisIEEEatan2piexpsqrt**logBasesincostanasinacosatansinhcoshtanhasinhacoshatanh$dmsqrt$dm** $dmlogBase$dmtan$dmtanh$dmatan2GHC.Internal.Data.BoolboolGHC.Internal.Data.TuplefstsndcurryuncurryswapGHC.Internal.Data.Functor<$><&>$>voidGHC.Internal.Data.FunctionfixonGHC.Internal.Conc.SyncTVarGHC.Internal.MVarMVareitherleftsrightspartitionEithersisLeftisRightfromLeft fromRightGHC.Internal.Text.Readreads readMaybereadGHC.Internal.Data.OrdDowngetDown comparingGHC.Internal.Data.ProxyProxySomeNatNatnatVal someNatValGHC.Internal.IO.IOModeIOModeReadMode WriteMode AppendMode ReadWriteMode$GHC.Internal.Data.Semigroup.InternalAltgetAltProduct getProductSumgetSumAnygetAnyAllgetAllEndoappEndoDualgetDualstimesIdempotentstimesIdempotentMonoid stimesMonoidGHC.Internal.Data.MonoidApgetApLastgetLastFirstgetFirstfoldfoldMapfoldMap'foldrfoldl'toListnullfoldlM traverse_mapM_forM_ sequenceA_ sequence_concat concatMapfind$dmfold $dmfoldMap $dmfoldMap'$dmfoldr $dmfoldl' $dmtoList$dmnull $dmlengthGHC.Internal.Data.Functor.ConstConstgetConst Exception toException fromExceptiondisplayExceptionbacktraceDesired$dmtoException$dmfromException$dmdisplayException$dmbacktraceDesiredGHC.Internal.Data.OldList isPrefixOf intersperse intercalate transpose genericLength genericTake genericDropgenericSplitAtgenericReplicategroupinitstails subsequences permutationssortsortBysortOnunfoldrGHC.Internal.IOFilePathGHC.Internal.IORefIORef BufferMode NoBuffering LineBufferingBlockBufferingGHC.Internal.IO.StdHandlesstdoutthrowSTMcatchSTMnewTVarreadTVar writeTVarstdinstderrwithFiletraverse sequenceAmapMsequenceforM mapAccumL mapAccumR $dmtraverse $dmsequenceA$dmmapM $dmsequence callStackwithFrozenCallStackGHC.Internal.ExecutionStack getStackTraceshowStackTraceGHC.Internal.Control.Category<<<>>>filterM>=><=<forever mapAndUnzipMzipWithM zipWithM_ replicateM replicateM_unless<$!>mfilterGHC.Internal.Functor.ZipListZipList getZipList $dmfromListNGHC.Internal.ExtssortWithGHC.Internal.Control.Arrow&&&baseControl.ApplicativeoptionalData.List.NonEmptynonEmptyData.Bifoldable Bifoldablebifold bifoldMapbifoldrbifoldlbifoldr'bifoldrMbifoldl'bifoldlM bitraverse_bifor_ bisequence_biasumbiListbinullbilengthbielembiandbiorbianybiallbifind $dmbifold $dmbifoldMap $dmbifoldr $dmbifoldlData.Bitraversable Bitraversable bitraverse bisequencebifor bimapDefaultbifoldMapDefaultData.Semigroup WrappedMonoidcycle1 mtimesDefaultbytestring-0.12.1.0-d0daData.ByteString.Short.InternalData.ByteString.Internal.TypetoShort fromShortcontainers-0.7-ed0dData.Set.InternalSetData.Sequence.InternalData.Map.InternalData.IntSet.InternalIntSetData.IntMap.InternalIntMapdeepseq-1.5.0.0-748cControl.DeepSeqNFDatarnfdeepseq$!!force$dmrnftransformers-0.6.1.1-1df5Control.Monad.Trans.ExceptExceptTControl.Monad.Trans.MaybeMaybeThshbl-1.5.0.0-ff4bad37Data.Hashable.ClassHashable hashWithSalt$dmhashWithSalt runExceptTControl.Monad.Trans.ReaderReaderT runReaderTReader runReader withReader withReaderT Control.Monad.Trans.State.StrictStateT runStateTStaterunState evalState execState withState evalStateT execStateTmtl-2.3.1-6c8eControl.Monad.Reader.Class MonadReaderasklocalreaderasks$dmask $dmreaderControl.Monad.State.Class MonadStategetputstatemodifymodify'gets$dmget$dmput$dmstateControl.Monad.Trans.Identity IdentityT runIdentityTnrdrd-cntnrs-0.2.20-1956bcbbData.HashMap.InternalHashMapData.HashSet.InternalHashSetstm-2.5.3.1-4c4fControl.Concurrent.STM.TMVarTMVarnewTMVar newEmptyTMVar takeTMVar tryTakeTMVarputTMVar tryPutTMVar readTMVar tryReadTMVar swapTMVar isEmptyTMVar mkWeakTMVarControl.Concurrent.STM.TVar modifyTVar'text-2.1.1-e1e4Data.Text.Encoding.ErrorUnicodeException OnDecodeErrorOnError strictDecode lenientDecodeData.Text.InternalData.Text.EncodingdecodeUtf8With decodeUtf8' runMaybeTmaybeToExceptTexceptToMaybeTpass appliedToidentity<<$>>flap??duptoFsttoSnd fmapToFst fmapToSndmapToFstmapToSnd traverseToFst traverseToSnd traverseBothuniverseuniverseNonEmpty inverseMapatomicModifyIORef_atomicModifyIORef'_cycle?:whenJust whenJustM whenNothing whenNothing_ whenNothingM whenNothingM_ mapMaybeM usingReaderT usingReader etaReaderT usingStateT usingStateevaluatingStateTevaluatingStateexecutingStateTexecutingState hoistMaybe hoistEither maybeToMonoid memptyIfFalse memptyIfTrueordNubordNubOnhashNubsortNub unstableNubintNubintNubOnlinesunlineswordsunwords LazyStricttoLazytoStrictToStringtoStringToLTexttoLTextToTexttoText ConvertUtf8 encodeUtf8 decodeUtf8decodeUtf8Strict LByteStringLTextfromLazy fromStrict $fConvertUtf8TextShortByteString!$fConvertUtf8TextShortByteString0 $fConvertUtf8ListShortByteString$fConvertUtf8TextByteString$fConvertUtf8TextByteString0$fConvertUtf8ListByteString$fConvertUtf8TextByteString1$fConvertUtf8TextByteString2$fConvertUtf8ListByteString0 $fToTextText $fToTextText0 $fToTextList $fToLTextText$fToLTextText0 $fToLTextList$fToStringText$fToStringText0$fToStringList$fToStringShortByteString$fToStringByteString$fToStringByteString0$fToLTextShortByteString$fToLTextByteString$fToLTextByteString0$fToTextShortByteString$fToTextByteString$fToTextByteString0$fLazyStrictTextText $fLazyStrictByteStringByteStringputText putTextLnputLText putLTextLnputBSputBSLnputLBSputLBSLn readFileText writeFileTextappendFileText readFileLTextwriteFileLTextappendFileLText readFileBS writeFileBS appendFileBS readFileLBS writeFileLBS appendFileLBS Undefinedtrace traceShow traceShowId traceShowWithtraceM traceShowMtraceIderror $fEqUndefined$fOrdUndefined$fShowUndefined$fReadUndefined$fEnumUndefined$fBoundedUndefined$fDataUndefined$fGenericUndefined leftToMaybe rightToMaybe maybeToRight maybeToLeftwhenLeft whenLeft_ whenLeftM whenLeftM_ whenRight whenRight_ whenRightM whenRightM_$fMonadFailEither chainedTo infinitely viaNonEmpty whenNotNull whenNotNullMBugExcbug$fExceptionBug $fShowBug evaluateWHNF evaluateWHNF_ evaluateNF evaluateNF_whenMunlessMifMguardMguarded&&^||^integerToBoundedintegerToNaturalOneOneItemone $fOneIntSet $fOneHashSet$fOneSet $fOneIntMap $fOneHashMap$fOneMap$fOneShortByteString$fOneByteString$fOneByteString0 $fOneText $fOneText0$fOneSeq $fOneNonEmpty $fOneList!!?maybeAt partitionWith flipfoldl'asumMapfoldMapAfoldMapMandMorMallManyM DynamicMapinsert insertWithdeletealter StaticMapKeyVallookupmember!? notMember lookupDefaulttoPairskeyselems$fStaticMapIntSet$fStaticMapHashSet$fStaticMapSet$fStaticMapIntMap$fStaticMapHashMap$fStaticMapMap$fDynamicMapIntMap$fDynamicMapHashMap$fDynamicMapMapElemSndFstAllHavetypeNameunwrapunderunder2underF2#.Lens'lensviewsetover^..~%~groupBy groupOneBy Foldable1foldMap1fold1foldr1 toNonEmptyhead1last1maximum1minimum1 maximumOn1 minimumOn1foldl1'average1$fFoldable1Sum$fFoldable1Product$fFoldable1Compose$fFoldable1Tuple2$fFoldable1Identity$fFoldable1NonEmpty$fFoldable1ListfoldlSCaveragenextprev safeToEnumownName callerName bimapBothbimapFfirstFsecondFatabsurdvacuouscoerceVoidGHC.Internal.OverloadedLabelsIsLabel fromLabelEq/=== CoercibleData.Functor.Contravariant$<>$$<>$<comparisonEquivalencedefaultComparisondefaultEquivalencephantomData.Bifunctor BifunctorbimapfirstsecondData.Functor.ComposeCompose getCompose Comparison getComparison Contravariant>$ contramap EquivalencegetEquivalenceOpgetOp Predicate getPredicate"GHC.Internal.Data.Functor.IdentityIdentity runIdentityControl.Monad.IO.ClassMonadIOliftIOGHC.Internal.Control.Monad.Fail MonadFailfailControl.Monad.Trans.Class MonadTransliftIntIsText EncodingError IsNonEmpty impureThrowGHC.Internal.IntInt16Int32Int64Int8 DisallowElem IsListError