Elise Huard | 4 Mar 10:32 2015
Picon

command-line interaction with running process

Hi,

I'm trying to do the following: implementing a command-line interface
to directly interact with the state or the parameters of a
looping/running process (a game, to be specific).

My first thought is to fork a thread, passing in a TChan/TVar or
similar to enable communication, and to have the command-line
interface on the thread (getLine or haskelline ...).
Another option would be to have a bona fide server-client interface
(with sockets or others), to fork a thread again to run the server and
to connect using the client library - which would allow me to use ghci
and have transparent serialization under the hood.

Are there known use cases?  Am I missing something, for instance is it
possible to interact with a running process directly using ghci?
Any tips?

Thank you,

Elise
Michael Jones | 4 Mar 07:50 2015

Google Summer of Code

If any students are interested in Google Summer of Code projects, there is a Minnow Board project here:

http://elinux.org/Minnowboard:GSoC2015

There is a Haskell project listed in the SMBus/PMBus section.

Mike
Richard Guay | 4 Mar 06:38 2015

Alfred Programs in Haskell

Hi,

I am using Haskell to write Alfred programs, but I have run into an issue I just can not fix. The routine for reading a data file in a application specific location for Alfred never detects the file as non-existant. It then dies on the read. Here is the code:

getAlfredCacheFileContents :: String -> IO (String)
getAlfredCacheFileContents fileName = do
    h <- getHomeDirectory
    fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName
    if fExist
    then do
        contents <- readFile $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName
        return contents
    else
        return ""

I just installed the latest version on my Mac Air. It always does the call to readFile, even when the file doesn't exist.
--
Sent with Postbox
<div>
Hi,<br><br>
I am using Haskell to write Alfred programs, but I have run into an 
issue I just can not fix. The routine for reading a data file in a 
application specific location for Alfred never detects the file as 
non-existant. It then dies on the read. Here is the code:<br><br>
getAlfredCacheFileContents :: String -&gt; IO (String)<br>
getAlfredCacheFileContents fileName = do<br>
&nbsp;&nbsp;&nbsp; h &lt;- getHomeDirectory<br>
&nbsp;&nbsp;&nbsp; fExist &lt;- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++ 
"/" ++ fileName<br>
&nbsp;&nbsp;&nbsp; if fExist<br>
&nbsp;&nbsp;&nbsp; then do<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contents &lt;- readFile $ h ++ cacheDirBasic ++ getBundleID ++ 
"/" ++ fileName<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return contents<br>
&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return ""<br><br>
I just installed the latest version on my Mac Air. It always does the 
call to readFile, even when the file doesn't exist.<br><div class="moz-signature">-- <br><div>Sent with <a href="http://www.getpostbox.com"><span>Postbox</span></a>
</div>
</div>
</div>
'2+ | 4 Mar 04:22 2015
Picon

fractal x = fractal [y - head x + z | y <- x, z <- x] with take doesnt end

hi!
since my

fractal :: [Int] -> [Int]
fractal x = [y - head x + z | y <- x, z <- x]

seems to be working fine with something like:

take 300 $ cycle $ fractal $ fractal $ [11..17] ++ [55..77]

wanted to twist the function to something totally recursive
but:

fractal x = fractal [y - head x + z | y <- x, z <- x]

experimented with:

take 300 $ fractal $ [11..17] ++ [55..77]

doesnt end its process and eat up the RAM

any hints to solve this issue?

thank you

----- 2g ---
http://sarigama.namaste.jp

emacstheviking | 3 Mar 21:19 2015
Picon

LTS is good but...

I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available.

The very next time I tried to work on my code.... I got this:

bash-3.2$ pwd
/Users/seancharles/Documents/Coding/haskell/lts1
bash-3.2$ cabal build
cabal: You need to re-run the 'configure' command. The version of Cabal being
used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0).
bash-3.2$ cabal configure
Resolving dependencies...
Configuring lts1-0.1.0.0...
cabal: At least the following dependencies are missing:
base ==4.7.*
bash-3.2$ cabal build
cabal: You need to re-run the 'configure' command. The version of Cabal being
used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0).
bash-3.2$ ls -l
total 112
-rw-r--r--  1 seancharles  staff     19 Mar  2 12:53 LICENCSE
-rw-r--r--  1 seancharles  staff    552 Mar  3 20:09 Main.hs
-rw-r--r--  1 seancharles  staff    477 Mar  3 20:07 Main.hs~
-rw-r--r--  1 seancharles  staff     46 Mar  2 12:52 Setup.hs
-rw-r--r--  1 seancharles  staff  30198 Mar  2 12:51 cabal.config
-rw-r--r--  1 seancharles  staff   1090 Mar  2 12:51 cabal.sandbox.config
drwxr-xr-x  5 seancharles  staff    170 Mar  2 12:53 dist
-rw-r--r--  1 seancharles  staff   1932 Mar  2 12:52 lts1.cabal
bash-3.2$ 

So, welcome to a different kind of hell, "cabal version hell" perhaps?

Can anybody help me get it running again?
Thanks.
Sean.

