Andreas Reuleaux | 29 Jul 01:26 2014
Picon

combining a trifecta parser with FreshMT from unbound

I can relatively easily combine a trifecta parser with some state:

  -- imports, language pragmas omitted here

  newtype InnerParser a = InnerParser { runInnerParser :: Parser a }
                        deriving (Functor
                                 , Monad
                                 , Applicative
                                 , Alternative
                                 , Parsing
                                 , CharParsing
                                 , MonadPlus
                                 )

  data PiState = PiState {
     foobar :: Integer
     -- ...some more stuff...
    }

  type PiParser = StateT PiState InnerParser

  instance TokenParsing PiParser where
    someSpace = buildSomeSpaceParser (skipSome (satisfy isSpace))
                $ commentStart .~ "{-"
                $ commentEnd .~ "-}"
                $ commentLine .~ "--"
                $ commentNesting .~ True
                $ emptyCommentStyle

  idStyle = styleStart .~ letter
(Continue reading)

양철웅 | 24 Jul 08:07 2014

Question on Lazy IO

Hi, all.

Haskell's lazy IO causes below program to 
write back "ECHO result" to the user 
even if he doesn't give any input to the program.

test1 :: IO ()
test1 = do
  l <- fmap lines getContents
  putStrLn "ECHO result"
  putStr $ unlines l

If the client logic, that is the part for feeding data to this program
and wait for the response, expect the server logic to respond
only after all the client's request data are feed to the server logic,
the behaviour could be problematic.

I'm now writing simple web server, as you might guess, and
my web server responds "HTTP/1.1" before any client's request
are given. I'm using hGetContents and web server's logic is
basically same with above code skeleton.

How can I tell the program to respond data only after all the
requests are feed? Any directions are welcomed.
Thanks.

Chul-Woong

<div><div dir="ltr">
<div>Hi, all.</div>
<div><br></div>
<div>Haskell's lazy IO causes below program to&nbsp;</div>
<div>write back "ECHO result" to the user&nbsp;</div>
<div>even if he doesn't give any input to the program.</div>

<div><br></div>
<div>test1 :: IO ()</div>
<div>test1 = do</div>
<div>&nbsp; l &lt;- fmap lines getContents</div>
<div>&nbsp; putStrLn "ECHO result"</div>
<div>&nbsp; putStr $ unlines l</div>
<div><br></div>
<div>If the client logic, that is the part for feeding data to this program</div>

<div>and wait for the response, expect the server logic to respond</div>
<div>only after all the client's request data are feed to the server logic,</div>
<div>the behaviour could be problematic.</div>
<div><br></div>
<div>

I'm now writing simple web server, as you might guess, and</div>
<div>my web server responds "HTTP/1.1" before any client's request</div>
<div>are given. I'm using hGetContents and web server's logic is</div>

<div>basically same with above code skeleton.</div>
<div><br></div>
<div>How can I tell the program to respond data only after all the</div>
<div>requests are feed? Any directions are welcomed.</div>
<div>Thanks.</div>
<div><br></div>
<div>Chul-Woong</div>
<div><br></div>
</div></div>
"René@gmail" | 23 Jul 17:23 2014
Picon

Re: Haskell in the Digital Humanities

Dear Niels-Oliver,

having some relation to DH and working in my student's job with 
(dirty-tagsoup) XML.

Struck by Haskells beauty and clearness of coding but also aware of the 
rather deep and technical type abstractions and combinatorics which are 
still hard to grasp for me, I also felt unsure about following the 
Haskell road. Still clinging on to Haskell because:

a) bespoken clearness of code of Haskell I miss too hard when looking on 
other languages code

b) elegance of Parser-Combinators (well this seems not really an 
argument because they are ported to many other languages, but I also 
suspect something might be lost, because you do not get the full 
customizability of functions and operators like in Haskell in other langs)

c) stemming from the same Parser-Combinator vein: PANDOC: is there a 
better text conversion tool, which is so well maintained and so easy 
(well yes, some knowledge needed -> see learning tipps) to extend

d) I don't know much about robust code in other languages, but then 
again I had so much input by Haskell blogs and tutorials, that the idea 
that type safety and testing functions in isolation might be a good one 
has stuck. So although you probably will not interface with a nuclear 
power plant in your DH coding, I think robustness could be an argument too.

