| 1 |
% Blue Blistering Barnacles!
|
| 2 |
% Getty Ritter
|
| 3 |
|
| 4 |
The basic idea of `blue-blistering-barnacles` is that, when looking
|
| 5 |
at documentation in a language like Haskell, you have two questions
|
| 6 |
about a type:
|
| 7 |
|
| 8 |
- How can I create it?
|
| 9 |
- What can I do with it?
|
| 10 |
|
| 11 |
Therefore, BBB will ignore the traditional Haddock structure and
|
| 12 |
spit out documentation that will have a page _for each type_ `T`. Each
|
| 13 |
page will have two sections: **Creating** and **Using**. The
|
| 14 |
**Creating** section will contain
|
| 15 |
- All constructors for `T`
|
| 16 |
- All defined values of type `T`
|
| 17 |
- All functions whose return value contains `T`
|
| 18 |
|
| 19 |
On the other hand, the **Using** section will contain
|
| 20 |
- All other functions that take a `T`, even if they appeared
|
| 21 |
in the above section
|
| 22 |
|
| 23 |
Both of these include _instances of typeclasses specialized
|
| 24 |
to `T`_, as well, but maybe hidden behind JavaScript. (TBD:
|
| 25 |
whether to _also_ include every function written in terms
|
| 26 |
of that typeclass.) So, given a source file like
|
| 27 |
|
| 28 |
```{.haskell}
|
| 29 |
module Sample(S(..), T(..), flip, mkT, sumT, zero) where
|
| 30 |
|
| 31 |
newtype S = S { fromS :: Int } deriving (Eq, Show)
|
| 32 |
|
| 33 |
instance Monoid S where
|
| 34 |
mempty = S 0
|
| 35 |
mappend (S x) (S y) = S (x + y)
|
| 36 |
|
| 37 |
zero :: S
|
| 38 |
zero = S 0
|
| 39 |
|
| 40 |
data T = Leaf S | Node T T | Nil deriving (Show)
|
| 41 |
|
| 42 |
mkT :: [Int] -> T
|
| 43 |
mkT [] = Nil
|
| 44 |
mkT [x] = Leaf (S x)
|
| 45 |
mkT (x:xs) = Node (Leaf (S x)) (mkT xs)
|
| 46 |
|
| 47 |
sumT :: T -> Int
|
| 48 |
sumT Nil = 0
|
| 49 |
sumT (Leaf (S x)) = x
|
| 50 |
sumT (Node l r) = sum l + sum r
|
| 51 |
|
| 52 |
flip :: T -> T
|
| 53 |
flip (Leaf s) = Leaf s
|
| 54 |
flip (Node l r) = Node (flip l) (flip r)
|
| 55 |
```
|
| 56 |
|
| 57 |
will produce two pages:
|
| 58 |
|
| 59 |
## newtype S :: *
|
| 60 |
|
| 61 |
### Creating
|
| 62 |
- _constructor_ `S { fromS :: Int }`
|
| 63 |
- _value_ `zero :: S`
|
| 64 |
- _typeclass instance_ `Monoid S` _where_
|
| 65 |
- _value_ `mempty :: S`
|
| 66 |
- _function_ `mappend :: S -> S -> S`
|
| 67 |
|
| 68 |
### Using
|
| 69 |
- _record field_ `fromS :: S -> Int`
|
| 70 |
- _typeclass instance_ `Monoid S` _where_
|
| 71 |
- _function_ `mappend :: S -> S -> S`
|
| 72 |
- _typeclass instance_ `Eq S` _where_
|
| 73 |
- _function_ `(==) :: S -> S -> Bool`
|
| 74 |
- _function_ `(/=) :: S -> S -> Bool`
|
| 75 |
- _typeclass instance_ `Show S` _where_
|
| 76 |
- _function_ `showsPrec :: Int -> S -> ShowS`
|
| 77 |
- _function_ `show :: S -> String`
|
| 78 |
- _function_ `showList :: [S] -> ShowS`
|
| 79 |
|
| 80 |
## data T :: *
|
| 81 |
|
| 82 |
### Creating
|
| 83 |
- _constructor_ `Leaf :: S -> T`
|
| 84 |
- _constructor_ `Node :: T -> T -> T`
|
| 85 |
- _function_ `mkT :: [Int] -> T`
|
| 86 |
- _function_ `flip :: T -> T`
|
| 87 |
|
| 88 |
### Using
|
| 89 |
- _function_ `flip :: T -> T`
|
| 90 |
- _function_ `sumT :: T -> Int`
|
| 91 |
- _typeclass instance_ `Show T` _where_
|
| 92 |
- _function_ `showsPrec :: Int -> T -> ShowS`
|
| 93 |
- _function_ `show :: T -> String`
|
| 94 |
- _function_ `showList :: [T] -> ShowS`
|
| 95 |
|
| 96 |
We also want to have pages for typeclasses, with typeclass
|
| 97 |
methods in one section, and functions and values that make
|
| 98 |
use of that typeclass in another section, e.g.
|
| 99 |
|
| 100 |
## class Show a
|
| 101 |
|
| 102 |
### Methods
|
| 103 |
- _function_ `showsPrec :: Int -> a -> ShowS`
|
| 104 |
- _function_ `show :: a -> String`
|
| 105 |
- _function_ `showList :: [a] -> String`
|
| 106 |
|
| 107 |
### Functions
|
| 108 |
- _function_ `print :: Show a => a -> IO ()`
|
| 109 |
|
| 110 |
and so forth.
|
| 111 |
|
| 112 |
In generating HTML + JS, we can use fragment identifiers to
|
| 113 |
indicate that a typeclass should also be monomorphized to a
|
| 114 |
particular type, too, e.g. visiting `show.html` might give
|
| 115 |
you the docs you see above, but visiting
|
| 116 |
`show.html#subst_a:Bool` would execute some JavaScript that
|
| 117 |
would change the above to
|
| 118 |
|
| 119 |
|
| 120 |
## instance Show Bool
|
| 121 |
|
| 122 |
### Methods
|
| 123 |
- _function_ `showsPrec :: Int -> Bool -> ShowS`
|
| 124 |
- _function_ `show :: Bool -> String`
|
| 125 |
- _function_ `showList :: [Bool] -> String`
|
| 126 |
|
| 127 |
### Functions
|
| 128 |
- _function_ `print :: Bool -> IO ()`
|