vault backup: 2025-02-04 12:03:53
This commit is contained in:
50
Functional Programming/Eq and Num.md
Normal file
50
Functional Programming/Eq and Num.md
Normal file
@ -0,0 +1,50 @@
|
||||
```haskell
|
||||
add :: (Int -> Int) -> Int
|
||||
add x y = x+y
|
||||
|
||||
instance Eq Bool where
|
||||
True == True = True
|
||||
False == False = True
|
||||
_ == _ = False
|
||||
|
||||
instance (Eq a, Eq b) => Eq (a, b) where
|
||||
(x1, y1) == (x2, y2) = x1 == x2 && y1 == y2
|
||||
|
||||
-- A value that exists
|
||||
myValue :: Maybe Int
|
||||
myValue = Just 42
|
||||
|
||||
-- A value that doesn't exist
|
||||
noValue :: Maybe Int
|
||||
noValue = Nothing
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
|
||||
class Number:
|
||||
# Some implementation
|
||||
|
||||
class Float(Number):
|
||||
# Some implentation
|
||||
|
||||
class Integer(Number):
|
||||
# Some implementation
|
||||
|
||||
|
||||
def add(numA:Number, numB:Number) -> Number:
|
||||
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
|
||||
class MyClass:
|
||||
def __eq__(self):
|
||||
# MyClass :: Eq
|
||||
def __str__(self)
|
||||
# MyClass :: Show
|
||||
def __
|
||||
```
|
Reference in New Issue
Block a user