So the elegance of code and the safety of the program are very general 
pro-arguments for Haskell. Text handling capabilities through 
Parser-Combinators are really handy. Still for text-munging to produce a 
desired output for D3.js all this might seem overkill and to be honest I 
wouldn't want to parse tagsoup with Haskell either (but only because I 
know the benefits of a specialized text-processing-toolbox like TUSTEP 
[http://www.tustep.uni-tuebingen.de/tustep_eng.html]).

On the other hand, if you have a well formed XML there a enough 
XML-tools for haskell which produce a neat Haskell data structure which 
in turn you can work at with nice pure functions. Also there are enough 
possibilities to get these structures out into Javascript (Fay,...). 
(javascript? I also find elm-lang.org very compelling.)

So for now my solution is to have Haskell as an important side-project. 
I still have to go through the "Write Yourself A Scheme" [1] which is 
said to give the needed exposure to some abstract types so that one can 
digest the theory behind those much better, but I hope by then the 
scariness of the abunding type system will abate a bit more. There's 
also a new book about data anlysis, which advertises "Recipes for every 
stage of data analysis, from collection to visualization" [2].

Interfacing with C?
At least from my superficial obervance of my cabal installs 
Foreign.PointerC (or so) is by no means an exception. Don't know about 
Python, though.

Well, anyway good to know, someone has similar worries like me. Good luck!

Cheers,
René Tobner

[1] http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours
[2] http://www.packtpub.com/haskell-data-analysis-cookbook/book

On 22.07.2014 14:00, beginners-request <at> haskell.org wrote:
> The question is simple and was raised by many people before, probably everyone who began with another
language and at some point got to know Haskell: Should I learn Haskell?

Christian Sperandio | 23 Jul 14:20 2014
Picon

Manage the type of a variable in the show implementation

Hi,

I wrote this kind of code:

data DataLog a = SingleData a
               | MultipleData [a]

instance (Show a) => Show (DataLog a) where
    show (SingleData v) = show v
    show (MultipleData vs) = join "|" vs
        where join _ [] = [] 
              join _ (x:[]) = show x
              join s (x:xs) = show x ++ s ++ join s xs

It works but when the DataLog is String typed I got this result:
"My Test"|"Another Value"

I'd prefer have: 
My Test|Another Value

I know the quote problem comes from the show function on String value. 
How could I do a show for no-string values and return directly the value for strings?

Thanks.

Chris
<div><div dir="ltr">Hi,<div><br></div>
<div>I wrote this kind of code:</div>
<div><br></div>
<div>
<div>data DataLog a = SingleData a</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| MultipleData [a]</div>
<div><br></div>
<div>instance (Show a) =&gt; Show (DataLog a) where</div>
<div>&nbsp; &nbsp; show (SingleData v) = show v</div>
<div>&nbsp; &nbsp; show (MultipleData vs) = join "|" vs</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; where join _ [] = []&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; join _ (x:[]) = show x</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; join s (x:xs) = show x ++ s ++ join s xs</div>
<div><br></div>
</div>
<div>It works but when the DataLog is String typed I got this result:</div>
<div>"My Test"|"Another Value"</div>
<div><br></div>
<div>I'd prefer have:&nbsp;</div>
<div>My Test|Another Value</div>
<div><br></div>
<div>I know the quote problem comes from the show function on String value.&nbsp;</div>
<div>How could I do a show for no-string values and return directly the value for strings?</div>
<div><br></div>
<div>Thanks.</div>
<div><br></div>
<div>Chris</div>
</div></div>
양철웅 | 23 Jul 14:08 2014

Type error in sub-function

Hi, all!

When I compile my program below, ghc emits Type error.
Since the return type of foo Func is IO String and
first case statement has "return timedVal", 
I think that ghc expects the type of timedVal as String.
However, the error message shows that
ghc expects timedVal should have type IO b0.
What am I missing? 
Any comments are appreciated. 

Thanks in advance!

Chul-Woong
-- 
 
import Data.Time.LocalTime      (getZonedTime, zonedTimeToUTC)
import System.Locale            (defaultTimeLocale)
import Data.Time.Format         (formatTime)
import Data.Time.Clock         (UTCTime)

currentUTCTime :: IO UTCTime
currentUTCTime = do
zTime <- getZonedTime
        return (zonedTimeToUTC zTime)

fooFunc :: IO String
fooFunc = do
  putStrLn "Hello, world"
  barFunc "xutc"       
      where barFunc s =
                case s of
                  "apple" -> return s
                  ('x': val) -> return timedVal
                       where timedVal = case val of
                                            "utc" -> do utcTime <- currentUTCTime
                                                        formatTime defaultTimeLocale "%a" utcTime
---
Prelude> :l test
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:21:57:
    Couldn't match expected type `IO b0' with actual type `String'
    In the return type of a call of `formatTime'
    In a stmt of a 'do' block:
      formatTime defaultTimeLocale "%a" utcTime
    In the expression:
      do { utcTime <- currentUTCTime;
           formatTime defaultTimeLocale "%a" utcTime }
<div><div dir="ltr">
<div>Hi, all!</div>
<div><br></div>
<div>When I compile my program below, ghc emits Type error.</div>
<div>Since the return type of foo Func is IO String and</div>
<div>first case statement has "return timedVal",&nbsp;</div>

<div>I think that ghc expects the type of timedVal as String.</div>
<div>However, the error message shows that</div>
<div>ghc expects timedVal should have type IO b0.</div>
<div>What am I missing?&nbsp;</div>
<div>Any comments are appreciated.&nbsp;</div>

<div><br></div>
<div>Thanks in advance!</div>
<div><br></div>
<div>Chul-Woong</div>
<div>--&nbsp;</div>
<div>&nbsp;</div>
<div>import Data.Time.LocalTime &nbsp; &nbsp; &nbsp;(getZonedTime, zonedTimeToUTC)</div>
<div>import System.Locale &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(defaultTimeLocale)</div>

<div>import Data.Time.Format &nbsp; &nbsp; &nbsp; &nbsp; (formatTime)</div>
<div>import Data.Time.Clock &nbsp; &nbsp; &nbsp; &nbsp; (UTCTime)</div>
<div><br></div>
<div>currentUTCTime :: IO UTCTime</div>
<div>currentUTCTime = do</div>
<div>
<span class="">	</span>zTime &lt;- getZonedTime</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; return (zonedTimeToUTC zTime)</div>
<div><br></div>
<div>fooFunc :: IO String</div>
<div>fooFunc = do</div>
<div>&nbsp; putStrLn "Hello, world"</div>
<div>&nbsp; barFunc "xutc" &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; where barFunc s =</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case s of</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "apple" -&gt; return s</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ('x': val) -&gt; return timedVal</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where timedVal = case val of</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "utc" -&gt; do utcTime &lt;- currentUTCTime</div>
<div>&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; formatTime defaultTimeLocale "%a" utcTime</div>

<div>---</div>
<div>
<div>Prelude&gt; :l test</div>
<div>[1 of 1] Compiling Main &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( test.hs, interpreted )</div>
<div><br></div>
<div>test.hs:21:57:</div>
<div>&nbsp; &nbsp; Couldn't match expected type `IO b0' with actual type `String'</div>

<div>&nbsp; &nbsp; In the return type of a call of `formatTime'</div>
<div>&nbsp; &nbsp; In a stmt of a 'do' block:</div>
<div>&nbsp; &nbsp; &nbsp; formatTime defaultTimeLocale "%a" utcTime</div>
<div>&nbsp; &nbsp; In the expression:</div>
<div>&nbsp; &nbsp; &nbsp; do { utcTime &lt;- currentUTCTime;</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;formatTime defaultTimeLocale "%a" utcTime }</div>
</div>
</div></div>
Niels-Oliver Walkowski | 22 Jul 10:19 2014
Picon

Haskell in the Digital Humanities

Dear Haskell Community,

I am coming to you with a question which I try to solve for 2 month now, but still struggling, so I tried the step
to refer to you. The question is simple and was raised by many people before, probably everyone who began
with another language and at some point got to know Haskell: Should I learn Haskell?

So I read a lot of things in the www that had the same question or that could support decision making. The
reason why I couldn't manage to make a decision rest on – as so often – in the particular case or at least
what seems particular for me. I would like to briefly outline why I would love to learn Haskell, what are the
reasons why I am hesitating and how all this relates to my background. I would be tremendously grateful for
feedback that will make a decision easier for me and hope that it is ok to ask such a question on a beginner's mailinglist.

Background: I am a humanist, working in the so called Digital Humanities realm. I don't have any
information technology education though I started coding in PHP at the beginning of University. In DH
like in many other areas of 'data driven science' Python is 'Lengua Franca'. That might relate to the fact
that coding is means not goal. In fact, often coding is more glueing things together than really code
something and the ecosystem of scripts and libraries is as broad as scientific discourse itself. It is
easy to reach a goal a goal (which is important when you want to test hypothesis) but things are often dirty
of cause.

Interest in Haskell: I got to know ideas of functional programing half a year ago when I digged a little bit
into machine theory. Functional Programing expresses exactly how I think about computation and
furthermore I enjoy very much to think within a functional logic about things I want to do. Additionally I
think that the functional approach has some important advantages for coding in science at least on the
publication level because it expresses ideas in a clear defined way that is not the same with an imperative
approach. I started to read a little bit about functional programing in Python since Python is
multi-paradigm but very quickly my impression was that it is something you do not really want to do, it
makes writing code more verbose, you do not really have the benefits of functional programing and often
feels like workaround, so I was brought back to Haskell again

Concerns: As mentioned before coding in Digital Humanities is definitely always means for an end. On the
other hand I like to to my things straight forward and on a certain abstraction level (maybe because I was
trained in Philosophy ;-) ) General concerns rest on the fear that the Haskell ecosystem is not big enough
for the area in which I code. I work in the area of text analysis (not identical with computational
linguistics), topic modeling, I need sophisticated visualisations, I work with XML (state of the art in
DH) and a lot with so called 'dirty data' which relates to the whole NoSQL world – especially Graph and
JSON based. Managing Web technologies is important because of the importance of publishing. Approaches
like the IPython Notebook are significant (I got to know that there is IHaskell which is IPython with a
Haskell kernel but I don't know how valid and stable this project is). I absolutely do not need to have a
library for any tiny task and I like to approach things from a higher level of abstraction but of cause there
is a point where implementing something on your own is not reasonably time efficient anymore, especially
when the goal is something completely different. And being not natively educated in informatics there is
also a limit in capacity at a certain point. 

If you could provide me with feedback or with your judgment to help me evaluate the Haskell environment
around my area and social field in a more substantial way and to get a more sophisticated feeling for or
against the idea that learning Haskell will work out in my case, it would be wonderful. (A blog article
about using Haskell in DH that summarizes the discussion and promotes the awareness of Haskell in the DH
community would also something I might consider afterwards) If you feel I misused the list, please apologize.

best,
Niels-Oliver Walkowski
_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://www.haskell.org/mailman/listinfo/beginners
Pavan Rikhi | 19 Jul 09:57 2014
Picon

Critique My First Project - CampBX API Client

Hiya, so I've spent the last 2 months or so learning Haskell. I've
finished the UPenn course, LYAH and a little bit of RWH.

I wanted to get a project going so I tried making an API client for the
CampBX Bitcoin Market[1]. I started out by following along with the
FPComplete Mailchimp API Tutorial[2].

I'm asking you beautiful people for any feedback on it so I can be sure
that I'm on the right track here, stuff like code style/idioms, project
layout, public interface, implementation, docs, ideas for new features,
anything you want to tell me, etc.:

https://github.com/prikhi/campbx-haskell

Typical usage would be something like this[3]:

    main :: IO ()
    main = do
        cfg <- defaultCampBXConfig
        _   <- runCampBX cfg $ do
            totalAskVolume <- calculateAskVolume <$> getDepth
            liftIO . putStrLn $ "Total Ask Volume: " ++ show totalAskVolume
        return ()

    calculateAskVolume :: Depth -> BTCAmount
    calculateAskVolume depthList = sum . map askPrice . asks $ depthList
        where askPrice (Ask (_, q)) = q

There are still some things I want to work on:

* Define Asks and Bids[4] using Record Syntax. The JSON[5] for a Bid/Ask
  comes back as a 2 item Array but the generically derived instance[6]
  expects an object. I haven't completely wrapped my head around Aeson's
  Array parsing...
* Write tests. I'm imagining they would be more "given this JSON, make
  sure the data structure is created correctly" instead of
  property-based testing.
* Use something other than Doubles to represent Amounts + Prices. Is
  there a standard library for accurate math with decimals(I need up to
  8 decimal places)? I suppose I could always just use Integers to
  represent Satoshis(the smallest subunit of bitcoins).

Also I tried adding "default-extensions: OverloadedStrings" to the
.cabal file and removing the pragmas from the source files, but the
package wouldn't build :(

[1] https://campbx.com/api.php
[2] https://www.fpcomplete.com/school/to-infinity-and-beyond/competition-winners/interfacing-with-restful-json-apis
[3] https://github.com/prikhi/campbx-haskell/blob/master/bin/CampBXMain.hs
[4] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L71
[5] http://sleepanarchy.com/p/K1wuSm
[6] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L188
Hiya, so I've spent the last 2 months or so learning Haskell. I've
finished the UPenn course, LYAH and a little bit of RWH.

I wanted to get a project going so I tried making an API client for the
CampBX Bitcoin Market[1]. I started out by following along with the
FPComplete Mailchimp API Tutorial[2].

I'm asking you beautiful people for any feedback on it so I can be sure
that I'm on the right track here, stuff like code style/idioms, project
layout, public interface, implementation, docs, ideas for new features,
anything you want to tell me, etc.:

https://github.com/prikhi/campbx-haskell

Typical usage would be something like this[3]:

    main :: IO ()
    main = do
        cfg <- defaultCampBXConfig
        _   <- runCampBX cfg $ do
            totalAskVolume <- calculateAskVolume <$> getDepth
            liftIO . putStrLn $ "Total Ask Volume: " ++ show totalAskVolume
        return ()

    calculateAskVolume :: Depth -> BTCAmount
    calculateAskVolume depthList = sum . map askPrice . asks $ depthList
        where askPrice (Ask (_, q)) = q

There are still some things I want to work on:

* Define Asks and Bids[4] using Record Syntax. The JSON[5] for a Bid/Ask
  comes back as a 2 item Array but the generically derived instance[6]
  expects an object. I haven't completely wrapped my head around Aeson's
  Array parsing...
* Write tests. I'm imagining they would be more "given this JSON, make
  sure the data structure is created correctly" instead of
  property-based testing.
* Use something other than Doubles to represent Amounts + Prices. Is
  there a standard library for accurate math with decimals(I need up to
  8 decimal places)? I suppose I could always just use Integers to
  represent Satoshis(the smallest subunit of bitcoins).

Also I tried adding "default-extensions: OverloadedStrings" to the
.cabal file and removing the pragmas from the source files, but the
package wouldn't build :(

[1] https://campbx.com/api.php
[2] https://www.fpcomplete.com/school/to-infinity-and-beyond/competition-winners/interfacing-with-restful-json-apis
[3] https://github.com/prikhi/campbx-haskell/blob/master/bin/CampBXMain.hs
[4] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L71
[5] http://sleepanarchy.com/p/K1wuSm
[6] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L188
martin | 15 Jul 20:32 2014
Picon

More simple continuation questions

Hello all,

(1) when reading about continuations, there is this thing which needs an "other function" to be passed to
produce a
final result. And there is this "other function". Which of the two is "the continuation"?

http://stackoverflow.com/questions/9050725/call-cc-implementation sais
" ... instead, they are passed a function that represents the 'next step' in the computation - the
'continuation' "

Which sound like the "other function" is called "continuation". But other articles hint in the opposite direction.

(2) When comparing continuations with callbacks, it struck me that the type is

	newtype Cont r a = Cont { runCont :: (a -> r) -> r }

So the type of the final result is r. But why does the function (a->r) need to return an r? With regular
callbacks this
does not seem to be the case. After returning from the callback the surrounding function is free to do
anything it wants
with the return value and return a value of a different type. Why is that so?
Andreas Reuleaux | 14 Jul 06:25 2014
Picon

cabal sandbox add-source + cabal repl (for tracking Idris git version)

Being somehow new to cabal sandboxes, I would expect that sources that I
add with

  cabal sandbox add-source /some/path

are available to me in my local (sandbox aware) cabal repl, this is
however not the case, or at least I haven't figured out how to make this
this work.

I am trying to use Idris as a library - roughly as described in
http://brianmckenna.org/blog/idris_library, (and in particular the
"cabal sandbox add-source..." step, described there) but my question is
really more Haskell and cabal sandbox than Idris related, therefore I am
asking here.

