Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • geode/ghc-geode
1 result
Show changes
Commits on Source (2)
...@@ -9,8 +9,8 @@ import Data.Aeson.KeyMap as Object (union) ...@@ -9,8 +9,8 @@ import Data.Aeson.KeyMap as Object (union)
import Data.Csv (FromNamedRecord(..), ToNamedRecord(..)) import Data.Csv (FromNamedRecord(..), ToNamedRecord(..))
import Data.HashMap.Strict as Hash (union) import Data.HashMap.Strict as Hash (union)
infixr 9 @ infixl 9 @
infixr 9 :@: infixl 9 :@:
data a @ b = a :@: b data a @ b = a :@: b
class Has a b where class Has a b where
...@@ -19,11 +19,11 @@ class Has a b where ...@@ -19,11 +19,11 @@ class Has a b where
instance Has a a where instance Has a a where
get = id get = id
instance Has a c => Has a (b @ c) where instance Has a b => Has a (b @ c) where
get (_ :@: c) = get c get (b :@: _) = get b
instance {-# OVERLAPS #-} Has a (a @ b) where instance {-# OVERLAPS #-} Has b (a @ b) where
get (a :@: _) = a get (_ :@: b) = b
instance (ToNamedRecord a, ToNamedRecord b) => ToNamedRecord (a @ b) where instance (ToNamedRecord a, ToNamedRecord b) => ToNamedRecord (a @ b) where
toNamedRecord (a :@: b) = Hash.union (toNamedRecord a) (toNamedRecord b) toNamedRecord (a :@: b) = Hash.union (toNamedRecord a) (toNamedRecord b)
......
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
module GEODE.Metadata.Work module GEODE.Metadata.Work
( Work(..) ) where ( Work(..) ) where
import Data.Aeson (ToJSON(..)) import Data.Aeson (FromJSON(..), ToJSON(..), withText)
import Data.ByteString.Char8 as ByteString (unpack)
import Data.Csv (FromField(..), ToField(..)) import Data.Csv (FromField(..), ToField(..))
import Data.Char (toLower) import Data.Char (toLower)
import Data.ByteString.Char8 as ByteString (map) import Data.Text as Text (unpack)
import GHC.Generics (Generic)
data Work = EDdA | LGE | Wikipedia deriving (Eq, Ord, Read, Show) data Work = EDdA | LGE | Wikipedia deriving (Eq, Generic, Ord, Show)
tolerantParser :: (Applicative m, Monoid (m Work)) => String -> m Work
tolerantParser = recognize . fmap toLower
where
recognize "edda" = pure EDdA
recognize "lge" = pure LGE
recognize "wikipedia" = pure Wikipedia
recognize _ = mempty
instance FromField Work where instance FromField Work where
parseField = recognize . ByteString.map toLower parseField = tolerantParser . ByteString.unpack
where
recognize "EDdA" = pure EDdA
recognize "LGE" = pure LGE
recognize "Wikipedia" = pure Wikipedia
recognize _ = mempty
instance ToField Work where instance ToField Work where
toField = toField . show toField = toField . show
instance ToJSON Work where instance ToJSON Work
toJSON = toJSON . show instance FromJSON Work where
parseJSON = withText "Work" $ tolerantParser . Text.unpack