git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Started on hierarchy.
commit43b93bae5f4f681b8fd76ab35a1874817ad4c12b authorjoneshf <jones3.hardy@gmail.com> dateSun 13 Apr 2014, 13:31 (13 years ago) parent7cbe4f8
7 files changed+333−40
docgen/Main.hs+5 docs/source/prelude.rst+125−19 hierarchy/Main.hs+88 prelude/README.md+103−19 prelude/typeclasses.png prelude/updateDocs.sh+1 purescript.cabal+11−2
docgen/Main.hs+5
@@ -70,6 +70,8 @@ renderModule (P.Module moduleName ds exps) =
7070 spacer
7171 headerLevel 3 "Type Classes"
7272 spacer
73+ renderTypeclassImage
74+ spacer
7375 renderTopLevel exps (filter isTypeClassDeclaration exported)
7476 spacer
7577 headerLevel 3 "Type Class Instances"
@@ -108,6 +110,9 @@ renderTopLevel exps decls = forM_ (sortBy (compare `on` getName) decls) $ \decl
108110 renderDeclaration 4 exps decl
109111 spacer
110112
113+renderTypeclassImage :: Docs
114+renderTypeclassImage = tell ["![typeclasses](typeclasses.png)"]
115+
111116renderDeclaration :: Int -> Maybe [P.DeclarationRef] -> P.Declaration -> Docs
112117renderDeclaration n _ (P.TypeDeclaration ident ty) =
113118 atIndent n $ show ident ++ " :: " ++ P.prettyPrintType ty
docs/source/prelude.rst+125−19
@@ -17,16 +17,25 @@ Types
1717Type Classes
1818~~~~~~~~~~~~
1919
20+.. figure:: typeclasses.png
21+ :alt: typeclasses
22+
23+ typeclasses
2024::
2125
2226 class Alternative f where
2327 empty :: forall a. f a
2428 (<|>) :: forall a. f a -> f a -> f a
2529
26− class Applicative f where
30+ class (Apply f) <= Applicative f where
2731 pure :: forall a. a -> f a
32+
33+ class (Functor f) <= Apply f where
2834 (<*>) :: forall a b. f (a -> b) -> f a -> f b
2935
36+ class (Apply m) <= Bind m where
37+ (>>=) :: forall a b. m a -> (a -> m b) -> m b
38+
3039 class Bits b where
3140 (&) :: b -> b -> b
3241 (|) :: b -> b -> b
@@ -41,9 +50,8 @@ Type Classes
4150 (||) :: b -> b -> b
4251 not :: b -> b
4352
44− class Category a where
53+ class (Semigroupoid a) <= Category a where
4554 id :: forall t. a t t
46− (<<<) :: forall b c d. a c d -> a b c -> a b d
4755
4856 class Eq a where
4957 (==) :: a -> a -> Prim.Boolean
@@ -52,9 +60,7 @@ Type Classes
5260 class Functor f where
5361 (<$>) :: forall a b. (a -> b) -> f a -> f b
5462
55− class Monad m where
56− return :: forall a. a -> m a
57− (>>=) :: forall a b. m a -> (a -> m b) -> m b
63+ class (Applicative m, Bind m) <= Monad m where
5864
5965 class Num a where
6066 (+) :: a -> a -> a
@@ -64,9 +70,15 @@ Type Classes
6470 (%) :: a -> a -> a
6571 negate :: a -> a
6672
67− class Ord a where
73+ class (Eq a) <= Ord a where
6874 compare :: a -> a -> Ordering
6975
76+ class Semigroup a where
77+ (<>) :: a -> a -> a
78+
79+ class Semigroupoid a where
80+ (<<<) :: forall b c d. a c d -> a b c -> a b d
81+
7082 class Show a where
7183 show :: a -> Prim.String
7284
@@ -75,8 +87,6 @@ Type Class Instances
7587
7688::
7789
78− instance applicativeFromMonad :: (Monad m) => Applicative m
79−
8090 instance bitsNumber :: Bits Prim.Number
8191
8292 instance boolLikeBoolean :: BoolLike Prim.Boolean
@@ -89,14 +99,20 @@ Type Class Instances
8999
90100 instance eqNumber :: Eq Prim.Number
91101
92− instance eqString :: Eq Prim.String
102+ instance eqOrdering :: Eq Ordering
93103
94− instance functorFromApplicative :: (Applicative f) => Functor f
104+ instance eqString :: Eq Prim.String
95105
96106 instance numNumber :: Num Prim.Number
97107
98108 instance ordNumber :: Ord Prim.Number
99109
110+ instance semigroupString :: Semigroup Prim.String
111+
112+ instance semigroupoidArr :: Semigroupoid Prim.Function
113+
114+ instance showArray :: (Show a) => Show [a]
115+
100116 instance showBoolean :: Show Prim.Boolean
101117
102118 instance showNumber :: Show Prim.Number
@@ -110,13 +126,13 @@ Values
110126
111127::
112128
113− (!!) :: forall a. [a] -> Prim.Number -> a
114−
115129 (#) :: forall a b. a -> (a -> b) -> b
116130
117131 ($) :: forall a b. (a -> b) -> a -> b
118132
119− (++) :: Prim.String -> Prim.String -> Prim.String
133+ (++) :: forall s. (Semigroup s) => s -> s -> s
134+
135+ (:) :: forall a. a -> [a] -> [a]
120136
121137 (<) :: forall a. (Ord a) => a -> a -> Prim.Boolean
122138
@@ -126,7 +142,11 @@ Values
126142
127143 (>=) :: forall a. (Ord a) => a -> a -> Prim.Boolean
128144
129− (>>>) :: forall a b c d. (Category a) => a b c -> a c d -> a b d
145+ (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
146+
147+ ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
148+
149+ asTypeOf :: forall a. a -> a -> a
130150
131151 boolAnd :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
132152
@@ -134,10 +154,18 @@ Values
134154
135155 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
136156
157+ concatString :: Prim.String -> Prim.String -> Prim.String
158+
159+ cons :: forall a. a -> [a] -> [a]
160+
137161 const :: forall a b. a -> b -> a
138162
139163 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
140164
165+ liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
166+
167+ liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
168+
141169 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
142170
143171 numAnd :: Prim.Number -> Prim.Number -> Prim.Number
@@ -166,14 +194,41 @@ Values
166194
167195 numZshr :: Prim.Number -> Prim.Number -> Prim.Number
168196
169− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
170−
171197 refEq :: forall a. a -> a -> Prim.Boolean
172198
173199 refIneq :: forall a. a -> a -> Prim.Boolean
174200
201+ return :: forall m a. (Monad m) => a -> m a
202+
203+ showArrayImpl :: forall a. (a -> Prim.String) -> [a] -> Prim.String
204+
175205 showNumberImpl :: Prim.Number -> Prim.String
176206
207+ showStringImpl :: Prim.String -> Prim.String
208+
209+Module Data.Function
210+--------------------
211+
212+Types
213+~~~~~
214+
215+Type Classes
216+~~~~~~~~~~~~
217+
218+.. figure:: typeclasses.png
219+ :alt: typeclasses
220+
221+ typeclasses
222+Type Class Instances
223+~~~~~~~~~~~~~~~~~~~~
224+
225+Values
226+~~~~~~
227+
228+::
229+
230+ on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
231+
177232Module Data.Eq
178233--------------
179234
@@ -188,6 +243,10 @@ Types
188243Type Classes
189244~~~~~~~~~~~~
190245
246+.. figure:: typeclasses.png
247+ :alt: typeclasses
248+
249+ typeclasses
191250Type Class Instances
192251~~~~~~~~~~~~~~~~~~~~
193252
@@ -202,6 +261,29 @@ Values
202261
203262 liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
204263
264+Module Prelude.Unsafe
265+---------------------
266+
267+Types
268+~~~~~
269+
270+Type Classes
271+~~~~~~~~~~~~
272+
273+.. figure:: typeclasses.png
274+ :alt: typeclasses
275+
276+ typeclasses
277+Type Class Instances
278+~~~~~~~~~~~~~~~~~~~~
279+
280+Values
281+~~~~~~
282+
283+::
284+
285+ unsafeIndex :: forall a. [a] -> Prim.Number -> a
286+
205287Module Control.Monad.Eff
206288------------------------
207289
@@ -217,11 +299,23 @@ Types
217299Type Classes
218300~~~~~~~~~~~~
219301
302+.. figure:: typeclasses.png
303+ :alt: typeclasses
304+
305+ typeclasses
220306Type Class Instances
221307~~~~~~~~~~~~~~~~~~~~
222308
223309::
224310
311+ instance applicativeEff :: Applicative (Eff e)
312+
313+ instance applyEff :: Apply (Eff e)
314+
315+ instance bindEff :: Bind (Eff e)
316+
317+ instance functorEff :: Functor (Eff e)
318+
225319 instance monadEff :: Monad (Eff e)
226320
227321Values
@@ -229,13 +323,13 @@ Values
229323
230324::
231325
232− bindEff :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
326+ bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
233327
234328 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
235329
236330 foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
237331
238− retEff :: forall e a. a -> Eff e a
332+ returnE :: forall e a. a -> Eff e a
239333
240334 runPure :: forall a. Pure a -> a
241335
@@ -252,6 +346,10 @@ Types
252346Type Classes
253347~~~~~~~~~~~~
254348
349+.. figure:: typeclasses.png
350+ :alt: typeclasses
351+
352+ typeclasses
255353Type Class Instances
256354~~~~~~~~~~~~~~~~~~~~
257355
@@ -275,6 +373,10 @@ Types
275373Type Classes
276374~~~~~~~~~~~~
277375
376+.. figure:: typeclasses.png
377+ :alt: typeclasses
378+
379+ typeclasses
278380Type Class Instances
279381~~~~~~~~~~~~~~~~~~~~
280382
@@ -304,6 +406,10 @@ Types
304406Type Classes
305407~~~~~~~~~~~~
306408
409+.. figure:: typeclasses.png
410+ :alt: typeclasses
411+
412+ typeclasses
307413Type Class Instances
308414~~~~~~~~~~~~~~~~~~~~
309415
hierarchy/Main.hsnew file+88
@@ -0,0 +1,88 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Main
4+-- Copyright : (c) Phil Freeman 2014
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- |
12+-- Generate Directed Graphs of PureScript TypeClasses
13+--
14+-----------------------------------------------------------------------------
15+
16+module Main where
17+
18+import Control.Applicative ((<*>), (<$>))
19+
20+import Data.List (intercalate,nub,sort)
21+import Data.Version (showVersion)
22+
23+import System.Console.CmdTheLine
24+import System.Exit (exitFailure, exitSuccess)
25+
26+import Text.Parsec (ParseError)
27+
28+import qualified Language.PureScript as P
29+import qualified Paths_purescript as Paths
30+import qualified System.IO.UTF8 as U
31+
32+newtype SuperMap = SuperMap { unSuperMap :: Either P.ProperName (P.ProperName, P.ProperName) }
33+ deriving Eq
34+
35+instance Show SuperMap where
36+ show (SuperMap (Left sub)) = show sub
37+ show (SuperMap (Right (super, sub))) = show super ++ " -> " ++ show sub
38+
39+instance Ord SuperMap where
40+ compare (SuperMap s) (SuperMap s') = getCls s `compare` getCls s'
41+ where
42+ getCls = either id snd
43+
44+readInput :: FilePath -> IO (Either ParseError [P.Module])
45+readInput p = do
46+ text <- U.readFile p
47+ return $ P.runIndentParser p P.parseModules text
48+
49+compile :: FilePath -> Maybe FilePath -> IO ()
50+compile input mOutput = do
51+ modules <- readInput input
52+ case modules of
53+ Left err -> U.print err >> exitFailure
54+ Right (P.Module _ decls _ : _) -> do
55+ let tcs = filter P.isTypeClassDeclaration decls
56+ let supers = sort . nub . filter (not . null) $ fmap superClasses tcs
57+ let hier = "digraph Prelude {\n" ++ intercalate "\n" (concatMap (fmap ((" " ++) . (++ ";") . show)) supers) ++ "\n}"
58+ case mOutput of
59+ Just output -> U.writeFile output hier
60+ Nothing -> U.putStrLn hier
61+ exitSuccess
62+
63+superClasses :: P.Declaration -> [SuperMap]
64+superClasses (P.TypeClassDeclaration sub _ supers@(_:_) _) =
65+ fmap (\(P.Qualified _ super, _) -> SuperMap (Right (super, sub))) supers
66+superClasses (P.TypeClassDeclaration sub _ _ _) = [SuperMap (Left sub)]
67+superClasses (P.PositionedDeclaration _ decl) = superClasses decl
68+superClasses _ = []
69+
70+outputFile :: Term (Maybe FilePath)
71+outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
72+ { optDoc = "The output file" }
73+
74+inputFile :: Term FilePath
75+inputFile = value $ pos 0 "main.purs" $ posInfo { posDoc = "The input file to generate a hierarchy from" }
76+
77+term :: Term (IO ())
78+term = compile <$> inputFile <*> outputFile
79+
80+termInfo :: TermInfo
81+termInfo = defTI
82+ { termName = "hierarchy"
83+ , version = showVersion Paths.version
84+ , termDoc = "Creates a GraphViz directed graph of PureScript TypeClasses"
85+ }
86+
87+main :: IO ()
88+main = run (term, termInfo)
prelude/README.md+103−19
@@ -11,14 +11,21 @@
1111
1212### Type Classes
1313
14+![typeclasses](typeclasses.png)
15+
1416 class Alternative f where
1517 empty :: forall a. f a
1618 (<|>) :: forall a. f a -> f a -> f a
1719
18− class Applicative f where
20+ class (Apply f) <= Applicative f where
1921 pure :: forall a. a -> f a
22+
23+ class (Functor f) <= Apply f where
2024 (<*>) :: forall a b. f (a -> b) -> f a -> f b
2125
26+ class (Apply m) <= Bind m where
27+ (>>=) :: forall a b. m a -> (a -> m b) -> m b
28+
2229 class Bits b where
2330 (&) :: b -> b -> b
2431 (|) :: b -> b -> b
@@ -33,9 +40,8 @@
3340 (||) :: b -> b -> b
3441 not :: b -> b
3542
36− class Category a where
43+ class (Semigroupoid a) <= Category a where
3744 id :: forall t. a t t
38− (<<<) :: forall b c d. a c d -> a b c -> a b d
3945
4046 class Eq a where
4147 (==) :: a -> a -> Prim.Boolean
@@ -44,9 +50,7 @@
4450 class Functor f where
4551 (<$>) :: forall a b. (a -> b) -> f a -> f b
4652
47− class Monad m where
48− return :: forall a. a -> m a
49− (>>=) :: forall a b. m a -> (a -> m b) -> m b
53+ class (Applicative m, Bind m) <= Monad m where
5054
5155 class Num a where
5256 (+) :: a -> a -> a
@@ -56,17 +60,21 @@
5660 (%) :: a -> a -> a
5761 negate :: a -> a
5862
59− class Ord a where
63+ class (Eq a) <= Ord a where
6064 compare :: a -> a -> Ordering
6165
66+ class Semigroup a where
67+ (<>) :: a -> a -> a
68+
69+ class Semigroupoid a where
70+ (<<<) :: forall b c d. a c d -> a b c -> a b d
71+
6272 class Show a where
6373 show :: a -> Prim.String
6474
6575
6676### Type Class Instances
6777
68− instance applicativeFromMonad :: (Monad m) => Applicative m
69−
7078 instance bitsNumber :: Bits Prim.Number
7179
7280 instance boolLikeBoolean :: BoolLike Prim.Boolean
@@ -79,14 +87,20 @@
7987
8088 instance eqNumber :: Eq Prim.Number
8189
82− instance eqString :: Eq Prim.String
90+ instance eqOrdering :: Eq Ordering
8391
84− instance functorFromApplicative :: (Applicative f) => Functor f
92+ instance eqString :: Eq Prim.String
8593
8694 instance numNumber :: Num Prim.Number
8795
8896 instance ordNumber :: Ord Prim.Number
8997
98+ instance semigroupString :: Semigroup Prim.String
99+
100+ instance semigroupoidArr :: Semigroupoid Prim.Function
101+
102+ instance showArray :: (Show a) => Show [a]
103+
90104 instance showBoolean :: Show Prim.Boolean
91105
92106 instance showNumber :: Show Prim.Number
@@ -98,13 +112,13 @@
98112
99113### Values
100114
101− (!!) :: forall a. [a] -> Prim.Number -> a
102−
103115 (#) :: forall a b. a -> (a -> b) -> b
104116
105117 ($) :: forall a b. (a -> b) -> a -> b
106118
107− (++) :: Prim.String -> Prim.String -> Prim.String
119+ (++) :: forall s. (Semigroup s) => s -> s -> s
120+
121+ (:) :: forall a. a -> [a] -> [a]
108122
109123 (<) :: forall a. (Ord a) => a -> a -> Prim.Boolean
110124
@@ -114,7 +128,11 @@
114128
115129 (>=) :: forall a. (Ord a) => a -> a -> Prim.Boolean
116130
117− (>>>) :: forall a b c d. (Category a) => a b c -> a c d -> a b d
131+ (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
132+
133+ ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
134+
135+ asTypeOf :: forall a. a -> a -> a
118136
119137 boolAnd :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
120138
@@ -122,10 +140,18 @@
122140
123141 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
124142
143+ concatString :: Prim.String -> Prim.String -> Prim.String
144+
145+ cons :: forall a. a -> [a] -> [a]
146+
125147 const :: forall a b. a -> b -> a
126148
127149 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
128150
151+ liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
152+
153+ liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
154+
129155 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
130156
131157 numAnd :: Prim.Number -> Prim.Number -> Prim.Number
@@ -154,14 +180,36 @@
154180
155181 numZshr :: Prim.Number -> Prim.Number -> Prim.Number
156182
157− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
158−
159183 refEq :: forall a. a -> a -> Prim.Boolean
160184
161185 refIneq :: forall a. a -> a -> Prim.Boolean
162186
187+ return :: forall m a. (Monad m) => a -> m a
188+
189+ showArrayImpl :: forall a. (a -> Prim.String) -> [a] -> Prim.String
190+
163191 showNumberImpl :: Prim.Number -> Prim.String
164192
193+ showStringImpl :: Prim.String -> Prim.String
194+
195+
196+## Module Data.Function
197+
198+### Types
199+
200+
201+### Type Classes
202+
203+![typeclasses](typeclasses.png)
204+
205+
206+### Type Class Instances
207+
208+
209+### Values
210+
211+ on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
212+
165213
166214## Module Data.Eq
167215
@@ -173,6 +221,8 @@
173221
174222### Type Classes
175223
224+![typeclasses](typeclasses.png)
225+
176226
177227### Type Class Instances
178228
@@ -184,6 +234,24 @@
184234 liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
185235
186236
237+## Module Prelude.Unsafe
238+
239+### Types
240+
241+
242+### Type Classes
243+
244+![typeclasses](typeclasses.png)
245+
246+
247+### Type Class Instances
248+
249+
250+### Values
251+
252+ unsafeIndex :: forall a. [a] -> Prim.Number -> a
253+
254+
187255## Module Control.Monad.Eff
188256
189257### Types
@@ -195,21 +263,31 @@
195263
196264### Type Classes
197265
266+![typeclasses](typeclasses.png)
267+
198268
199269### Type Class Instances
200270
271+ instance applicativeEff :: Applicative (Eff e)
272+
273+ instance applyEff :: Apply (Eff e)
274+
275+ instance bindEff :: Bind (Eff e)
276+
277+ instance functorEff :: Functor (Eff e)
278+
201279 instance monadEff :: Monad (Eff e)
202280
203281
204282### Values
205283
206− bindEff :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
284+ bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
207285
208286 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
209287
210288 foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
211289
212− retEff :: forall e a. a -> Eff e a
290+ returnE :: forall e a. a -> Eff e a
213291
214292 runPure :: forall a. Pure a -> a
215293
@@ -225,6 +303,8 @@
225303
226304### Type Classes
227305
306+![typeclasses](typeclasses.png)
307+
228308
229309### Type Class Instances
230310
@@ -243,6 +323,8 @@
243323
244324### Type Classes
245325
326+![typeclasses](typeclasses.png)
327+
246328
247329### Type Class Instances
248330
@@ -267,6 +349,8 @@
267349
268350### Type Classes
269351
352+![typeclasses](typeclasses.png)
353+
270354
271355### Type Class Instances
272356
prelude/typeclasses.pngnew file

Binary file not shown.

prelude/updateDocs.sh+1
@@ -1,2 +1,3 @@
11../dist/build/docgen/docgen prelude.purs > README.md
2+../dist/build/hierarchy/hierarchy prelude.purs | dot -Tpng -o typeclasses.png
23pandoc -o ../docs/source/prelude.rst README.md
purescript.cabal+11−2
@@ -20,8 +20,8 @@ data-dir: ""
2020library
2121 build-depends: base >=4 && <5, cmdtheline -any, containers -any,
2222 directory >= 1.2, filepath -any, mtl -any, parsec -any, syb >= 0.4.1 && < 0.5,
23− transformers -any, utf8-string -any,
24− pattern-arrows >= 0.0.2 && < 0.1,
23+ transformers -any, utf8-string -any,
24+ pattern-arrows >= 0.0.2 && < 0.1,
2525 monad-unify >= 0.2.1 && < 0.3,
2626 xdg-basedir -any, time -any
2727 if (!os(windows))
@@ -125,6 +125,15 @@ executable docgen
125125 other-modules:
126126 ghc-options: -Wall -O2
127127
128+executable hierarchy
129+ build-depends: base >=4 && <5, cmdtheline -any, purescript -any, utf8-string -any,
130+ process -any, mtl -any, parsec -any
131+ main-is: Main.hs
132+ buildable: True
133+ hs-source-dirs: hierarchy
134+ other-modules:
135+ ghc-options: -Wall -O2
136+
128137test-suite tests
129138 build-depends: base >=4 && <5, containers -any, directory -any,
130139 filepath -any, mtl -any, parsec -any, purescript -any, syb >= 0.4.1 && < 0.5,