I have successfully installed Idris from git in a sandbox (For
completeness's sake here are the individual steps, including some test
steps with highlight-versions, that are not strictly necessary). I
install only the idris deps via cabal (i.e. from hackage), idris itself
via make from its git sources:
--------------------

(within my dir ~/idr, i.e. creating ~/idr/dev here)
git clone git://github.com/idris-lang/Idris-dev dev
cd dev
cabal sandbox init
cabal update
cabal install highlight-versions

(activate my sandbox with some bash magic, i.e. include
/home/reuleaux/idr/dev/.cabal-sandbox/bin
in my PATH, so that the command highlight-versions is found:)

cabal install --dry-run --only-dependencies idris | highlight-versions

(now the wet run:)
cabal install --only-dependencies idris

make
(which installs idris from its git sources)
I have two more wrappers in my sandbox for that purpose:
(really some bash magic...)

* ghc:
  exec "/usr/bin/ghc" -no-user-package-db
-package-db=/home/reuleaux/idr/dev/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d "$ <at> "

* ghc-pkg:
  exec "/usr/bin/ghc-pkg" --no-user-package-db
--package-db=/home/reuleaux/idr/dev/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d "$ <at> "

  I know that "cabal sandbox hc-pkg" is the regular wrapper for
  ghc-pkg, but idris make expects a ghc-pkg command (not cabal sandbox hc-pkg)

