Questions tagged [arrows]

Arrows are a means of modeling computational effects that are more general and less powerful than Monads.

Arrows can express relationships between nodes in a graph (a tree is a type of graph).

Arrows can be primitives in computer graphics.

In some programming languages, arrow symbols like -> and => are syntax with specific meaning.

335 questions
7
votes
1 answer

How to work with types that change under composition?

I recently read the very interesting paper Monotonicity Types in which a new HM-language is described that keeps track of monotonicity across operations, so that the programmer does not have to do this manually (and fail at compile-time when a…
Qqwy
  • 5,214
  • 5
  • 42
  • 83
7
votes
1 answer

HXT: Left-Factoring Nondeterministic Arrows?

I'm trying to come to terms with Haskell's XML Toolbox (HXT) and I'm hitting a wall somewhere, because I don't seem to fully grasp arrows as a computational tool. Here's my problem, which I hoped to illustrate a little better using a GHCi session: >…
Aleksandar Dimitrov
  • 9,275
  • 3
  • 41
  • 48
7
votes
1 answer

Adding arrow symbols in ggplot text in R

I recently found out that it is possible to add greek alphabets and other symbols within the annotate text in ggplot. I am trying to add arrows (upwards and downwards) to my text and I can't seem to find the correct numerical code for it. I tried…
Binggg
  • 147
  • 1
  • 2
  • 8
7
votes
1 answer

HLint : use &&& suggestion advice

I ran HLint on a little project and it suggested me to use &&&. Example : >>> cat st.hs f = (+) 10 g = (+) 1 main = print $ (\x -> (f x, g x)) 5 >>> hlint st.hs st.hs:4:17: Warning: Use &&& Found: \ x -> (f x, g x) Why not: f Control.Arrow.&&&…
mb14
  • 22,276
  • 7
  • 60
  • 102
7
votes
3 answers

How to work around the first-order constraint on arrows?

What I mean by first-order constraint First, I'll explain what I mean by first-order constraint on arrows: Due to the way arrows desugar, you cannot use a locally bound name where an arrow command is expected in the arrow do-notation. Here is an…
Jason Dagit
  • 13,684
  • 8
  • 33
  • 56
6
votes
3 answers

Using monads, monoids, functors and arrows in practice

I recently ran into this post about useful resources for different aspects of functional programming, such as monads and monoids, etc. But the question is - what use can an average programmer make out of such concepts. I often run into "academic"…
SPIRiT_1984
  • 2,717
  • 3
  • 29
  • 46
6
votes
3 answers

Comparing list length with arrows

Inspired by Comparing list length If I want to find the longest list in a list of lists, the simplest way is probably: longestList :: [[a]] -> [a] longestList = maximumBy (comparing length) A more efficient way would be to precompute the…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
6
votes
1 answer

Calling an IO Monad inside an Arrow

Perhaps I'm going about this the wrong way, but I'm using HXT to read in some vertex data that I'd like to use in an array in HOpenGL. Vertex arrays need to be a Ptr which is created by calling newArray. Unfortunately newArray returns an IO Ptr, so…
John
  • 452
  • 2
  • 14
6
votes
1 answer

How to implement Factorial via Control.Arrow.loop?

I wonder whether it is possible to implement factorial using Control.Arrow.loop. loop :: ArrowLoop a => a (b, d) (c, d) -> a b c One of the evident ideas is to implement a somehow terminating branch (a branch where the first element of the pair…
Zhiltsoff Igor
  • 1,812
  • 8
  • 24
6
votes
1 answer

Quick question about Arrow operators

Say I've got f :: u -> v -> w and g :: x -> y -> z. What I want is h :: (u,x) -> (v,y) -> (w,z). So I could go about this manually: h (u,x) (v,y) = (f u v, g x y) But where's the fun in that? Using (***) I can get partway there: (f *** g) :: (u,x)…
rampion
  • 87,131
  • 49
  • 199
  • 315
6
votes
1 answer

Counting and filtering Arrow for HXT

I'm trying to parse an XML, but I want to filter and extract only a determinate number of children from a given node. For example: And then if I execute…
Jorge Diz
  • 85
  • 3
6
votes
2 answers

Why are database queries a good place to use Arrows?

I was reading this, which said: Well, the point is that arrow notation forbids some computations that do notation allows. In particular all “arrow actions” must be “statically” known“. and it explains: Statically known" means that if we have a…
6
votes
1 answer

insert label in between a arrow (not below/above) with edge node, tikz

I am trying to draw a graph with an arrow and I would like the label of the arrow to be in between the line (not above or below) like this: how the output should look like : I'm using the tikz library and edge node to draw the arrow between two…
michela
  • 61
  • 1
  • 1
  • 3
6
votes
2 answers

Is there a direct way to combine setters for multiple record fields to a single setter?

import Control.Lens import Control.Lens.TH data Foo = Foo { _bar, _baz :: Int } makeLenses ''Foo Now if I want to modify both int fields, I can do barbaz :: Setter' Foo Int barbaz = sets $ \foo f -> foo & bar %~ f …
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
6
votes
1 answer

Why can't Conduit and Pipe have an Arrow instance?

There is an archived thread on reddit which says essentially conduit/pipes cannot be arrows b/c arrows need to be synchronous. The thread is linked here https://www.reddit.com/r/haskell/comments/rq1q5/conduitssinks_and_refactoring_arrows/ I fail to…
user2812201
  • 437
  • 3
  • 7