i built a state monad using a reader w/ an ioref in it, but i'm not sure if there are any practical uses for it over the existing state monad, but i guess u could use it with lenses for proper mutable variables
also it's probably really buggy, i didnt test it muchIntolerable
[link] [3 comments]
Is anyone able to do this? It's for a small project me and my brother are working on. We would truly appreciate it
Ideally it would work something like this, string: "red blue green red"
green 1submitted by the16
[link] [9 comments]
Alex Andreou writes in The Guardian:
I hear results of straw polls showing that a majority of people in this country feel "uncomfortable" with immigration. ... I am disappointed by both the Conservatives and Labour's stance on immigration. It seems to me they are trying to address multiple audiences; on the one hand they want to comfort the uncomfortable, on the other there seems to be a nudge-nudge, wink-wink message between the lines intended for people like me that says "don't worry". By doing that, they legitimise Ukip's highly dangerous message, because they allow Farage to point to imitators and boost the brand validity of his "original" snake oil.
I don't think I can bring myself to vote for the Liberal Democrats again. Tuition fees, austerity, bedroom tax, welfare cap, Atos, Royal Mail – the list goes on. This left me looking at the Green party, as the default remaining choice. The surprise was that the more I looked at them, the more I liked them. Their policies appear to me eminently sensible and unabashedly progressive, in most areas. They are the only party which has refused to be drawn into the immigrant-bashing competition with the others, and the only which proposes a vote in the general elections for EU citizens based on residency, rather than nationality. Their commitment to minority rights, including LGBT, is second to none. They alone seem to understand that discussion and collaboration, rather than confrontation, is the way to reform the EU. Their candidates seem passionate and compassionate. My scrutiny left me thinking: why wasn't I planning to vote for them in the first place, especially when there is proportional representation?
Ok, so, I'm trying to learn various recursion schemes to help make my code nicer. I have an abstract syntax tree thusly:data ExprF a self where Const :: Symbolic → ExprF a self Zero ∷ ExprF a self Add :: self → self → ExprF a self Subtract ∷ self → self→ ExprF a self Sum :: [self] → ExprF a self Product :: [self] → ExprF a self Tuple ∷ [self] → ExprF a self Polynomial ∷ self → [PowerSeriesCoefficient a] → ExprF a self Apply ∷ Operator → [self] → ExprF a self Power :: self → self → ExprF a self Psuedoscalar ∷ ExprF a self Exp ∷ self → ExprF a self Cos ∷ self → ExprF a self UnaryOperator ∷ UnaryOperator → self → ExprF a self BinaryOperator ∷ BinaryOperator → self → self → ExprF a self type TExpr a = Fix (ExprF a)
I have implemented evaluation like so:type Env a = Data.Map.Map Symbolic a eval ∷ Algebra.Ring.C a ⇒ Env a → TExpr anno → a eval env = cata (evalAlg env) evalAlg ∷ Algebra.Ring.C a ⇒ Env a → ExprF anno a → a evalAlg env = eval' where eval' (Const var) = fromJust $ Data.Map.lookup var env eval' (Sum xs) = Data.List.Stream.foldr1 (+) xs eval' (Product xs) = Data.List.Stream.foldr1 (*) xs eval' (UnaryOperator op val) = evalUnary op val eval' (Add a b) = a + b eval' (Subtract a b) = a - b eval' _ = undefined --etc evalUnary ∷ Algebra.Ring.C a ⇒ UnaryOperator → a → a evalUnary Negate val = negate val
Now, the question is... What would be the nicest way of implementing simplification using a recursion scheme? I'm currently doing it with another catamorphism like this:simplify ∷ TExpr anno → TExpr anno simplify = cata alg where alg (Add a b) = simplifyAdd a b alg a = Fix a simplifyAdd (Fix (Sum xs)) s = Fix (Sum (s:xs)) --etc
however, this seems to be full of boilerplate Fixing and so on. Is there a nicer morphism?deltaSquee
[link] [21 comments]