<div><div dir="ltr">I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available.<div><br></div>
<div>The very next time I tried to work on my code.... I got this:</div>
<div><br></div>
<div>
<div>bash-3.2$ pwd</div>
<div>/Users/seancharles/Documents/Coding/haskell/lts1</div>
<div>bash-3.2$ cabal build</div>
<div>cabal: You need to re-run the 'configure' command. The version of Cabal being</div>
<div>used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0).</div>
<div>bash-3.2$ cabal configure</div>
<div>Resolving dependencies...</div>
<div>Configuring lts1-0.1.0.0...</div>
<div>cabal: At least the following dependencies are missing:</div>
<div>base ==4.7.*</div>
<div>bash-3.2$ cabal build</div>
<div>cabal: You need to re-run the 'configure' command. The version of Cabal being</div>
<div>used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0).</div>
<div>bash-3.2$ ls -l</div>
<div>total 112</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; &nbsp; 19 Mar &nbsp;2 12:53 LICENCSE</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; &nbsp;552 Mar &nbsp;3 20:09 Main.hs</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; &nbsp;477 Mar &nbsp;3 20:07 Main.hs~</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; &nbsp; 46 Mar &nbsp;2 12:52 Setup.hs</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp;30198 Mar &nbsp;2 12:51 cabal.config</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; 1090 Mar &nbsp;2 12:51 cabal.sandbox.config</div>
<div>drwxr-xr-x &nbsp;5 seancharles &nbsp;staff &nbsp; &nbsp;170 Mar &nbsp;2 12:53 dist</div>
<div>-rw-r--r-- &nbsp;1 seancharles &nbsp;staff &nbsp; 1932 Mar &nbsp;2 12:52 lts1.cabal</div>
<div>bash-3.2$&nbsp;</div>
</div>
<div><br></div>
<div>So, welcome to a different kind of hell, "cabal version hell" perhaps?</div>
<div><br></div>
<div>Can anybody help me get it running again?</div>
<div>Thanks.</div>
<div>Sean.</div>
<div><br></div>
</div></div>
Song Zhang | 3 Mar 15:41 2015
Picon

"Template Haskell and higher order meta programming."

I generally have 2 questions. I am writing some functions to derive typeclass instances with a package called derive. I just want to get rid of using Derivation type with a stupid reason. I want use just Name type.

How can I defined a function with type 

derivings :: Name -> Name -> Q [Dec]

by using function derive :: Derivation -> Name -> Q [Dec]
so that user can just write derivings ''Eq ''D instead of derive makeEq ''D?

