View Tarjan.hs
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
{-# LANGUAGE RankNTypes, GADTs, PolyKinds #-} | |
module Tarjan where | |
import Control.Applicative | |
import Control.Category | |
import Data.Monoid | |
import Prelude hiding ((.),id) | |
-- Radu Mihaesau and Robert Tarjan's Catenable Deque |
View Success.hs
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
{-# LANGUAGE DeriveFunctor, TypeFamilies #-} | |
module Success | |
( Parser(..) | |
, parse | |
) where | |
import Control.Applicative | |
import Control.Monad | |
import Data.Bifunctor | |
import Data.Profunctor |
View CF.hs
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
bihom a b _ _ e f _ _ xs [] = hom a b e f xs | |
bihom a _ c _ e _ g _ [] ys = hom a c e g ys | |
bihom a b c d e f g h xs@(x:xs') ys@(y:ys') | |
| e /= 0, f /= 0, g /= 0, h /= 0 | |
, q <- quot a e, q == quot b f | |
, q == quot c g, q == quot d h | |
= q : go e f g h (a-q*e) (b-q*f) (c-q*g) (d-q*h) xs ys | |
| e /= 0 || f /= 0 | |
, (e == 0 && g == 0) || abs (g*e*b - g*a*f) > abs (f*e*c - g*a*f) | |
= go (a*x+b) a (c*x+d) c (e*x+f) e (g*x+h) g xs' ys |
View WordMap.hs
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
{-# LANGUAGE CPP #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE PatternGuards #-} | |
{-# LANGUAGE MultiWayIf #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE Trustworthy #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} |
View monads for plt-racket
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 monad scheme | |
(require "curry.ss") | |
;; i'm too lazy to repeat this pattern for now. | |
(define-syntax init-public | |
(syntax-rules () | |
((_) (begin)) | |
((_ (m default) ms ...) (begin | |
(init-field (m default)) | |
(public (internal-m m)) | |
(define (internal-m . rest) (apply (get-field m this) rest)) |
View deepSeq once and only once
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
import Control.Parallel.Strategies | |
data NF a = NF () a | |
nfBy :: Strategy a -> a -> NF a | |
nfBy s a0 = r where r@(NF _ a) = NF (s a) a0 | |
nf :: NFData a => a -> NF a | |
nf = nfBy rnf |
View product categories in scala
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
package scalaz | |
/** | |
* Defines a category. | |
* | |
* <p> | |
* All instances must satisfy 3 laws: | |
* <ol> | |
* <li><strong>left identity</strong><br/><code>∀ a. compose(id, a) == a</code></li> |
View dual
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
trait HomClass { self => | |
type L | |
type H>:L | |
type C[_>:L<:H,_>:L<:H] | |
type Dual <: HomClass { | |
type L=self.type#L | |
type H=self.type#H | |
type C[A>:L<:H,B>:L<:H] = self.type#C[B,A] | |
type Dual = self.type | |
} |
View why not conformant?
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
object hom { | |
trait set { | |
type inf | |
type sup >: inf | |
type hom[_>:inf<:sup,_>:inf<:sup] | |
type dual = set.of[inf,sup,({type λ[x>:inf<:sup,y>:inf<:sup]=hom[y,x]})#λ] | |
} | |
object set { | |
trait of[l,h>:l,c[_>:l<:h,_>:l<:h]] extends set { | |
type inf = l |
View example
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
scala> import magpie._ | |
import magpie._ | |
scala> type i = hom.set.singleton[Int] | |
defined type alias i | |
scala> type arr = hom.set.of[Nothing,Any,({type o[-x,+y] = y})#o, ({type f[-x,+y] = x => y })#f] | |
defined type alias arr | |
scala> (_/2) : arr#hom[Int,Double] |
OlderNewer