From b73c4cfd1b9c9ecf2230de31995f89c95644d27d Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Thu, 11 Nov 2021 21:15:17 +0200 Subject: [PATCH] Shuffle things around and create a demo --- FeedMonad-demo/CHANGELOG.md | 5 +++ FeedMonad-demo/FeedMonad-demo.cabal | 38 +++++++++++++++++++ FeedMonad-demo/app/Main.hs | 9 +++++ FeedMonad-demo/default.nix | 11 ++++++ FeedMonad-demo/src/MyLib.hs | 4 ++ FeedMonad/FeedMonad.cabal | 16 +------- FeedMonad/app/Main.hs | 7 ---- FeedMonad/src/Data/Category.hs | 15 ++++++++ FeedMonad/src/FeedMonad.hs | 7 ++-- cabal.project | 1 + .../easy-hls-nix.json => easy-hls-nix.json | 0 hie.yaml | 2 + FeedMonad/shell.nix => shell.nix | 5 ++- 13 files changed, 93 insertions(+), 27 deletions(-) create mode 100644 FeedMonad-demo/CHANGELOG.md create mode 100644 FeedMonad-demo/FeedMonad-demo.cabal create mode 100644 FeedMonad-demo/app/Main.hs create mode 100644 FeedMonad-demo/default.nix create mode 100644 FeedMonad-demo/src/MyLib.hs delete mode 100644 FeedMonad/app/Main.hs create mode 100644 FeedMonad/src/Data/Category.hs create mode 100644 cabal.project rename FeedMonad/easy-hls-nix.json => easy-hls-nix.json (100%) create mode 100644 hie.yaml rename FeedMonad/shell.nix => shell.nix (78%) diff --git a/FeedMonad-demo/CHANGELOG.md b/FeedMonad-demo/CHANGELOG.md new file mode 100644 index 0000000..bc145ab --- /dev/null +++ b/FeedMonad-demo/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for FeedMonad-demo + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/FeedMonad-demo/FeedMonad-demo.cabal b/FeedMonad-demo/FeedMonad-demo.cabal new file mode 100644 index 0000000..dd3612e --- /dev/null +++ b/FeedMonad-demo/FeedMonad-demo.cabal @@ -0,0 +1,38 @@ +cabal-version: 2.4 +name: FeedMonad-demo +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- A URL where users can report bugs. +-- bug-reports: + +-- The license under which the package is released. +-- license: +author: Mats Rauhala +maintainer: mats.rauhala@iki.fi + +-- A copyright notice. +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +executable FeedMonad-demo + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + build-depends: + base ^>=4.14.3.0, + FeedMonad, + containers + + hs-source-dirs: app + default-language: Haskell2010 diff --git a/FeedMonad-demo/app/Main.hs b/FeedMonad-demo/app/Main.hs new file mode 100644 index 0000000..ce1944a --- /dev/null +++ b/FeedMonad-demo/app/Main.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main where + +import FeedMonad +import Data.Category + +main :: IO () +main = do + defaultMain defaultConfig{feeds = [ Category "News" [] ]} diff --git a/FeedMonad-demo/default.nix b/FeedMonad-demo/default.nix new file mode 100644 index 0000000..bffdefd --- /dev/null +++ b/FeedMonad-demo/default.nix @@ -0,0 +1,11 @@ +{ mkDerivation, base, FeedMonad, lib }: +mkDerivation { + pname = "FeedMonad-demo"; + version = "0.1.0.0"; + src = ./.; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ base FeedMonad ]; + license = "unknown"; + hydraPlatforms = lib.platforms.none; +} diff --git a/FeedMonad-demo/src/MyLib.hs b/FeedMonad-demo/src/MyLib.hs new file mode 100644 index 0000000..e657c44 --- /dev/null +++ b/FeedMonad-demo/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib (someFunc) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/FeedMonad/FeedMonad.cabal b/FeedMonad/FeedMonad.cabal index 32701e3..500ccc1 100644 --- a/FeedMonad/FeedMonad.cabal +++ b/FeedMonad/FeedMonad.cabal @@ -28,6 +28,7 @@ library Data.Entry Middleware Paths_FeedMonad + Data.Category -- Modules included in this library but not exported. -- other-modules: @@ -50,18 +51,3 @@ library hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall - -executable FeedMonad - main-is: Main.hs - - -- Modules included in this executable, other than Main. - -- other-modules: - - -- LANGUAGE extensions used by modules in this package. - -- other-extensions: - build-depends: - base ^>=4.14.3.0, - FeedMonad - - hs-source-dirs: app - default-language: Haskell2010 diff --git a/FeedMonad/app/Main.hs b/FeedMonad/app/Main.hs deleted file mode 100644 index 9b1ca3c..0000000 --- a/FeedMonad/app/Main.hs +++ /dev/null @@ -1,7 +0,0 @@ -module Main where - -import FeedMonad (defaultMain, defaultConfig) - -main :: IO () -main = - defaultMain defaultConfig diff --git a/FeedMonad/src/Data/Category.hs b/FeedMonad/src/Data/Category.hs new file mode 100644 index 0000000..ec5ba49 --- /dev/null +++ b/FeedMonad/src/Data/Category.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE DeriveFunctor #-} +module Data.Category where + +import Data.Text (Text) + +data Category a + = Leaf a + | Category Text [Category a] + deriving (Show, Functor) + +foldCategory :: (a -> b) -> (Text -> [b] -> b) -> Category a -> b +foldCategory fab f = go + where + go (Leaf a) = fab a + go (Category txt cats) = f txt (map go cats) diff --git a/FeedMonad/src/FeedMonad.hs b/FeedMonad/src/FeedMonad.hs index c3342af..cb4c817 100644 --- a/FeedMonad/src/FeedMonad.hs +++ b/FeedMonad/src/FeedMonad.hs @@ -1,17 +1,18 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE DeriveFunctor #-} module FeedMonad where -import Data.Tree (Forest) import Data.Text (Text) import Data.Entry (URL) import Middleware (Middleware) import Numeric.Natural (Natural) -import Data.Foldable (for_) +import Data.Category (Category) + newtype Minutes = Minutes Natural data FeedMonad = FeedMonad - { feeds :: Forest URL + { feeds :: [Category URL] -- ^ The forest of urls for the feeds. It's a forest because of the categories , filters :: Middleware -- ^ The middleware. Modifies the scoring, tags and content diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..f44a24c --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: */*.cabal diff --git a/FeedMonad/easy-hls-nix.json b/easy-hls-nix.json similarity index 100% rename from FeedMonad/easy-hls-nix.json rename to easy-hls-nix.json diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 0000000..04cd243 --- /dev/null +++ b/hie.yaml @@ -0,0 +1,2 @@ +cradle: + cabal: diff --git a/FeedMonad/shell.nix b/shell.nix similarity index 78% rename from FeedMonad/shell.nix rename to shell.nix index f22dae9..c0ff229 100644 --- a/FeedMonad/shell.nix +++ b/shell.nix @@ -10,13 +10,14 @@ let }; easy-hls = callPackage easy-hls-src { ghcVersions = [ hp.ghc.version ]; }; hp = haskellPackages.extend (self: super: { - FeedMonad = self.callPackage ./. {}; + FeedMonad = self.callPackage ./FeedMonad {}; + FeedMonad-demo = self.callPackage ./FeedMonad-demo {}; }); in hp.shellFor { - packages = h: [h.FeedMonad]; + packages = h: [h.FeedMonad h.FeedMonad-demo]; withHoogle = true; buildInputs = [ entr