> {-# LANGUAGE TemplateHaskell #-}

> import Data.DeriveTH -- in derive package
> import qualified Language.Haskell.TH.Syntax as S
> data D = D
> derivings :: Name -> String -> Q Exp
> derivings cla typ = do
>               let makeClassName = mkName $ "make" ++ nameBase cla
>               a <-  [| derive makeClassName (mkName typ) |]
>               return a

> instance S.Lift Name where
>         lift x = varE x

Main> :t derivings ''Eq "D"
derivings ''Eq "D" :: Q Exp

Main> :t $(derivings ''Eq "D")
$(derivings ''Eq "D") :: Q [Dec]

There is no problem to quote twice in other file in order to get the declaration. Maybe it should called second order meta programming. But the following has problems:

> derivings'' :: Name -> Name -> Q Exp
> derivings'' cla typ = do
>               let makeClassName = mkName $ "make" ++ nameBase cla
>               a <-  [| derive makeClassName typ |]
>               return a

Main> :t derivings''
derivings'' :: Name -> Name -> Q Exp

Main> :t derivings'' ''Eq ''D
derivings'' ''Eq ''D :: Q Exp

Main> :t $(derivings'' ''Eq ''D)
<interactive>:1:3:
    Illegal variable name: ‘D’
    When splicing a TH expression:
      Data.DeriveTH.derive makeEq (Language.Haskell.TH.Syntax.mkName Main.D)
    In the splice: $(derivings'' ''Eq ''D)

In the first case I used String, it works. however, it is not workiing if I use D with a Name type. Cannot figure it out.
My second question is that if my return type is Q [Exp] while the [Exp] can be further expanded into [Dec]. How can I do it to expand [Exp] into [Dec]? Do we have a function for $ in $(thcode_with_Q_Exp) so that I do not need to splice each Exp value?

Best wishes
Song
<div><div dir="ltr">
<div>I generally have 2 questions. I am writing some functions to derive typeclass instances with a package called derive. I just want to get rid of using Derivation type with a stupid reason. I want use just Name type.</div>
<div><br></div>
<div>How can I defined a function with type&nbsp;</div>
<div><br></div>
<div>derivings :: Name -&gt; Name -&gt; Q [Dec]</div>
<div><br></div>
<div>by using function derive :: Derivation -&gt; Name -&gt; Q [Dec]</div>
<div>so that user can just write derivings ''Eq ''D instead of derive makeEq ''D?</div>
<div><br></div>
<div>&gt; {-# LANGUAGE TemplateHaskell #-}</div>
<div><br></div>
<div>&gt; import Data.DeriveTH -- in derive package</div>
<div>&gt; import <a href="http://Language.Haskell.TH">Language.Haskell.TH</a>
</div>
<div>&gt; import qualified Language.Haskell.TH.Syntax as S</div>
<div>&gt; data D = D</div>
<div>&gt; derivings :: Name -&gt; String -&gt; Q Exp</div>
<div>&gt; derivings cla typ = do</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let makeClassName = mkName $ "make" ++ nameBase cla</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &lt;- &nbsp;[| derive makeClassName (mkName typ) |]</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return a</div>
<div><br></div>
<div>&gt; instance S.Lift Name where</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; lift x = varE x</div>
<div><br></div>
<div>Main&gt; :t derivings ''Eq "D"</div>
<div>derivings ''Eq "D" :: Q Exp</div>
<div><br></div>
<div>Main&gt; :t $(derivings ''Eq "D")</div>
<div>$(derivings ''Eq "D") :: Q [Dec]</div>
<div><br></div>
<div>There is no problem to quote twice in other file in order to get the declaration. Maybe it should called second order meta programming. But the following has problems:</div>
<div><br></div>
<div>&gt; derivings'' :: Name -&gt; Name -&gt; Q Exp</div>
<div>&gt; derivings'' cla typ = do</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let makeClassName = mkName $ "make" ++ nameBase cla</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &lt;- &nbsp;[| derive makeClassName typ |]</div>
<div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return a</div>
<div><br></div>
<div>Main&gt; :t derivings''</div>
<div>derivings'' :: Name -&gt; Name -&gt; Q Exp</div>
<div><br></div>
<div>Main&gt; :t derivings'' ''Eq ''D</div>
<div>derivings'' ''Eq ''D :: Q Exp</div>
<div><br></div>
<div>Main&gt; :t $(derivings'' ''Eq ''D)</div>
<div>&lt;interactive&gt;:1:3:</div>
<div>&nbsp; &nbsp; Illegal variable name: &lsquo;D&rsquo;</div>
<div>&nbsp; &nbsp; When splicing a TH expression:</div>
<div>&nbsp; &nbsp; &nbsp; Data.DeriveTH.derive makeEq (Language.Haskell.TH.Syntax.mkName Main.D)</div>
<div>&nbsp; &nbsp; In the splice: $(derivings'' ''Eq ''D)</div>
<div><br></div>
<div>In the first case I used String, it works. however, it is not workiing if I use D with a Name type. Cannot figure it out.</div>
<div>My second question is that if my return type is Q [Exp] while the [Exp] can be further expanded into [Dec]. How can I do it to expand [Exp] into [Dec]? Do we have a function for $ in $(thcode_with_Q_Exp) so that I do not need to splice each Exp value?</div>
<div><br></div>
<div>Best wishes</div>
<div>Song</div>
</div></div>
Picon

CodeWarriors -- Spreading the word

I just found out about www.codewarriors.com, and wanted to spread the word.
It's a good place for beginners to get questions in increasing order of complexity.

Best.

--
Regards

Sumit Sahrawat
<div><div dir="ltr">I just found out about <a href="http://www.codewarriors.com">www.codewarriors.com</a>, and wanted to spread the word.<div>It's a good place for beginners to get questions in increasing order of complexity.</div>
<div><br></div>
<div>Best.<br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr">
<div>Regards</div>
<div dir="ltr">
<div><br></div>
<div>Sumit Sahrawat</div>
</div>
</div></div></div></div></div>
</div>
</div></div>
emacstheviking | 2 Mar 14:06 2015

Re: trying to install libraries for Haskell School of Expression

PS: Did you mean stackage .ORG not .COM


On 2 March 2015 at 13:04, emacstheviking <sean <at> objitsu.com> wrote:
Plunk! (penny drops)
I get it...now that is truly the icing on the cabal-hell free cake!
Thanks again Julian.


On 2 March 2015 at 12:48, Julian Birch <julian.birch <at> gmail.com> wrote:
If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. It'll give you search results for everything in LTS 1.10.


On Monday, March 2, 2015, emacstheviking <sean <at> objitsu.com> wrote:
What does that do for me within LTS confines? I know Hoogle, but I don't understand what you mean by "they run a hoogle for the exact version, with every library." ...I just want to understand so I can be as excited as everybody else right now! LOL :)


On 2 March 2015 at 12:34, Julian Birch <julian.birch <at> gmail.com> wrote:

It gets better: they run a hoogle for the exact version, with every library. :)

On Monday, March 2, 2015, emacstheviking <sean <at> objitsu.com> wrote:
Took a while to sink in....DEF trying this out tonight
Looks AWESOME if it does what it says!
Getting excited about Haskell again.
THANKS!!!! Yoohoo :)


On 2 March 2015 at 12:10, Julian Birch <julian.birch <at> gmail.com> wrote:
Just a small note: if you're suffering from cabal hell, LTS Haskell may help you. I described how to use it here:


Hope someone finds it useful.

J


On Monday, March 2, 2015, emacstheviking <sean <at> objitsu.com> wrote:
Agreed. I will "finish" with a mild semi-demi-rant too regarding the assumption by a lot of posters that we are all academics with access to papers on this and that. I am not and I don't. If you cite a paper, make sure it's available to Joe Public please!

As for only sticking to plain vanialla simple Haskell, yes, that works BUT there are some many great libraries that a real time savers...it's such a shame when they won't play well together!

So, despite it all, tonight I will be hacking Haskell !

