What I want is to "compose" functions taking some argument and
returning an Alt
value, like a -> m b
where Alt b
. The
resulting value should be a function from a -> m b
. The
implementation below does that, but I was wondering if there's
a better way? I'm thinking that maybe I could create a newtype
wrapper around these functions, and an Alt
instance for that
type, but I haven't gotten that to work, and I'm not sure it's
a good approach.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TypeSynonymsProblem where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Data.Either (Either) | |
import Data.Tuple (Tuple(Tuple)) | |
type Foo e a a' b b' = Eff e (Tuple a b) -> Eff e (Tuple a' b') | |
type Bar e a a' b b' = Eff e (Either a b) -> Eff e (Either a' b') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SafeWeb where | |
import Prelude | |
import Data.Array (filter) | |
import Data.Leibniz (type (~)) | |
import Data.String (Pattern(Pattern), split, joinWith) | |
type Path = Array String | |
pathToHtml :: Path -> String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No type class instance was found for | |
Control.Monad.Monad m0 | |
while checking that expression { path: [ "contact" | |
] | |
, GET: handler (\conn -> | |
... | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, log) | |
type R m = { f ∷ Int → m Int } | |
makeDecr ∷ ∀ m. Monad m ⇒ R m → R m | |
makeDecr r = { f: \n → if n > 0 then r.f (n - 1) else pure n } |
I hereby claim:
- I am owickstrom on github.
- I am owickstrom (https://keybase.io/owickstrom) on keybase.
- I have a public key whose fingerprint is 571E 0B73 FDB5 B163 DD48 7576 CEDE 3357 E0C5 F53E
To claim this, I am signing this object:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Examples.SafeForm where | |
import Control.IxMonad ((:*>)) | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE) | |
import Control.Monad.Except (ExceptT) | |
import Data.Foldable (traverse_) | |
import Data.Maybe (Maybe(..), maybe) | |
import Data.MediaType.Common (textHTML) | |
import Data.Monoid (mempty) |
With Servant-style routing, the ordering of endpoints in types must line up with handlers on the value level. Destructuring clients and link structures derived from a routing type cannot be done without introducing coupling to the ordering of the routing type.
This experiment tries to remove that ordering issue, by using named resources and methods on the type level, in combination with PureScript's records (constrained by RowCons
) at the value level. The ordering no longer matter when we give handlers in a record. We could also implement link or client deriving functions that would extract specific clients based on a given name. All name checks are done at compile time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.stack-work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | This shows a way of computing a recursive type, and applying | |
-- constraints to individual types within it, using a type family. | |
-- I've commented the different parts, and the file ends with some | |
-- questions. | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE RankNTypes #-} |