This commit is contained in:
Stephen Diehl
2016-07-29 12:07:32 -04:00
parent 4437583e3f
commit 5de8f47138
5 changed files with 298 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
Applicative
===========
#### Functor
```haskell
class Functor (f :: * -> *) where
fmap :: (a -> b) -> f a -> f b
(<$) :: a -> f b -> f a
```
```haskell
(<$>) :: Functor f => (a -> b) -> f a -> f b
```
```haskell
($>) :: Functor f => f a -> b -> f b
```
#### Applicatives
```haskell
class Functor f => Applicative (f :: * -> *) where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: f a -> f b -> f b
(<*) :: f a -> f b -> f a
```
```haskell
(<$>) :: Functor f => (a -> b) -> f a -> f b
```
```haskell
orAlt :: (Alternative f, Monoid a) => f a -> f a
```
```haskell
orEmpty :: Alternative f => Bool -> a -> f a
```
```haskell
eitherA :: (Alternative f) => f a -> f b -> f (Either a b)
```
#### Alternative
```haskell
class Applicative f => Alternative (f :: * -> *) where
empty :: f a
(<|>) :: f a -> f a -> f a
some :: f a -> f [a]
many :: f a -> f [a]
```
```haskell
(<|>) :: Alternative f => f a -> f a -> f a
```
```haskell
many :: Alternative f => f a -> f [a]
```
```haskell
some :: Alternative f => f a -> f [a]
```
```haskell
optional :: Alternative f => f a -> f (Maybe a)
```
```haskell
liftA :: Applicative f => (a -> b) -> f a -> f b
```
```haskell
empty :: Alternative f => f a
```
+62
View File
@@ -0,0 +1,62 @@
Exception Handling
==================
#### MonadError
```haskell
class Monad m => MonadError e (m :: * -> *) | m -> e where
throwError :: e -> m a
catchError :: m a -> (e -> m a) -> m a
```
```haskell
type Except e = ExceptT e Identity
```
```haskell
newtype ExceptT e (m :: * -> *) a
= Control.Monad.Trans.Except.ExceptT (m (Either e a))
```
```haskell
throwError :: MonadError e m => e -> m a
```
```haskell
catchError :: MonadError e m => m a -> (e -> m a) -> m a
```
```haskell
runExcept :: Except e a -> Either e a
```
```haskell
runExceptT :: ExceptT e m a -> m (Either e a)
```
#### Exceptions
```haskell
class (Typeable e, Show e) => Exception e where
toException :: e -> SomeException
fromException :: SomeException -> Maybe e
GHC.Exception.displayException :: e -> String
```
```haskell
throwIO :: (MonadIO m, Exception e) => e -> m a
```
```haskell
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
```
```haskell
throwSTM :: Exception e => e -> STM a
```
```haskell
throwError :: MonadError e m => e -> m a
```
+50
View File
@@ -0,0 +1,50 @@
Functions
=========
```haskell
($) :: (a -> b) -> a -> b
```
```haskell
(&) :: a -> (a -> b) -> b
```
```haskell
(.) :: (b -> c) -> (a -> b) -> a -> c
```
```haskell
flip :: (a -> b -> c) -> b -> a -> c
```
```haskell
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
```
```haskell
const :: a -> b -> a
```
```haskell
fix :: (a -> a) -> a
```
```haskell
($!) :: (a -> b) -> a -> b
```
```haskell
identity :: a -> a
```
```haskell
($!!) :: NFData a => (a -> b) -> a -> b
```
```haskell
($!!) :: NFData a => (a -> b) -> a -> b
```
```haskell
force :: NFData a => a -> a
```
+8
View File
@@ -1,3 +1,11 @@
Welcome to project documentation.
- [Functions](Function.md)
- [Functors](Applicative.md)
- [Monad](Monad.md)
- [Maybe](Maybe.md)
- [Lists](List.md)
- [Folds](Folds.md)
- [Dictionaries](Map.md)
- [Sets](Set.md)
- [Exception Handling](Exceptions.md)
+100
View File
@@ -0,0 +1,100 @@
List
====
#### Slicing
```haskell
head :: Foldable f => f a -> Maybe a
```
```haskell
tailMay :: [a] -> Maybe [a]
```
```haskell
tailSafe :: [a] -> [a]
```
```haskell
initMay :: [a] -> Maybe [a]
```
```haskell
initSafe :: [a] -> [a]
```
```haskell
initDef :: [a] -> [a] -> [a]
```
```haskell
lastMay :: [a] -> Maybe a
```
```haskell
lastDef :: a -> [a] -> a
```
```haskell
list :: [b] -> (a -> b) -> [a] -> [b]
```
```haskell
drop :: Int -> [a] -> [a]
```
```haskell
take :: Int -> [a] -> [a]
```
#### Unpacking
```haskell
uncons :: [a] -> Maybe (a, [a])
```
```haskell
unsnoc :: [x] -> Maybe ([x],x)
```
#### Sorting
```haskell
sortOn :: Ord o => (a -> o) -> [a] -> [a]
```
#### Removing
```haskell
ordNub :: Ord a => [a] -> [a]
```
#### Splitting
```haskell
splitAt :: Int -> [a] -> ([a], [a])
```
```haskell
splitAt :: Int -> [a] -> ([a], [a])
```
```haskell
intercalate :: [a] -> [[a]] -> [a]
```
#### Comparison
```haskell
isPrefixOf :: Eq a => [a] -> [a] -> Bool
```
#### Filter
```haskell
filter :: (a -> Bool) -> [a] -> [a]
```
```haskell
replicate :: Int -> a -> [a]
```