:)


On 1 March 2015 at 19:27, DJ <jakep <at> arqux.com> wrote:
Yeah. I think there are a lot of us out there. I won't rant (much) here, because I hope to get some help from time to time. Alienating people is not a good way to get help.

But:

There are many things I like about the language, but I have always been perplexed by the haskell ecosystem in a couple of ways. However good and/or interesting a language might be, it is not possible to do meat and potatoes development unless there is a good supply of packages/libraries.

My first problem was that I often just could not get stuff to install. The second problem was documentation. I hope it has improved a bit. I was always flabbergasted at the (apparent) belief that a few lines of API documentation coughed out by haddock are enough. But that's all there was in a lot of cases. That, and "refer to xxxx research paper" and "figure it out from the types". Hah. Any math paper that consisted of just the equations sorted in alphabetical order would not be well received, I think.

I really admired that fact that Michael Snoyman wrote a book about Yesod. For all I know he may not have kept the book up, but at least he realized that people needed an explanation of how to use his software.

Well, back to work. I am going to give haskell another try for sure. It's just too tempting to give up on. If it doesn't work, the next stop will be sml or ocaml.

Best,

- DJ -


On 15-03-01 09:56 AM, emacstheviking wrote:
I feel your pain...
 
Confession: I abandoned Haskell two years ago because of frustration with cabal and hackage. I decided to get back to the language today, and to start with Haskell School of Expression. I immediately run into the problem that the first thing I try to install with cabal does not work.

It is the same reason I have stopped using it. It's a real shame. Those with better education and understanding than mine should be concerned that the uptake of the language is stunted by its package manager.

I love Haskell. I have taught myself (the beginnings at least) of group theory just to better comprehend the mindset of monads. For that alone I am glad I learned Haskell as it has rekindled my interest in maths!

 
Thanks for any help. Please tell me things are not just as bad now as they were when I left ;-)

This mail seems to indicate to me that "cabal hell" is here for some time to come...
 



_______________________________________________ Beginners mailing list Beginners <at> haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




--
Sent from an iPhone, please excuse brevity and typos.

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




--
Sent from an iPhone, please excuse brevity and typos.

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




--
Sent from an iPhone, please excuse brevity and typos.

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



<div>
<div dir="ltr">PS: Did you mean stackage .ORG not .COM<div><br></div>
</div>
<div class="gmail_extra">
<br><div class="gmail_quote">On 2 March 2015 at 13:04, emacstheviking <span dir="ltr">&lt;<a href="mailto:sean <at> objitsu.com" target="_blank">sean <at> objitsu.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">Plunk! (penny drops)<div>I get it...now that is truly the icing on the cabal-hell free cake!</div>
<div>Thanks again Julian.</div>
<div><br></div>
</div>
<div class="HOEnZb"><div class="h5">
<div class="gmail_extra">
<br><div class="gmail_quote">On 2 March 2015 at 12:48, Julian Birch <span dir="ltr">&lt;<a href="mailto:julian.birch <at> gmail.com" target="_blank">julian.birch <at> gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">If you go to <a href="http://www.stackage.com/lts/1.10" target="_blank">www.stackage.com/lts/1.10</a>, you'll find a hoogle search&nbsp;<span></span>box. It'll give you search results for everything in LTS 1.10.<div><div>
<br><br>On Monday, March 2, 2015, emacstheviking &lt;<a href="mailto:sean <at> objitsu.com" target="_blank">sean <at> objitsu.com</a>&gt; wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">What does that do for me within LTS confines? I know Hoogle, but I don't understand what you mean by "<span>they run a hoogle for the exact version, with every library." ...I just want to understand so I can be as excited as everybody else right now! LOL :)</span><div><span><br></span></div>
</div>
<div class="gmail_extra">
<br><div class="gmail_quote">On 2 March 2015 at 12:34, Julian Birch <span dir="ltr">&lt;<a>julian.birch <at> gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<br>It gets better: they run a hoogle for the exact version, with every library. :)<div><div>
<div>
<span></span><br>On Monday, March 2, 2015, emacstheviking &lt;<a>sean <at> objitsu.com</a>&gt; wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">Took a while to sink in....DEF trying this out tonight<div>Looks AWESOME if it does what it says!</div>
<div>Getting excited about Haskell again.</div>
<div>THANKS!!!! Yoohoo :)</div>
<div><br></div>
</div>
<div class="gmail_extra">
<br><div class="gmail_quote">On 2 March 2015 at 12:10, Julian Birch <span dir="ltr">&lt;<a>julian.birch <at> gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">Just a small note: if you're suffering from cabal hell, LTS Haskell may help you. I described how to use it here:<div><br></div>
<div><a href="http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx" target="_blank">http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx</a></div>
<div><br></div>
<div>Hope someone finds it useful.</div>
<div><br></div>
<div>J<div><div>
<span></span><br><br>On Monday, March 2, 2015, emacstheviking &lt;<a>sean <at> objitsu.com</a>&gt; wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">Agreed. I will "finish" with a mild semi-demi-rant too regarding the assumption by a lot of posters that we are all academics with access to papers on this and that. I am not and I don't. If you cite a paper, make sure it's available to Joe Public please!<div><br></div>
<div>As for only sticking to plain vanialla simple Haskell, yes, that works BUT there are some many great libraries that a real time savers...it's such a shame when they won't play well together!</div>
<div><br></div>
<div>So, despite it all, tonight I will be hacking Haskell !</div>
<div><br></div>
<div>:)<br><br>
</div>
</div>
<div class="gmail_extra">
<br><div class="gmail_quote">On 1 March 2015 at 19:27, DJ <span dir="ltr">&lt;<a>jakep <at> arqux.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">

    

  <div bgcolor="#FFFFFF" text="#000000">
    Yeah. I think there are a lot of us out there. I won't rant (much)
    here, because I hope to get some help from time to time. Alienating
    people is not a good way to get help.<br><br>
    But:<br><br>
    There are many things I like about the language, but I have always
    been perplexed by the haskell ecosystem in a couple of ways. However
    good and/or interesting a language might be, it is not possible to
    do meat and potatoes development unless there is a good supply of
    packages/libraries.<br><br>
    My first problem was that I often just could not get stuff to
    install. The second problem was documentation. I hope it has
    improved a bit. I was always flabbergasted at the (apparent) belief
    that a few lines of API documentation coughed out by haddock are
    enough. But that's all there was in a lot of cases. That, and "refer
    to xxxx research paper" and "figure it out from the types". Hah. Any
    math paper that consisted of just the equations sorted in
    alphabetical order would not be well received, I think.<br><br>
    I really admired that fact that Michael Snoyman wrote a book about
    Yesod. For all I know he may not have kept the book up, but at least
    he realized that people needed an explanation of how to use his
    software.<br><br>
    Well, back to work. I am going to give haskell another try for sure.
    It's just too tempting to give up on. If it doesn't work, the next
    stop will be sml or ocaml.<br><br>
    Best,<br><br>
    - DJ -<div><div>
