Open hdgarrood opened 10 years ago
Or this:
class PPFileType a where
ext :: a -> Text
newtype Sass = Sass { unSass :: ByteString }
instance PPFileType Sass where
ext = const "sass"
Actually I think that will cause too much noise and boilerplate for type checking. Maybe this would work better:
newtype FileExtension = FileExtension { unFileExtension :: Text }
newtype PP' a = PP' { runPP :: [(FileExtension, a)] -> PPM [(FileExtension, a)] }
newtype PP = PP { unPP :: PPT ByteString }
instance Monoid a => Monoid PPT a where
mempty = PP return
mappend (PP a) (PP b) = PP (b >=> a)
Then a list of pairs Then we can check the correct files have been supplied at runtime with something like this:
withFiles :: [(FileExtension, a -> PPM a)] -> [(FileExtension, a)] -> PPM [(FileExtension, a)]
withFile :: FileExtension -> (a -> PPM a) -> [(FileExtension, a)] -> PPM [(FileExtension, a)]
withFile ext action = withFiles [(ext, (,) <$> pure ext <*> action)]
sassWithSourceMap :: PP
sassWithSourceMap = PP $ PP' $ withFile "sass" $ \fileData -> do
(css, sourceMap) <- compileSass fileData
return [("css", css), ("map", sourceMap)]
minifyCss :: PP
minifyCss = PP $ PP' $ withFile "css" $ ???
Reasoning is:
Ideas:
PP
consumes/produces at the type level, enabling aCategory
instance:Problems: can't really do more than 1 source / destination per PP.
Next attempt:
where
Sass
,Css
,SourceMap
are probably newtypedByteString