Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/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. Re: Designing complex Haskell programs (Courtney Robinson)
2. Re: Designing complex Haskell programs (Bob Ippolito)
3. "Segmentation fault/access violation" when working with FFI
(Leza Morais Lutonda)
4. Help with Data.Aeson json data parsing (Miro Karpis)
5. Re: Help with Data.Aeson json data parsing (Brandon Allbery)
----------------------------------------------------------------------
Message: 1
Date: Fri, 3 Jan 2014 17:57:25 +0000
From: Courtney Robinson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Designing complex Haskell programs
Message-ID:
<cago6xjze_2thq+knqkgigmjaa1ofnyg4fifvzuzj8mdqdyy...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thanks to both of you for your reply.
I have something similar to your example Bob, wasn't sure if it was a good
way forward. Plus it fell apart when I tried contacting multiple hosts on
different threads using forkIO. But with Daniel's response I'll look into
MVars.
Thanks again
On Fri, Jan 3, 2014 at 5:16 PM, Bob Ippolito <[email protected]> wrote:
> Generally speaking, state lives on the call stack in functional
> programming languages that have tail call elimination. Modification of the
> state is done by recursion with a new value for the state. This is more or
> less equivalent to a "do while" loop in imperative programming.
>
> myServer :: State -> IO ()
> myServer state = do
> state' <- updateState state
> myServer state'
>
> For the concurrency, Control.Concurrent or Cloud Haskell (for a higher
> level Erlang-like approach) is probably the way to go here. Parallel and
> Concurrent Programming in Haskell is a great resource:
> http://chimera.labs.oreilly.com/books/1230000000929
>
>
> On Fri, Jan 3, 2014 at 8:45 AM, Courtney Robinson <[email protected]>wrote:
>
>> I'm trying to take the training wheels of and moving more of my code base
>> to Haskell from C++ but finding it increasingly tricky.
>>
>> I have a subset of a gossip protocol written in C++.
>> When a server comes online it connects to 1 or more nodes already in the
>> cluster and get data from them about other nodes they know of.
>>
>> The new node merges the information and keeps a copy of the merged view.
>> Every so often it contacts the nodes it knows about and refreshes the
>> merged view. It also must have the up to date view ready to be sent in
>> response to a new node joining.
>>
>> I currently can't wrap my head around how to maintain this state. How
>> would a more experienced Haskeller approach this problem? Code is OK if it
>> demonstrates a particular point but I'm more interested in the line of
>> thought that would go into designing a solution as I suspect that'll be
>> more useful as I get further into the migration.
>>
>> As a gauge to you for my current level in Haskell. I read and understand
>> most Haskell programs fine. I write some but currently heavily rely on
>> hackage/hoogle docs for APIs, even some common ones.
>>
>> Thanks
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Courtney Robinson
[email protected]
http://crlog.info
07535691628 (No private #s)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140103/91b8534b/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 3 Jan 2014 10:17:13 -0800
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Designing complex Haskell programs
Message-ID:
<CACwMPm9ZqEM82XC735yf98JNgN+ALotA+w-fP4TtrYMuuu1=t...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I wouldn't recommend going down the path of using IORef or MVar for
everything, it's not easy to build robust systems that way. Do you mind
showing the code that you tried that "fell apart"? I'm sure there's a
slightly different way to structure it that would work just fine, probably
using some kind of message passing.
On Fri, Jan 3, 2014 at 9:57 AM, Courtney Robinson <[email protected]>wrote:
> Thanks to both of you for your reply.
> I have something similar to your example Bob, wasn't sure if it was a good
> way forward. Plus it fell apart when I tried contacting multiple hosts on
> different threads using forkIO. But with Daniel's response I'll look into
> MVars.
>
> Thanks again
>
>
> On Fri, Jan 3, 2014 at 5:16 PM, Bob Ippolito <[email protected]> wrote:
>
>> Generally speaking, state lives on the call stack in functional
>> programming languages that have tail call elimination. Modification of the
>> state is done by recursion with a new value for the state. This is more or
>> less equivalent to a "do while" loop in imperative programming.
>>
>> myServer :: State -> IO ()
>> myServer state = do
>> state' <- updateState state
>> myServer state'
>>
>> For the concurrency, Control.Concurrent or Cloud Haskell (for a higher
>> level Erlang-like approach) is probably the way to go here. Parallel and
>> Concurrent Programming in Haskell is a great resource:
>> http://chimera.labs.oreilly.com/books/1230000000929
>>
>>
>> On Fri, Jan 3, 2014 at 8:45 AM, Courtney Robinson <[email protected]>wrote:
>>
>>> I'm trying to take the training wheels of and moving more of my code
>>> base to Haskell from C++ but finding it increasingly tricky.
>>>
>>> I have a subset of a gossip protocol written in C++.
>>> When a server comes online it connects to 1 or more nodes already in the
>>> cluster and get data from them about other nodes they know of.
>>>
>>> The new node merges the information and keeps a copy of the merged view.
>>> Every so often it contacts the nodes it knows about and refreshes the
>>> merged view. It also must have the up to date view ready to be sent in
>>> response to a new node joining.
>>>
>>> I currently can't wrap my head around how to maintain this state. How
>>> would a more experienced Haskeller approach this problem? Code is OK if it
>>> demonstrates a particular point but I'm more interested in the line of
>>> thought that would go into designing a solution as I suspect that'll be
>>> more useful as I get further into the migration.
>>>
>>> As a gauge to you for my current level in Haskell. I read and understand
>>> most Haskell programs fine. I write some but currently heavily rely on
>>> hackage/hoogle docs for APIs, even some common ones.
>>>
>>> Thanks
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
>
> --
> Courtney Robinson
> [email protected]
> http://crlog.info
> 07535691628 (No private #s)
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140103/d8bb0009/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 03 Jan 2014 16:45:38 -0800
From: Leza Morais Lutonda <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] "Segmentation fault/access violation"
when working with FFI
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
I has trying to use the portaudio [1] package to play some sound, and
running the examples [2] results in "Segmentation fault/access
violation" error.
How can I solve this problem?
Thanks.
[1] http://hackage.haskell.org/package/portaudio
[2] https://github.com/sw17ch/portaudio/blob/master/examples/Example1.h
------------------------------
Message: 4
Date: Sat, 4 Jan 2014 00:42:33 +0100
From: Miro Karpis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Help with Data.Aeson json data parsing
Message-ID:
<CAJnnbxFbSYW1KOsmeNcpx6g9HkrUt6rBm=jcqitkc0q0v23...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi, please can you help me with following? I'm trying to parse one json
(simplified version below), but I keep getting:
"when expecting a record (:*:), encountered Array instead"
code:
------------
data SomeData = SomeData {
v1 :: Int,
v2 :: Int
} deriving (Show, Generic)
data SomeDataPack = SomeDataPack{
pack :: [SomeData]
} deriving (Show, Generic)
instance FromJSON SomeData
instance FromJSON SomeDataPack
parsedata :: IO (Maybe SomeDataPack)
parsedata = do
let x = "[{\"v1\":11,\"v2\":12},{\"v1\":13,\"v2\":14}]";
case (eitherDecode' x :: Either String SomeDataPack) of
Right r -> do
putStrLn $ show r
return $ Just r
Left e -> do
putStrLn $ show e
return Nothing
thanks,
m.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140104/cd5870fa/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 3 Jan 2014 18:48:49 -0500
From: Brandon Allbery <[email protected]>
To: Miro Karpis <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Help with Data.Aeson json data
parsing
Message-ID:
<cakfcl4wzduo4tpcjglgutekj34+dzrjm03qankh77vgjvby...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Fri, Jan 3, 2014 at 6:42 PM, Miro Karpis <[email protected]>wrote:
> data SomeDataPack = SomeDataPack{
> pack :: [SomeData]
> } deriving (Show, Generic)
>
Isn't this going to be a record? {"pack": [an array goes here]} just as
with the preceding definition, but with only a single field.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140103/79dfa8be/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 67, Issue 6
****************************************