Skip to content

Instantly share code, notes, and snippets.

import Data.List.NonEmpty
import Control.Applicative
import Prelude hiding (foldl1)
import Data.Foldable (foldl1)
isA :: a -> Bool
isA = undefined
isB :: a -> Bool
isB = undefined
⛅ ~/tehcodez/scalaz (scalaz-seven)
⚡ grep -ri 'haskell' .
./core/src/main/scala/scalaz/BKTree.scala: * This implementation is a port of Haskell's [[http://hackage.haskell.org/packages/archive/bktrees/0.2.1/doc/html/src/Data-Set-BKTree.html Data.Set.BKTree]]
./core/src/main/scala/scalaz/ContravariantCoyoneda.scala: * @see http://hackage.haskell.org/package/kan-extensions-4.0.1/docs/Data-Functor-Contravariant-Coyoneda.html
./core/src/main/scala/scalaz/DList.scala: * Based on `Data.DList`, a Haskell library by Don Stewart.
./core/src/main/scala/scalaz/Heap.scala: * Based on the heaps Haskell library by Edward Kmett
./core/src/main/scala/scalaz/ISet.scala:// http://www.haskell.org/ghc/docs/latest/html/libraries/containers-0.5.0.0/src/Data-Set-Base.html#Set
./core/src/main/scala/scalaz/ISet.scala: * Documentation as copied from the Haskell source:
./core/src/main/scala/scalaz/InvariantFunctor.scala: * @see [[http://hackage.haskell.org/packages/archive/invariant/latest/doc/html/Data-Functor-Invariant.html]]
./c
Ϟ *Main
λ let x = 1 :/ 'a' :/ 2 :/ 'c' :/ ABNil
Ϟ *Main
λ :t x
x :: ABList Integer Char
infixl 4 <&&
(<&&) :: Functor f => f (a -> b) -> a -> f b
(<&&) = \f a -> fmap ($ a) f
import scala.collection.immutable.Queue
import scalaz.Monoid
case class BQ[A](private val q: Queue[A], n: Int) {
private def bound(qq: Queue[A]): Queue[A] = {
val s = qq.size
if (s > n)
qq.drop(n - s)
else
total
natToFin2 : (m : Nat) -> (n : Nat) -> {p : Nat.LT m n} -> Fin n
natToFin2 Z (S j) = fZ
natToFin2 (S k) (S j) = fS (natToFin2 k j)
-- *natto> :r
-- Type checking ./natto.idr
-- natto.idr:17:11:Incomplete term fS (natToFin2 k j)
-- Metavariables: Main.natToFin2
@techtangents
techtangents / monad.js
Created July 14, 2014 02:36
Some ideas for monads in javascript. There's probably bugs - this is just some ideas. You can run the file with node and it'll print some example code.
/**
Produce a monad given:
- point
and one or:
- bind
- map + join
So long as you have a minimum definition, the remainder of the ops will be derived.
You can explicitly specify any of these - e.g. you can specify point, map and bind if you like.
module Mappy where
import Control.Monad.State.Trans
import Data.Traversable
import Data.Tuple
import Control.Monad.State
import Control.Monad.State.Class
mapAccumL :: forall a b c t. (Traversable t) => (a -> b -> Tuple c a) -> a -> t b -> Tuple (t c) a
mapAccumL f s t =
measureInner :: forall eff. JQuery -> Eff (dom :: DOM | eff) Size
measureInner jq =
size <$> innerWidth jq <*> innerHeight jq
foreign import innerWidth
"""
function innerWidth(ob) {
return function () {
return ob.innerWidth();
@techtangents
techtangents / join-bimap.hs
Last active March 9, 2020 01:02
join bimap explanation
-- Consider the function type constructor "->" in infix form:
-- e.g. "a -> b" is the same as "(->) a b"
-- Partially applied, "(->) a" is the "reader" type,
-- i.e. functions that "read" an 'a'. "(->) a" is a Monad - the Reader Monad.
-- Consider the join function:
join :: Monad m => m (m a) -> m a