ref: d36ac13b38f5cfe3b1508cf75dee143ad113e7c2
parent: 3606a14708ac8cd1e2ffa53573c38775eee0b878
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sat Aug 17 09:38:41 EDT 2024
Some more base functionality.
--- a/lib/Data/Bool.hs
+++ b/lib/Data/Bool.hs
@@ -44,3 +44,7 @@
otherwise :: Bool
otherwise = True
+
+bool :: forall a . a -> a -> Bool -> a
+bool f _ False = f
+bool _ t True = t
--- a/lib/Data/Function.hs
+++ b/lib/Data/Function.hs
@@ -30,12 +30,6 @@
fix :: forall a . (a -> a) -> a
fix = primFix
-curry :: forall a b c . ((a, b) -> c) -> (a -> b -> c)
-curry f a b = f (a, b)
-
-uncurry :: forall a b c . (a -> b -> c) -> ((a, b) -> c)
-uncurry f (a, b) = f a b -- XXX not lazy
-
infixl 0 `on`
on :: forall a b c . (a -> a -> b) -> (c -> a) -> (c -> c -> b)
on op sel x y = op (sel x) (sel y)
@@ -50,3 +44,11 @@
until p f = rec
where
rec x = if p x then x else rec (f x)
+
+infixl 1 &
+(&) :: forall a b . a -> (a -> b) -> b
+(&) x f = f x
+
+applyWhen :: forall a . Bool -> (a -> a) -> a -> a
+applyWhen True f x = f x
+applyWhen False _ x = x
--- a/lib/Data/Tuple.hs
+++ b/lib/Data/Tuple.hs
@@ -23,11 +23,23 @@
data Solo a = MkSolo a
deriving (Eq, Ord)
+getSolo :: Solo a -> a
+getSolo (MkSolo a) = a
+
fst :: forall a b . (a, b) -> a
fst (a, _) = a
snd :: forall a b . (a, b) -> b
snd (_, b) = b
+
+curry :: forall a b c . ((a, b) -> c) -> (a -> b -> c)
+curry f a b = f (a, b)
+
+uncurry :: forall a b c . (a -> b -> c) -> ((a, b) -> c)
+uncurry f (a, b) = f a b -- XXX not lazy
+
+swap :: forall a b . (a, b) -> (b, a)
+swap (a, b) = (b, a)
-----------------------------------
--- a/lib/Prelude.hs
+++ b/lib/Prelude.hs
@@ -54,7 +54,7 @@
import Data.Float(Float)
import Data.Floating(Floating(..))
import Data.Fractional(Fractional(..), (^^))
-import Data.Function(id, const, (.), flip, ($), seq, ($!), until, curry, uncurry, asTypeOf)
+import Data.Function(id, const, (.), flip, ($), seq, ($!), until, asTypeOf)
import Data.Functor(Functor(..), (<$>))
import Data.Int(Int)
import Data.Int.Instances
@@ -78,7 +78,7 @@
import Data.Records -- XXX redo this somehow
import Data.Semigroup(Semigroup(..))
import Data.String(IsString(..), lines, unlines, words, unwords)
-import Data.Tuple(()(..), fst, snd)
+import Data.Tuple(()(..), fst, snd, curry, uncurry)
import Data.Word(Word)
import System.IO(IO, putChar, putStr, putStrLn, print, getLine, getContents, interact,
FilePath, readFile, writeFile, appendFile,
--
⑨