arrows

Convert from arrow notation

半城伤御伤魂 提交于 2019-12-04 06:11:50
I'm still trying to get a hang of the parallels between arrow notation and the semantics of the Arrow typeclasses defined in Haskell. In particular, this question seems to have a very canonical example of a small counter written with arrow notation: counter :: ArrowCircuit a => a Bool Int counter = proc reset -> do rec output <- returnA -< if reset then 0 else next next <- delay 0 -< output+1 returnA -< output Can someone show me how to convert this back into Haskell2010 without arrow notation? {- | +---------+ >Bool>--------------> | | >------------------>Int> +---------+ | arr f | /---->

Arrow equivalent of mapM?

给你一囗甜甜゛ 提交于 2019-12-03 23:39:07
I'm trying to grok & work with Arrows, and am having some difficulty. I have a context where I need an Arrow [a] [b] , and I want to write an Arrow a b and map/sequence it inside the arrow, a la mapM . Specifically, the arrow is a Hakyll Compiler , but I don't think that matters much for the answer. Given an arrow myInnerArrow :: Arrow a => a b c How can I lift this into an arrow myOuterArrow :: Arrow a => a [b] [c] ? I have scoured the base library, particularly in Data.List and Control.Arrow , but I cannot find anything that looks like it will do the job. Does it exist under a name I do not

Creative uses of arrows

我是研究僧i 提交于 2019-12-03 07:26:47
问题 I just read the post Creative uses of monads, that is crowded of very interesting ideas and references, so I got curious: what about arrows? I'm not looking for personal opinions or references on the basics or "standard" uses (as in monads vs arrows or help understanding arrows in haskell), but rather for a list of references to smart and/or non-trivial applications (maybe in research papers?). Thanks. 回答1: Arrows can be used for security: A very interesting paper by Li and Zdancewic

Haskell: Am I misunderstanding how Arrows may be used?

拜拜、爱过 提交于 2019-11-30 10:40:01
问题 I wrote some toy code to play with the concept of Arrows. I wanted to see if I could write an Arrow which encoded the concept of a stateful function - giving a different value after different calls. {-# LANGUAGE Arrows#-} module StatefulFunc where import Control.Category import Control.Arrow newtype StatefulFunc a b = SF { unSF :: a -> (StatefulFunc a b, b) } idSF :: StatefulFunc a a idSF = SF $ \a -> (idSF, a) dotSF :: StatefulFunc b c -> StatefulFunc a b -> StatefulFunc a c dotSF f g = SF $

How to draw a nice arrow in ggplot2

落花浮王杯 提交于 2019-11-30 06:00:01
I am creating a ggplot chart where I want to have some arrows between two points. The main task is easily done with geom_line(arrow = arrow()) . However, I want to have some "beautiful" thick arrows. Resizing the arrow via size= doesn't help since it messes up the head of the arrow completely. I illustrate my Problems: Create some sample data and a plot: NAME <- c("A", "A", "B", "B", "C", "C") YEAR <- c(2016, 2011, 2016, 2011, 2016, 2011) YEAR <- as.factor(YEAR) VALUE <- c(1, 4, 1, 5, 2, 8) DATA <- data.frame(NAME, YEAR, VALUE) ggplot(DATA, aes(x=VALUE, y=NAME)) + geom_point(size=5, aes(colour

What's the relationship between profunctors and arrows?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 03:44:39
Apparently, every Arrow is a Strong profunctor. Indeed ^>> and >>^ correspond to lmap and rmap . And first' and second' are just the same as first and second . Similarly every ArrowChoice is also Choice . What profunctors lack compared to arrows is the ability to compose them. If we add composition, will we get an arrow? In other words, if a (strong) profunctor is also a category , is it already an arrow? If not, what's missing? What profunctors lack compared to arrows is the ability to compose them. If we add composition, will we get an arrow? MONOIDS This is exactly the question tackled in

How does the Haskell rec keyword work?

送分小仙女□ 提交于 2019-11-30 00:06:33
In arrow do notation, you can use the rec keyword to write recursive definitions. So for example: rec name <- function -< input input <- otherFunction -< name How can this ever evaluate? It seems like it would just go into an infinite loop or something. I know it evaluates to the loop arrow combinator, but I don't understand how that works either. EDIT: that powers example is really helpful. How would you write that with do notation, though? I assume you would need to use rec. This bit of magic works due to haskells laziness. As you might know, Haskell evaluates a value when needed, not when

Haskell: Am I misunderstanding how Arrows may be used?

半腔热情 提交于 2019-11-29 22:24:20
I wrote some toy code to play with the concept of Arrows. I wanted to see if I could write an Arrow which encoded the concept of a stateful function - giving a different value after different calls. {-# LANGUAGE Arrows#-} module StatefulFunc where import Control.Category import Control.Arrow newtype StatefulFunc a b = SF { unSF :: a -> (StatefulFunc a b, b) } idSF :: StatefulFunc a a idSF = SF $ \a -> (idSF, a) dotSF :: StatefulFunc b c -> StatefulFunc a b -> StatefulFunc a c dotSF f g = SF $ \a -> let (g', b) = unSF g a (f', c) = unSF f b in (dotSF f' g', c) instance Category StatefulFunc

How does ArrowLoop work? Also, mfix?

妖精的绣舞 提交于 2019-11-29 21:23:18
I'm fairly comfortable now with the rest of the arrow machinery, but I don't get how loop works. It seems magical to me, and that's bad for my understanding. I also have trouble understanding mfix. When I look at a piece of code that uses rec in a proc or do block, I get confused. With regular monadic or arrow code, I can step through the computation and keep an operational picture of what's going on in my head. When I get to rec , I don't know what picture to keep! I get stuck, and I can't reason about such code. The example I'm trying to grok is from Ross Paterson's paper on arrows , the one

What are arrows, and how can I use them?

跟風遠走 提交于 2019-11-29 18:43:43
I tried to learn the meaning of arrows , but I didn't understand them. I used the Wikibooks tutorial. I think Wikibook's problem is mainly that it seems to be written for somebody who already understands the topic. Can somebody explain what arrows are and how I can use them? I don't know a tutorial, but I think it's easiest to understand arrows if you look at some concrete examples. The biggest problem I had learning how to use arrows was that none of the tutorials or examples actually show how to use arrows, just how to compose them. So, with that in mind, here's my mini-tutorial. I'll