Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
hughfdjackson / gate.js
Created June 17, 2015 22:13
A suggested utility function based on RxJS
// Gate takes three Observables.
// gateFlag$: an Observable of booleans
// open$: an Observable of values
// closed$: an Observable of values
var gate = function(gateFlag$, open$, closed$) {
...
};
// Use Case:
var composeBack = function(nb2, nb1){
return function(input, cb){
nb1(input, function(err, val1) {
if (err) return cb(err);
else nb2(val1, function(err, val){
if (err) return cb(err);
else cb(undefined, val)
})
});
}
import Text.Parsec
import Text.Parsec.String
import Control.Applicative hiding (many, (<|>))
data Calc = Number Float
| OpPlus Calc Calc
| OpMult Calc Calc
| OpSubt Calc Calc
| OpDivd Calc Calc
*Main> 1 / 2 + 3 * 34 / 3 - 343 * 3 / 34 * 34
-994.5
*Main> intr "1 / 2 + 3 * 34 / 3 - 343 * 3 / 34 * 34"
Right (-994.5)
Building dust-0.1.0.0...
Preprocessing executable 'dust' for dust-0.1.0.0...
Preprocessing test suite 'tests' for dust-0.1.0.0...
[2 of 4] Compiling Language.Parse ( src/Language/Parse.hs, dist/build/tests/tests-tmp/Language/Parse.o )
src/Language/Parse.hs:17:12:
No instance for (Stream s m Char) arising from a use of ‘oneOf’
In a stmt of a 'do' block: first <- oneOf alpha
In the expression:
do { first <- oneOf alpha;
- + Errors (1)
`-- tutorial.idr line 24 col 20:
When elaborating right hand side of vectormanip.reverse, reverseAcc:
Can't unify
Vect (m + S n) a
with
Vect (S (plus m n)) a
Specifically:
Can't unify
> var clone = _.partial(_.extend, {})
undefined
> clone({ x: 3, y: 3 })
Object { x: 3, y: 3 }
> clone({ x: 3 })
Object { x: 3, y: 3 }
-- proving that these are equivalent
sPlusAssoc : (m, n: Nat) -> S (m + n) = plus m (S n)
sPlusAssoc Z n = refl
sPlusAssoc (S m) n = rewrite sPlusAssoc m n in refl
-- want to use the proof here
total concat : Vect n a -> Vect m a -> Vect (m + n) a
concat (x :: xs) ys = x :: (concat xs ys)
concat Nil ys = ys
sPlusAssoc : (m, n: Nat) -> S (m + n) = plus m (S n)
sPlusAssoc Z n = refl
sPlusAssoc (S m) n = rewrite sPlusAssoc m n in refl
total concat : Vect n a
-> Vect m a
-> Vect (m + n) a
concat {a=a} {m=m} {n=n} (x :: xs) ys = replace {P = \k => Vect k a} (sPlusAssoc m n) (x :: concat xs ys)
concat Nil ys = replace sPlusAssoc $ ys
sPlusAssoc : (m, n: Nat) -> S (m + n) = plus m (S n)
sPlusAssoc Z n = refl
sPlusAssoc (S m) n = rewrite sPlusAssoc m n in refl
total concat : Vect n a
-> Vect m a
-> replace {P = \k => Vect k a} (sPlusAssoc m n) (Vect (m + n) a)
concat (x :: xs) ys = x :: (concat xs ys)
concat nil ys = ys