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 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 } |
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 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
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
-- A data type wrapping a non-empty string | |
data Name : Type where | |
MkName : (s : String) -> (not (s == "") = True) -> Name | |
-- Some function that expects a valid Name | |
test : Name -> String | |
test (MkName s _) = s | |
-- Usage of that function. Do I need Refl here? Any better way of doing this? | |
foo : 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
//----------// | |
// SEMIRING // | |
//----------// | |
// Types that support addition and multiplication. | |
protocol Semiring(a) { | |
add : a -> a -> a | |
zero : a | |
mul : a -> a -> a | |
one : a |
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
(pkg main) | |
(import fmt) | |
;; if expressions | |
(: fib (int -> int)) | |
(def (fib n) | |
(if (== n 1) | |
0 | |
(if (== n 2) |
THIS DRAFT HAS MOVED TO https://github.com/owickstrom/kashmir.
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
#lang racket | |
(require "minikanren/mk.rkt") | |
(struct e/var (name) #:transparent) | |
(struct e/app (fn param) #:transparent) | |
(struct e/lam (arg body) #:transparent) | |
(define (t/fn domain range) | |
(list ':fn domain range)) |