<br><br><div>On 15-03-01 09:56 AM, emacstheviking
      wrote:<br>
</div>
    </div></div>
<blockquote type="cite">
<div><div>
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>I feel your pain...</div>
            <div>&nbsp;</div>
            <blockquote class="gmail_quote">
              Confession: I abandoned Haskell two years ago because of
              frustration with cabal and hackage. I decided to get back
              to the language today, and to start with Haskell School of
              Expression. I immediately run into the problem that the
              first thing I try to install with cabal does not work.<br><br>
</blockquote>
            <div>It is the same reason I have stopped using it. It's a
              real shame. Those with better education and understanding
              than mine should be concerned that the uptake of the
              language is stunted by its package manager.</div>
            <div><br></div>
            <div>I love Haskell. I have taught myself (the beginnings at
              least) of group theory just to better comprehend the
              mindset of monads. For that alone I am glad I learned
              Haskell as it has rekindled my interest in maths!</div>
            <div><br></div>
            <div>&nbsp;</div>
            <blockquote class="gmail_quote">
              Thanks for any help. Please tell me things are not just as
              bad now as they were when I left ;-)<br><br>
</blockquote>
            <div>This mail seems to indicate to me that "cabal hell" is
              here for some time to come...</div>
            <div>&nbsp;</div>
            <div><br></div>
          </div>
        </div>
      </div>
      <br><br>
</div></div>
<span>_______________________________________________
Beginners mailing list
<a>Beginners <at> haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>

    </span>
</blockquote>
    <br>
</div>

<br>_______________________________________________<br>
Beginners mailing list<br><a>Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div></div>
</div>
<span><br><br>-- <br>Sent from an iPhone, please excuse brevity and typos.<br></span><br>_______________________________________________<br>
Beginners mailing list<br><a>Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
<br><br>-- <br>Sent from an iPhone, please excuse brevity and typos.<br>
</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br><a>Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br><br>-- <br>Sent from an iPhone, please excuse brevity and typos.<br>
</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br><a href="mailto:Beginners <at> haskell.org" target="_blank">Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
<br>
</div>
</div></div>
</blockquote>
</div>
<br>
</div>
</div>
DJ | 1 Mar 05:40 2015

trying to install libraries for Haskell School of Expression

Trying to install the package soegtk.

I am running linux mint 17 with the latest (as of Feb. 28) haskell 
platform and cabal-install.

I did install gtk2hs-buildtools and put the .cabal/bin in my path.

Cannot install soegtk:

Failed to install glib-0.12.5.4
cabal: Error: some packages failed to install:
cairo-0.12.5.3 failed during the configure step. The exception was:
ExitFailure 1
gio-0.12.5.3 depends on glib-0.12.5.4 which failed to install.
glib-0.12.5.4 failed during the configure step. The exception was:
ExitFailure 1
gtk-0.12.5.7 depends on glib-0.12.5.4 which failed to install.
pango-0.12.5.3 depends on glib-0.12.5.4 which failed to install.
soegtk-0.12.1 depends on glib-0.12.5.4 which failed to install.

Confession: I abandoned Haskell two years ago because of frustration 
with cabal and hackage. I decided to get back to the language today, and 
to start with Haskell School of Expression. I immediately run into the 
problem that the first thing I try to install with cabal does not work.

Thanks for any help. Please tell me things are not just as bad now as 
they were when I left ;-)

- DJP -

