on master help sign in
cosmetic / add strictness to Canonical module names

Mostly just clean up indentation and add headers though.

commit79dee76455fa665bd88de92696642b74cf8d7814 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 23 Mar 2017, 17:52 (10 years ago) parent6b5b33c
1 file changed+34−7
src/AST/Module/Name.hs+34−7
src/AST/Module/Name.hs+34−7
@@ -1,6 +1,13 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module AST.Module.Name where
3+module AST.Module.Name
4+ ( Raw
5+ , Canonical(..)
6+ , inVirtualDom, inCore, inHtml
7+ , toString, toText, canonicalToText
8+ , isNative, canonicalIsNative
9+ )
10+ where
411
512import Data.Binary
613import qualified Data.Text as Text
@@ -9,17 +16,25 @@ import Data.Text (Text)
916import qualified Elm.Package as Package
1017
1118
19+
20+-- NAMES
21+
22+
1223type Raw = Text -- must be non-empty
1324
1425
1526data Canonical =
1627 Canonical
17− { _package :: Package.Name
18− , _module :: Raw
28+ { _package :: !Package.Name
29+ , _module :: !Raw
1930 }
2031 deriving (Eq, Ord)
2132
2233
34+
35+-- HELPERS
36+
37+
2338inVirtualDom :: Raw -> Canonical
2439inVirtualDom raw =
2540 Canonical Package.virtualDom raw
@@ -35,6 +50,10 @@ inHtml raw =
3550 Canonical Package.html raw
3651
3752
53+
54+-- CONVERSIONS
55+
56+
3857toString :: Raw -> String
3958toString =
4059 Text.unpack
@@ -51,6 +70,10 @@ canonicalToText (Canonical _ name) =
5170 toText name
5271
5372
73+
74+-- IS NATIVE
75+
76+
5477isNative :: Raw -> Bool
5578isNative name =
5679 Text.isPrefixOf "Native." name
@@ -61,9 +84,13 @@ canonicalIsNative (Canonical _ name) =
6184 isNative name
6285
6386
87+
88+-- BINARY
89+
90+
6491instance Binary Canonical where
65− put (Canonical home name) =
66− put home >> put name
92+ put (Canonical home name) =
93+ put home >> put name
6794
68− get =
69− Canonical <$> get <*> get
95+ get =
96+ Canonical <$> get <*> get