Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. [Netwire] Problems constructing a simple Event Wire
(Francesco Ariis)
2. Re: Mutable grid (mike h)
----------------------------------------------------------------------
Message: 1
Date: Tue, 27 Dec 2016 08:49:11 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] [Netwire] Problems constructing a simple
Event Wire
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hello list,
I am learning netwire and decided to write a simple toy program
to get to know the library better. The structure is extremely
simple:
1. a MVar is created and an endless loop fills it with Char
2. a Wire is created (using mkGen_) to provide Events (from the
source described in (1))
3. the final Wire performs some basic filtering/merging on (2)
and outputs a behaviour which is then printed on screen.
[[[ I attach a commented .hs, `main` to test, 'x' and C-c to exit ]]]
The final wire `testWire2 = hold . (keyQ &> keyA)` doesn't work as
expected, i.e. it responds to Q keypresses but not to A ones.
I suspect the problem lies in how I used `mkGen_` to create the
'source' wire, but I am not sure to fix it.
Any help appreciated!
-F
-------------- next part --------------
A non-text attachment was scrubbed...
Name: beginner-netwire.hs
Type: text/x-haskell
Size: 2331 bytes
Desc: not available
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161227/c0585a78/attachment-0001.hs>
------------------------------
Message: 2
Date: Tue, 27 Dec 2016 10:38:34 +0000
From: mike h <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Mutable grid
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi,
In the end I used a set to hold tuples of int pairs (row, col) and manipulated
them
type By = Int
type Row = Int
type Col = Int
type Pixels = Set (Row, Col)
data Screen = Screen
{ maxX :: Col,
maxY :: Row,
pixels :: Pixels
}
Thanks
Mike
> On 24 Dec 2016, at 14:37, Magnus Therning <[email protected]> wrote:
>
> How did it go?
>
> When I solved that AoC problem I ended up using the matrix package:
> http://hackage.haskell.org/package/matrix
> <http://hackage.haskell.org/package/matrix>
>
> /M
>
>
> On 19 Dec 2016 7:31 pm, "mike h" <[email protected]
> <mailto:[email protected]>> wrote:
> Thanks for the pointers - I’ll take a look.
>
> The background to this is one of the puzzles on Advent Of Code 2016 Q.8.
> https://adventofcode.com/2016/day/8 <https://adventofcode.com/2016/day/8>
>
> There are (several hundred) sequential operations on a grid 50 x 6 -
> initially all zeroes
> e.g.
> rotate row y=0 by 4
> rect 2x1 — sets sub grid from (0,0) to (2,1) to all 1s
> rotate column x=35 by 1
>
> I’m fine about parsing the input to a data structure and executing them i.e.
>
> evalExpr :: Expr -> Screen -> Screen — screen is essentially [[Int]]
> evalExpr e s =
> case e of
> (Rect r c ) -> evalRect r c s
> (RotRow r by) -> evalRotRow r by s
> (RotCol c by) -> evalRotCol c by s
> (NOP ) -> id s
>
> rotating a row was simple enough, code to rotate column a bit untidy and not
> very nice. The
> evalRect - which sets values to one in the rectangle of size r x c starting
> at (0,0) top left - triggered the original question.
>
>
> At this point my knowledge of Haskell is being pushed (which is good) but I
> have a feeling that
> my approach is not ‘correct’ once it gets beyond the parsing. Should each of
> the evalRect, evalRotRow and evalRotCol be called with a Screen (i.e. the
> grid at the root of this question)?
> Is the state monad a fit for this problem?
> Should I change my approach or is using vector the way forward?
>
> Many thanks
>
> Mike
>
>
>
>
>
>> On 19 Dec 2016, at 15:27, Michael Orlitzky <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> On 12/19/2016 08:10 AM, mike h wrote:
>>> Hi,
>>>
>>> I’m looking a problem where I have an NxN grid of ints. I need a
>>> function like setValue x y newVal
>>>
>>> I have tried using [[Int]] but it does become messy when splitting ,
>>> dropping and then ++ back together.
>>>
>>> What other options are available to represent a mutable grid?
>>>
>>
>> Mutable vectors (from the vector[1] package) are an obvious choice. When
>> I had to do something similar, I wound up going all the way to repa[2],
>> which magically turns all of your grid operations into parallel ones.
>>
>>
>> [1] https://hackage.haskell.org/package/vector
>> <https://hackage.haskell.org/package/vector>
>> [2] https://hackage.haskell.org/package/repa
>> <https://hackage.haskell.org/package/repa>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected] <mailto:[email protected]>
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161227/f5cc1eaf/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 102, Issue 16
******************************************