Thomas Jakway | 28 Feb 14:20 2015
Picon

FFI Problems

I'm very new to Haskell and am trying to write a "real" program to motivate myself to learn it better (so far I've only gotten through Project Euler problems after reading LYAH and most of RWH).  I'm using Taglib (https://github.com/taglib/taglib) to read the metadata from a music file and print it.  I have a struct C-side (with C linkage) serving as the bridge between Taglib's C++ and Haskell's FFI.  A small demo program (compiled with gcc and linked against the C++ object files) gives the correct results, but Haskell is weirdly only getting some of it right.  Specifically, the C string fields are working but ints are not.

The output from the C demo (what Haskell should be printing):

music_metadata
title: It's My Life,    artist: Bon Jovi,    album: Bon Jovi Greatest Hits - The Ultimate Collection
comment: ,    genre: Rock,    track: 3,
length: 224,    bitrate: 256,    channels: 2,
codec: 768

The output from Haskell:

MusicMetadata {codec = UNKNOWN, length = 1099511628000, bitrate = 8589934848, channels = 12884901890, track = 8589934848, title = "It's My Life", artist = "Bon Jovi", album = "Bon Jovi Greatest Hits - The Ultimate Collection", comment = "", genre = "Rock"}

I would have expected it to work or not work at all, but did not anticipate getting only some of it right.

I was going to include snippets from my hsc file but given how new I am to Haskell I don't trust myself to assume where the problem is, so sorry if this is way too long:

{-# LANGUAGE CPP, ForeignFunctionInterface #-}

module MusicReader
( Codec,
  MusicMetadata,
  readMusicMetadata
) where

import Control.Monad
import Foreign
import Foreign.C.Types
import Foreign.C.String
import System.IO.Unsafe as Unsafe

#include "CodecDefines.h"
#include "MusicReader.h"

constantToCodec code
                    | code == mp3 = MP3
                    | code == flac = FLAC
                    | code == ogg = OGG_VORBIS
                    | code == mp4 = MP4
                    | code == mpeg = MPEG
                    | code == none = NONE
                    | code == unknown = UNKNOWN
                    | otherwise = UNKNOWN
                       where mp3 = #const MP3_CODEC
                             flac = #const FLAC_CODEC
                             ogg = #const OGG_VORBIS_CODEC
                             mp4 = #const MP4_CODEC
                             mpeg = #const MPEG_CODEC
                             none = #const NO_EXTENSION
                             unknown = #const UNKNOWN_EXTENSION

data Codec = MP3 | FLAC | OGG_VORBIS | MP4 | MPEG | NONE | UNKNOWN deriving (Show)

data MusicMetadata = MusicMetadata { codec :: Codec,
                      length :: Int,
                      bitrate :: Int,
                      channels :: Int,
                      track :: Int,
                      title :: String,
                      artist :: String,
                      album :: String,
                      comment :: String,
                      genre :: String } deriving (Show)

instance Storable MusicMetadata where
    sizeOf _ = (#size struct music_metadata)
    alignment _ = alignment (undefined::CDouble)
    peek a = do
        codec <- liftM constantToCodec $ (((#peek struct music_metadata, codec) a) :: IO Int)
        length <- ((#peek struct music_metadata, length) a) :: IO Int
        bitrate <- ((#peek struct music_metadata, bitrate) a) :: IO Int
        channels <- ((#peek struct music_metadata, channels) a) :: IO Int
        track <- ((#peek struct music_metadata, bitrate) a) :: IO Int
        title <-  ((#peek struct music_metadata, title) a) :: IO CString
        artist <- ((#peek struct music_metadata, artist) a) :: IO CString
        album <- ((#peek struct music_metadata, album) a) :: IO CString
        comment <- ((#peek struct music_metadata, comment) a) :: IO CString
        genre <- ((#peek struct music_metadata, genre) a) :: IO CString
        --FIXME: find replacement for temporary names
        marshalledTitle <- peekCString title
        marshalledArtist <- peekCString artist
        marshalledAlbum <- peekCString album
        marshalledComment <- peekCString comment
        marshalledGenre <- peekCString genre
        return (MusicMetadata codec length bitrate channels track marshalledTitle marshalledArtist marshalledAlbum marshalledComment marshalledGenre)
    poke a = undefined

--This is the "primitive" FFI call--calls the C function and gets a pointer
--in return
--TODO: write a higher level function this module should export that calls
--primReadMusicMetadata and converts the C Pointer into the Haskell data
--MusicMetadata
foreign import ccall unsafe "read_metadata" primReadMusicMetadata :: CString -> IO (Ptr MusicMetadata)

--convert the Haskell string to a CString, call into the FFI then
--dereference the resulting pointer
readMusicMetadata a = join $ withCString a $ \cs -> ((liftM peek) $ primReadMusicMetadata cs)



Here's the struct in MusicReader.h (in an extern C block):
    struct music_metadata
    {
        int codec;
        int length,
                bitrate,
                channels;
        int track;
        char *title,
             *artist,
             *album,
             *comment,
             *genre;
    };


with the corresponding call:
    struct music_metadata* read_metadata(char*);


I've tried playing around with the alignment but it didn't do anything.  I also tried declaring the struct's fields as int32_t which also did nothing.

The C demo in question is a very simple:

#include <stdio.h>
#include "MusicReader.h"

#define FILENAME "Its_My_Life.m4a"

int main()
{
    struct music_metadata* metadata = read_metadata(FILENAME);  
    printf("music_metadata\ntitle: %s,\tartist: %s,\talbum: %s\n",
            metadata->title, metadata->artist, metadata->album);
    printf("comment: %s,\tgenre: %s,\ttrack: %d,\n",
            metadata->comment, metadata->genre, metadata->track);
    printf("length: %d,\tbitrate: %d,\tchannels: %d,\n",
            metadata->length, metadata->bitrate, metadata->channels);
    printf("codec: %d\n");

}

It just reads the metadata into the struct and prints the fields.

I've gotten the impression of the Haskell FFI being very beginner-unfriendly, which isn't surprising but still disappointing because it would be a great opportunity to replace some projects with Haskell.

Any help is appreciated, including general feedback on my code!
<div>
    I'm very new to Haskell and am trying to write a "real" program to
    motivate myself to learn it better (so far I've only gotten through
    Project Euler problems after reading LYAH and most of RWH).&nbsp; I'm
    using Taglib (<a class="moz-txt-link-freetext" href="https://github.com/taglib/taglib">https://github.com/taglib/taglib</a>) to read the metadata
    from a music file and print it.&nbsp; I have a struct C-side (with C
    linkage) serving as the bridge between Taglib's C++ and Haskell's
    FFI.&nbsp; A small demo program (compiled with gcc and linked against the
    C++ object files) gives the correct results, but Haskell is weirdly
    only getting some of it right.&nbsp; Specifically, the C string
    fields are working but ints are not.<br><br>
    The output from the C demo (what Haskell should be printing):<br><br>
    music_metadata<br>
    title: It's My Life,&nbsp;&nbsp;&nbsp; artist: Bon Jovi,&nbsp;&nbsp;&nbsp; album: Bon Jovi
    Greatest Hits - The Ultimate Collection<br>
    comment: ,&nbsp;&nbsp;&nbsp; genre: Rock,&nbsp;&nbsp;&nbsp; track: 3,<br>
    length: 224,&nbsp;&nbsp;&nbsp; bitrate: 256,&nbsp;&nbsp;&nbsp; channels: 2,<br>
    codec: 768<br><br>
    The output from Haskell:<br><br>
    MusicMetadata {codec = UNKNOWN, length = 1099511628000, bitrate =
    8589934848, channels = 12884901890, track = 8589934848, title =
    "It's My Life", artist = "Bon Jovi", album = "Bon Jovi Greatest Hits
    - The Ultimate Collection", comment = "", genre = "Rock"}<br><br>
    I would have expected it to work or not work at all, but did not
    anticipate getting only some of it right.<br><br>
    I was going to include snippets from my hsc file but given how new I
    am to Haskell I don't trust myself to assume where the problem is,
    so sorry if this is way too long:<br><br>
    {-# LANGUAGE CPP, ForeignFunctionInterface #-}<br><br>
    module MusicReader<br>
    ( Codec,<br>
    &nbsp; MusicMetadata,<br>
    &nbsp; readMusicMetadata<br>
    ) where<br><br>
    import Control.Monad<br>
    import Foreign<br>
    import Foreign.C.Types<br>
    import Foreign.C.String<br>
    import System.IO.Unsafe as Unsafe<br><br>
    #include "CodecDefines.h"<br>
    #include "MusicReader.h"<br><br>
    constantToCodec code<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == mp3 = MP3<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == flac = FLAC<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == ogg = OGG_VORBIS<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == mp4 = MP4<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == mpeg = MPEG<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == none = NONE<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | code == unknown = UNKNOWN<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise = UNKNOWN<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where mp3 = #const MP3_CODEC<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flac = #const FLAC_CODEC<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ogg = #const OGG_VORBIS_CODEC <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mp4 = #const MP4_CODEC<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mpeg = #const MPEG_CODEC<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; none = #const NO_EXTENSION<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unknown = #const UNKNOWN_EXTENSION<br><br>
    data Codec = MP3 | FLAC | OGG_VORBIS | MP4 | MPEG | NONE | UNKNOWN
    deriving (Show)<br><br>
    data MusicMetadata = MusicMetadata { codec :: Codec,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length :: Int,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitrate :: Int,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; channels :: Int,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; track :: Int,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title :: String,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; artist :: String,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; album :: String,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment :: String,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; genre :: String } deriving (Show)<br><br>
    instance Storable MusicMetadata where<br>
    &nbsp;&nbsp;&nbsp; sizeOf _ = (#size struct music_metadata)<br>
    &nbsp;&nbsp;&nbsp; alignment _ = alignment (undefined::CDouble)<br>
    &nbsp;&nbsp;&nbsp; peek a = do<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codec &lt;- liftM constantToCodec $ (((#peek struct
    music_metadata, codec) a) :: IO Int)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length &lt;- ((#peek struct music_metadata, length) a) :: IO
    Int<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitrate &lt;- ((#peek struct music_metadata, bitrate) a) ::
    IO Int<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; channels &lt;- ((#peek struct music_metadata, channels) a)
    :: IO Int<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; track &lt;- ((#peek struct music_metadata, bitrate) a) :: IO
    Int<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title &lt;-&nbsp; ((#peek struct music_metadata, title) a) :: IO
    CString<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; artist &lt;- ((#peek struct music_metadata, artist) a) :: IO
    CString<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; album &lt;- ((#peek struct music_metadata, album) a) :: IO
    CString<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment &lt;- ((#peek struct music_metadata, comment) a) ::
    IO CString<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; genre &lt;- ((#peek struct music_metadata, genre) a) :: IO
    CString<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --FIXME: find replacement for temporary names<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; marshalledTitle &lt;- peekCString title<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; marshalledArtist &lt;- peekCString artist<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; marshalledAlbum &lt;- peekCString album<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; marshalledComment &lt;- peekCString comment<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; marshalledGenre &lt;- peekCString genre<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (MusicMetadata codec length bitrate channels track
    marshalledTitle marshalledArtist marshalledAlbum marshalledComment
    marshalledGenre)<br>
    &nbsp;&nbsp;&nbsp; poke a = undefined<br><br>
    --This is the "primitive" FFI call--calls the C function and gets a
    pointer<br>
    --in return<br>
    --TODO: write a higher level function this module should export that
    calls<br>
    --primReadMusicMetadata and converts the C Pointer into the Haskell
    data<br>
    --MusicMetadata<br>
    foreign import ccall unsafe "read_metadata" primReadMusicMetadata ::
    CString -&gt; IO (Ptr MusicMetadata)<br><br>
    --convert the Haskell string to a CString, call into the FFI then<br>
    --dereference the resulting pointer<br>
    readMusicMetadata a = join $ withCString a $ \cs -&gt; ((liftM peek)
    $ primReadMusicMetadata cs)<br><br><br><br>
    Here's the struct in MusicReader.h (in an extern C block):<br>
    &nbsp;&nbsp;&nbsp; struct music_metadata<br>
    &nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int codec;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int length,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bitrate,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; channels;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int track;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *title,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *artist,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *album,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *comment,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *genre;<br>
    &nbsp;&nbsp;&nbsp; };<br><br><br>
    with the corresponding call:<br>
    &nbsp;&nbsp;&nbsp; struct music_metadata* read_metadata(char*);<br><br><br>
    I've tried playing around with the alignment but it didn't do
    anything.&nbsp; I also tried declaring the struct's fields as int32_t
    which also did nothing.<br><br>
    The C demo in question is a very simple:<br><br>
    #include &lt;stdio.h&gt;<br>
    #include "MusicReader.h"<br><br>
    #define FILENAME "Its_My_Life.m4a"<br><br>
    int main()<br>
    {<br>
    &nbsp;&nbsp;&nbsp; struct music_metadata* metadata = read_metadata(FILENAME);&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; printf("music_metadata\ntitle: %s,\tartist: %s,\talbum: %s\n",<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; metadata-&gt;title, metadata-&gt;artist,
    metadata-&gt;album);<br>
    &nbsp;&nbsp;&nbsp; printf("comment: %s,\tgenre: %s,\ttrack: %d,\n", <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; metadata-&gt;comment, metadata-&gt;genre,
    metadata-&gt;track);<br>
    &nbsp;&nbsp;&nbsp; printf("length: %d,\tbitrate: %d,\tchannels: %d,\n",<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; metadata-&gt;length, metadata-&gt;bitrate,
    metadata-&gt;channels);<br>
    &nbsp;&nbsp;&nbsp; printf("codec: %d\n");<br><br>
    }<br><br>
    It just reads the metadata into the struct and prints the fields.<br><br>
    I've gotten the impression of the Haskell FFI being very
    beginner-unfriendly, which isn't surprising but still disappointing
    because it would be a great opportunity to replace some projects
    with Haskell.<br><br>
    Any help is appreciated, including general feedback on my code!<br>
</div>
Alex Hammel | 27 Feb 23:32 2015
Picon

Bounded STM Queues with load shedding

Hi list,

It would be handy for me to have a bounded STM Queue along the lines of TBQueue with the difference that when the queue is full, a call to writeTBQueue is a non-blocking no-op.

This is in the context of an asynchronous logging system. If the load (somehow) gets heavy enough that the log message queue is taking up a lot of memory, It's better to lose a few log messages than to have processes block until the logger catches up.

Are there any off-the-shelf solutions?

Cheers,
Allex
<div><div dir="ltr">Hi list,<br><br>It would be handy for me to have a bounded STM Queue along the lines of <a href="https://hackage.haskell.org/package/stm-2.4/docs/Control-Concurrent-STM-TBQueue.html">TBQueue</a> with the difference that when the queue is full, a call to writeTBQueue is a non-blocking no-op.<br><br>This is in the context of an asynchronous logging system. If the load (somehow) gets heavy enough that the log message queue is taking up a lot of memory, It's better to lose a few log messages than to have processes block until the logger catches up.<br><br>Are there any off-the-shelf solutions?<br><br>Cheers,<br>Allex<br><a href="https://hackage.haskell.org/package/stm-2.4/docs/Control-Concurrent-STM-TBQueue.html"></a>
</div></div>

Gmane