Skip to content

Commit

Permalink
Merge pull request #15 from alexfmpe/develop
Browse files Browse the repository at this point in the history
Build with ghc 9.10
  • Loading branch information
alexfmpe authored Jan 14, 2025
2 parents 29e0c5b + 64cd8a6 commit ed16e73
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
ghc: ['8.6.5', '8.10.7']
ghc: ['8.6', '8.8', '8.10', '9.0', '9.2', '9.4', '9.6', '9.8', '9.10']
os: ['ubuntu-latest', 'macos-latest']
runs-on: ${{ matrix.os }}

Expand All @@ -16,7 +16,6 @@ jobs:
- uses: haskell/actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: '3.10.1.0'
- name: Cache
uses: actions/cache@v3
env:
Expand All @@ -31,10 +30,15 @@ jobs:
${{ runner.os }}
- name: Install dependencies
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
run: |
cabal update
cabal build --only-dependencies --enable-tests --enable-benchmarks
- name: Build
run: cabal build --enable-tests --enable-benchmarks all

- name: Run tests
run: cabal test all

- name: Build Docs
run: cabal haddock
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist-newstyle
37 changes: 19 additions & 18 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ Let's start with some imports and language pragmas.
> {-# LANGUAGE TemplateHaskell #-}
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE UndecidableInstances #-}
>

> module Readme where
>

> import Control.Monad (void)
> import Control.Monad.IO.Class (MonadIO)
> import Control.Monad.Fix (MonadFix)
> import Data.Aeson (ToJSON(..), FromJSON(..))
> import Data.Aeson.GADT.TH (deriveJSONGADT)
> import Data.Constraint.Extras (Has)
> import Data.Constraint.Extras.TH (deriveArgDict)
> import Data.Kind (Type)
> import Data.Text as T (Text, null, pack)
> import Data.Time (UTCTime, Day)
> import GHC.Generics (Generic)
> import Reflex.Dom.Core
> import Reflex.Dom.GadtApi
>


```

Expand All @@ -60,30 +61,30 @@ The code that follows would typically go in a common module, since it would be u
> , _dog_imageUri :: Maybe Text
> }
> deriving (Generic)
>

> instance ToJSON Dog
> instance FromJSON Dog
>


```

Here we have an API for retrieving and interacting with the `Dog` data:

```haskell

> data DogApi :: * -> * where
> data DogApi :: Type -> Type where
> DogApi_GetByDay :: Day -> DogApi [Dog]
> DogApi_GetByName :: Text -> DogApi [Dog]
> DogApi_GetLastSeen :: DogApi (Maybe Dog)
> DogApi_ReportSighting :: Text -> Bool -> Maybe Text -> DogApi (Either Text ())
> DogApi_GetSuspiciousSightings :: DogApi [Dog]
>

> newtype Token = Token { unToken :: Text }
> deriving (Generic)
>

> instance ToJSON Token
> instance FromJSON Token
>


```

Expand All @@ -94,12 +95,12 @@ We can take the `DogApi` and embed it in another GADT API. This outer API will h
> data CatApi a where
> CatApi_Identify :: Text -> CatApi (Either Text Token)
> CatApi_DogApi :: Token -> DogApi a -> CatApi a
>

> deriveJSONGADT ''DogApi
> deriveJSONGADT ''CatApi
> deriveArgDict ''DogApi
> deriveArgDict ''CatApi
>


```

Expand All @@ -108,7 +109,7 @@ On the frontend, we'll run a `RequesterT` widget that allows us to emit an event
```haskell

> type Catnet t m = (RequesterT t CatApi (Either Text) m)
>


```

Expand Down Expand Up @@ -178,7 +179,7 @@ We're using reflex `Workflow`s to switch between pages, but we could accomplish
> rsp <- dogSighting token
> leave <- delay 3 rsp
> pure ((), catnetW token <$ leave) -- Go back to catnet
>


```

Expand All @@ -191,7 +192,7 @@ If you're building your frontend in a context where the user interface needs to
> => Event t (Request (Client (Catnet t m)) a)
> -> Catnet t m (Event t (Response (Client (Catnet t m)) a))
> requestingJs r = fmap (switch . current) $ prerender (pure never) $ requesting r
>


```

Expand All @@ -214,7 +215,7 @@ The response from the server is an `Event` that can be used to update the user i
> Right (Right catToken) -> Just catToken
> _ -> Nothing
> pure token
>


```

Expand Down Expand Up @@ -246,7 +247,7 @@ This function builds a UI with a few buttons. Depending on which button is click
> Right dogs -> el "ul" $ mapM_ (el "li" . showDog) dogs
> -- Return the "Report a sighting" click event
> pure addDog
>


```

Expand All @@ -268,7 +269,7 @@ The `showDog` widget below does not have `Catnet` or `RequesterT` in its type si
> el "dd" $ case _dog_imageUri dog of
> Just img -> elAttr "img" ("src" =: img <> "alt" =: "dog mugshot") blank
> Nothing -> text "None"
>


```

Expand Down Expand Up @@ -318,7 +319,7 @@ Once we've got those three values, we can apply them to the `DogApi_ReportSighti
> Right (Left err) -> Left err
> Left err -> Left err
> Right (Right result) -> Right result
>

> main :: IO ()
> main = return ()

Expand Down
12 changes: 6 additions & 6 deletions reflex-gadt-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description:
This package is designed to be used in full-stack Haskell applications where the API is defined as a GADT and the frontend is using reflex-dom.

bug-reports: https://github.com/reflex-frp/reflex-gadt-api/issues
license: BSD3
license: BSD3
license-file: LICENSE
author: Obsidian Systems
maintainer: [email protected]
Expand All @@ -24,16 +24,16 @@ library
build-depends:
aeson >=1.4.4 && <2.3
, aeson-gadt-th >=0.2.4 && <0.3
, base >=4.12 && <4.16
, bytestring >=0.10.8 && <0.11
, base >=4.12 && <4.21
, bytestring >=0.10.8 && <0.13
, constraints-extras >=0.3.0 && <0.5
, containers >=0.6 && <0.7
, data-default >=0.6 && <0.8
, containers >=0.6 && <0.8
, data-default >=0.6 && <0.9
, jsaddle >=0.9.7 && <0.10
, reflex >=0.7 && <1
, reflex-dom-core >=0.7.0 && <0.9
, some >=1 && <1.1
, text >=1.2 && <1.3
, text >=1.2 && <2.2
, time >=1.6.0 && <2

exposed-modules:
Expand Down

0 comments on commit ed16e73

Please sign in to comment.