Now within ~/dev I can e.g. call

* "idris" or 

* cabal repl
  and then

  > :m +Idris.Parser

  i.e. load some idris modules on the repl
--------------------

So far, so good.

Now I would like to track that dev version of idris in a separate
directory / sandbox, I am therefore using "cabal sandbox add-source...":

mkdir ~/foo
cd foo
cabal sandbox init
cabal sandbox add-source ~/idr/dev
cabal update

(I don't mind reinstalling the deps, not sure if this is really
necessary:)

cabal install --only-dependencies idris

I would think that within foo, I should be able to
just do e.g.

cabal repl
> :m +Idris.Parser

(as cabal repl is sandbox aware, as I learned) but nope !?

    Prelude > :m +Idris.Parser

    <no location info>:
        Could not find module `Idris.Parser'
        It is not a module in the current program, or in any known package.
    Prelude >

Well I can see the sources with

    [sb] reuleaux <at> mirabelle ~/foo $ cabal sandbox list-sources
    Source dependencies registered in the current sandbox
    ('/home/reuleaux/foo/.cabal-sandbox'):

    /home/reuleaux/idr/dev

    To unregister source dependencies, use the 'sandbox delete-source' command.
    [sb] reuleaux <at> mirabelle ~/foo $

But that's about it. 

Similarly: How would I use these added sources with ghc? Do I have to
use both:

* /home/reuleaux/idr/dev/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d

* and 
  /home/reuleaux/idr/foo/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d

in my -package-db ?

I am happy to give more details of my installation, if
necessary (I am on debian jessie, my cabal is v 1.20)

Thanks in advance.

-Andreas
martin | 12 Jul 12:24 2014
Picon

Simple Continuation question

Hello all,

I just started trying to understand Continuations, but my very first exercise already left me mystified.

import Control.Monad.Cont

resultIs :: Int -> Cont String String
resultIs i = ContT $ f
        where
            f :: (String -> a) -> a
            f k = k ("result=" ++ show i)

If resultIs returns a Cont String String, then f should be (String->String)->String, but that doesn't
compile. Why is
that so?
Matthew Moppett | 11 Jul 14:05 2014
Picon

foldM efficiency

I recently wrote the following code to solve a Project Euler problem:

coin :: Int -> Int -> [Int] coin coinvalue stash = [stash, stash + coinvalue .. 200] main = print . length . foldl (>>=) [0] $ map coin [200, 100, 50, 20, 10, 5, 2]
The program (correctly) works out how many ways there are to make up £2 from £2, £1, 50p, 20p, 10p, 5p, and 1p coins. Looking at the code, I realised that (foldl (>>=) [0] . map) does a very similar job to foldM from Control.Monad. So I tried rewriting the code as 
follows:

import Control.Monad coin :: Int -> Int -> [Int] coin stash coinvalue = [stash, stash + coinvalue .. 200] main = print . length $ foldM coin 0 [200, 100, 50, 20, 10, 5, 2]
This works, but it's about four times slower: it takes about 0.065 seconds on my computer, while the first version takes about 0.017 seconds. To put it another way, if I define foldM as follows:

foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a foldM f x = foldl (>>=) (return x) . map (flip f)
... and use that definition instead of the standard Control.Monad version, the code runs about four times faster. Here's the Control.Monad version (copied from Hackage):

foldM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a foldM _ a [] = return a foldM f a (x:xs) = f a x >>= \fax -> foldM f fax xs
Why is my version so much faster here? And under what circumstances (if any) could I expect the Control.Monad foldM to give better performance than my version?

Attachment (FoldM.hs): text/x-haskell, 328 bytes
Attachment (problem31a.hs): text/x-haskell, 230 bytes
Attachment (problem31b.hs): text/x-haskell, 239 bytes
<div><div dir="ltr">
<div class="gmail_quote">
<div dir="ltr">
<span>I recently wrote the following code to solve a Project Euler problem:</span><br><div><span><br></span></div>
<div>coin <span>::</span> Int <span>-</span><span>&gt;</span> Int <span>-</span><span>&gt;</span> <span>[</span>Int<span>]</span>
coin coinvalue stash <span>=</span> <span>[</span>stash<span>,</span> stash <span>+</span> coinvalue <span>.</span><span>.</span> <span>200</span><span>]</span>

<span>main</span> <span>=</span> print <span>.</span> length <span>.</span> foldl <span>(</span><span>&gt;</span><span>&gt;</span><span>=</span><span>)</span> <span>[</span><span>0</span><span>]</span> $ map coin <span>[</span><span>200</span><span>,</span> <span>100</span><span>,</span> <span>50</span><span>,</span> <span>20</span><span>,</span> <span>10</span><span>,</span> <span>5</span><span>,</span> <span>2</span><span>]</span>

<span><br></span>The program (correctly) works out how many ways there are to make up &pound;2 from &pound;2, &pound;1, 50p, 20p, 10p, 5p, and 1p coins. Looking at the code, I realised that (foldl (&gt;&gt;=) [0] . map) does a very similar job to foldM from Control.Monad. So I tried rewriting the code as&nbsp;<br>
</div>
<div>follows:</div>
<div><br></div>
<div>
<span>import</span> Control<span>.</span>Monad

coin <span>::</span> Int <span>-</span><span>&gt;</span> Int <span>-</span><span>&gt;</span> <span>[</span>Int<span>]</span>
coin stash coinvalue <span>=</span> <span>[</span>stash<span>,</span> stash <span>+</span> coinvalue <span>.</span><span>.</span> <span>200</span><span>]</span>

<span>main</span> <span>=</span> print <span>.</span> length $ foldM coin <span>0</span> <span>[</span><span>200</span><span>,</span> <span>100</span><span>,</span> <span>50</span><span>,</span> <span>20</span><span>,</span> <span>10</span><span>,</span> <span>5</span><span>,</span> <span>2</span><span>]</span>

<span><br></span>This works, but it's about four times slower: it takes about 0.065 seconds on my computer, while the first version takes about 0.017 seconds. To put it another way, if I define foldM as follows:</div>

<div><br></div>
<div>foldM <span>::</span> Monad m <span>=</span><span>&gt;</span> <span>(</span>a <span>-</span><span>&gt;</span> b <span>-</span><span>&gt;</span> m a<span>)</span> <span>-</span><span>&gt;</span> a <span>-</span><span>&gt;</span> <span>[</span>b<span>]</span> <span>-</span><span>&gt;</span> m a
foldM f x <span>=</span> foldl <span>(</span><span>&gt;</span><span>&gt;</span><span>=</span><span>)</span> <span>(</span><span>return</span> x<span>)</span> <span>.</span> map <span>(</span>flip f<span>)</span>

<br>... and use that definition instead of the standard Control.Monad version, the code runs about four times faster. Here's the Control.Monad version (copied from Hackage):<br><br>
</div>
<div>
foldM             <span>::</span> <span>(</span>Monad m<span>)</span> <span>=</span><span>&gt;</span> <span>(</span>a <span>-</span><span>&gt;</span> b <span>-</span><span>&gt;</span> m a<span>)</span> <span>-</span><span>&gt;</span> a <span>-</span><span>&gt;</span> <span>[</span>b<span>]</span> <span>-</span><span>&gt;</span> m a
foldM _ a <span>[</span><span>]</span>      <span>=</span>  <span>return</span> a
foldM f a <span>(</span>x<span>:</span>xs<span>)</span>  <span>=</span>  f a x <span>&gt;</span><span>&gt;</span><span>=</span> \fax <span>-</span><span>&gt;</span> foldM f fax xs

<br>Why is my version so much faster here? And under what circumstances (if any) could I expect the Control.Monad foldM to give better performance than my version?
<br>
</div>
</div>
</div>
<br>
</div></div>

Gmane