on master help sign in
Type-safe identifiers in haddocks
d3f15b1Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+2−2
@@ -53,7 +53,7 @@
53-- This illustration can help us understand the type signature of 'require'.
53-- This illustration can help us understand the type signature of 'require'.
54--
54--
55-- > require :: (Binary a, Typeable a, Writable a)
55-- > require :: (Binary a, Typeable a, Writable a)
56−-- > => Identifier
56+-- > => Identifier a
57-- > -> (b -> a -> c)
57-- > -> (b -> a -> c)
58-- > -> Compiler b c
58-- > -> Compiler b c
59--
59--
@@ -64,7 +64,7 @@
64-- These are constraints for the @a@ type. @a@ (the template) needs to have
64-- These are constraints for the @a@ type. @a@ (the template) needs to have
65-- certain properties for it to be required.
65-- certain properties for it to be required.
66--
66--
67−-- > Identifier
67+-- > Identifier a
68--
68--
69-- This is simply @templates/fancy.html@: the 'Identifier' of the item we want
69-- This is simply @templates/fancy.html@: the 'Identifier' of the item we want
70-- to 'require', in other words, the name of the item we want to add to the
70-- to 'require', in other words, the name of the item we want to add to the
src/Hakyll/Core/Identifier.hs+9−6
@@ -20,6 +20,15 @@
20-- @posts/foo.html@. In this case, the identifier is the name of the source
20-- @posts/foo.html@. In this case, the identifier is the name of the source
21-- file of the page.
21-- file of the page.
22--
22--
23+-- An `Identifier` carries the type of the value it identifies. This basically
24+-- means that an @Identifier (Page String)@ refers to a page.
25+--
26+-- It is a phantom type parameter, meaning you can safely change this if you
27+-- know what you are doing. You can change the type using the 'castIdentifier'
28+-- function.
29+--
30+-- If the @a@ type is not known, Hakyll traditionally uses @Identifier ()@.
31+--
23{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
32{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
24module Hakyll.Core.Identifier
33module Hakyll.Core.Identifier
25 ( Identifier (..)
34 ( Identifier (..)
@@ -41,12 +50,6 @@ import Data.Typeable (Typeable)
41
50
42-- | An identifier used to uniquely identify a value
51-- | An identifier used to uniquely identify a value
43--
52--
44−-- The @a@ is used to denote the type that the identifier points to. It is a
45−-- phantom type parameter, meaning you can safely change this if you know what
46−-- you are doing.
47−--
48−-- If the @a@ type is not known, Hakyll traditionally uses @Identifier ()@.
49−--
50data Identifier a = Identifier
53data Identifier a = Identifier
51 { identifierGroup :: Maybe String
54 { identifierGroup :: Maybe String
52 , identifierPath :: String
55 , identifierPath :: String
src/Hakyll/Core/Identifier/Pattern.hs+4
@@ -31,6 +31,10 @@
31-- The 'capture' function allows the user to get access to the elements captured
31-- The 'capture' function allows the user to get access to the elements captured
32-- by the capture elements in the pattern.
32-- by the capture elements in the pattern.
33--
33--
34+-- Like an 'Identifier', a 'Pattern' also has a type parameter. This is simply
35+-- an extra layer of safety, and can be discarded using the 'castPattern'
36+-- function.
37+--
34module Hakyll.Core.Identifier.Pattern
38module Hakyll.Core.Identifier.Pattern
35 ( Pattern
39 ( Pattern
36 , castPattern
40 , castPattern