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: Problem combining monads <sigh!> (James Jones)
2. Re: function not working as expected, type issues (Gesh)
(Alexej Magura)
3. Re: function not working as expected, type issues (David
McBride) (Alexej Magura)
4. Nonsensical behavior with http-conduit, httpLbs
(Christopher Allen)
5. Re: Nonsensical behavior with http-conduit, httpLbs
(Christopher Allen)
6. Re: Nonsensical behavior with http-conduit, httpLbs
(Michael Snoyman)
----------------------------------------------------------------------
Message: 1
Date: Wed, 9 Apr 2014 11:31:32 -0500
From: James Jones <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem combining monads <sigh!>
Message-ID:
<CAFY=adacv+gep74ehvbrdeo-vsp8h2s4pou4zns_rfxixnn...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Mon, Apr 7, 2014 at 4:06 AM, John M. Dlugosz <[email protected]>wrote:
> (Aside: is there a "history" function in GHCi to show the last
> few commands I typed?)
>
> :hist apparently only works at a breakpoint, but ghci does remember what
you typed, and you can look through it with up/down arrow.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140409/ebc14e9f/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 9 Apr 2014 22:00:40 -0600
From: Alexej Magura <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] function not working as expected,
type issues (Gesh)
Message-ID: <etPan.53461769.431bd7b7.2b5e@Gin>
Content-Type: text/plain; charset="utf-8"
>an arg. ?My initial guess is that the *first* type specified is the one?
>returned, but I?m not sure.?
>?
I'm curious as to why you thought that. The directionality of the arrows in a
type signature is quite clear, at least to me. a -> b is the type of functions
*from* a *to* b.?
Well, most of the languages that I?ve used are dynamically typed, but the one
language that I?m _kinda_ familiar with that _is_ statically typed is C:
several of the Haskell tutorials that I?ve been reading describe that:
A :: Int
means that *A* is _of_ type *Int*, which kind of sounds like A?returns type Int
functions such as map :: (a -> b) -> [a] -> [b] (can you guess what it does and
how it does it? Can you do that just by looking at the type?).?
Map appears to take a lambda function, which takes type *a* returning type *b*
(both of which are purely arbitrary), a list of type *a*, and returns a list of
type *b*, applying the lambda function to each element in the list of type *a*.
>From your coding style, it appears that you think of && in the way Bash does -
>as the function:?
> p && x = if p then x else *nothing*?
Something like that.
Anyway, all of the above means that passing a non-Bool value to && is not
acceptable, and since hPutStr stdout string is not a value of type Bool, GHC
complains.?
Makes sense.
--
Alexej Magura
Sent with Airmail
------------------------------
Message: 3
Date: Wed, 9 Apr 2014 22:01:45 -0600
From: Alexej Magura <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] function not working as expected,
type issues (David McBride)
Message-ID: <etPan.534617aa.3f2dba31.2b5e@Gin>
Content-Type: text/plain; charset="utf-8"
Thanks
displayD :: String -> Int -> IO ()
displayD string 0 = return ()
?.
is exactly what I was looking for.
--
Alexej Magura
Sent with Airmail
------------------------------
Message: 4
Date: Thu, 10 Apr 2014 00:41:28 -0500
From: Christopher Allen <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Nonsensical behavior with http-conduit,
httpLbs
Message-ID:
<cadnndorp3cf8uetzmbfweuxmkworp_a01smbjdhofgd22df...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Repro'd on GHC 7.8.1 and 7.6.3
Original code is: https://github.com/bitemyapp/bloodhound/
The code only works if I manually (out of band) run insertData (in a REPL)
and then run main with the insertData invocation stripped out. If I run
main with the insertData invocation included, it throws an exception (head)
because the search results are empty.
The behavior is as if queryTweet was executing after insertData deleted the
index, but before it inserted the new data.
The following is a stripped down example:
insertData :: IO ()
insertData = do
let encoded = encode exampleTweet
_ <- deleteExampleIndex
created <- createExampleIndex
docCreated <- indexDocument (Server "http://localhost:9200") "twitter"
"tweet" exampleTweet "1"
print "test"
return ()
el
queryTweet :: IO (Either String Tweet)
queryTweet = do
let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)
<||> IdentityFilter
let search = Search Nothing (Just queryFilter)
reply <- searchByIndex testServer "twitter" search
let result = eitherDecode (responseBody reply) :: Either String
(SearchResult Tweet)
let myTweet = fmap (hitSource . head . hits . searchHits) result
return myTweet
main :: IO ()
main = do
_ <- insertData
myTweet <- queryTweet
print myTweet
further up the call chain, the http call is getting dispatched with
http-conduit's gear, the result returned with the expression:
withManager $ httpLbs req
Included this in case it affects the semantics.
Can anybody help? This has stumped me for a couple hours and I couldn't get
anything clueful on IRC.
Thanks to any that help.
--- Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140410/a9b3caad/attachment-0001.html>
------------------------------
Message: 5
Date: Thu, 10 Apr 2014 00:43:52 -0500
From: Christopher Allen <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Nonsensical behavior with
http-conduit, httpLbs
Message-ID:
<CADnndOpz5=xtccwi6didxwv_gdowdhaokcydamjwanu+ufr...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
to add to my question adding a delay made it work:
main :: IO ()
main = do
_ <- insertData
threadDelay 1000000
myTweet <- queryTweet
print myTweet
On Thu, Apr 10, 2014 at 12:41 AM, Christopher Allen <[email protected]>wrote:
> Repro'd on GHC 7.8.1 and 7.6.3
>
> Original code is: https://github.com/bitemyapp/bloodhound/
>
> The code only works if I manually (out of band) run insertData (in a REPL)
> and then run main with the insertData invocation stripped out. If I run
> main with the insertData invocation included, it throws an exception (head)
> because the search results are empty.
>
> The behavior is as if queryTweet was executing after insertData deleted
> the index, but before it inserted the new data.
>
> The following is a stripped down example:
>
> insertData :: IO ()
> insertData = do
> let encoded = encode exampleTweet
> _ <- deleteExampleIndex
> created <- createExampleIndex
> docCreated <- indexDocument (Server "http://localhost:9200") "twitter"
> "tweet" exampleTweet "1"
> print "test"
> return ()
> el
> queryTweet :: IO (Either String Tweet)
> queryTweet = do
> let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)
> <||> IdentityFilter
> let search = Search Nothing (Just queryFilter)
> reply <- searchByIndex testServer "twitter" search
> let result = eitherDecode (responseBody reply) :: Either String
> (SearchResult Tweet)
> let myTweet = fmap (hitSource . head . hits . searchHits) result
> return myTweet
>
> main :: IO ()
> main = do
> _ <- insertData
> myTweet <- queryTweet
> print myTweet
>
> further up the call chain, the http call is getting dispatched with
> http-conduit's gear, the result returned with the expression:
>
> withManager $ httpLbs req
>
> Included this in case it affects the semantics.
>
> Can anybody help? This has stumped me for a couple hours and I couldn't
> get anything clueful on IRC.
>
> Thanks to any that help.
>
> --- Chris
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140410/a275921f/attachment-0001.html>
------------------------------
Message: 6
Date: Thu, 10 Apr 2014 09:15:03 +0300
From: Michael Snoyman <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Nonsensical behavior with
http-conduit, httpLbs
Message-ID:
<CAKA2JgKh9toU_zwFrcBEs+R4bOG5=hpghgatsfbv4cp9uwu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I can't say I fully understand your code, but it seems like it's doing the
following:
1. Send request to server to delete data.
2. Send request to server to add data.
3. Request data from server.
You're saying that with a long enough delay between steps 2 and 3, then (3)
works, otherwise it fails. It sounds to me like there's some kind of a race
condition. I don't know anything about createExampleIndex, but are you
certain that it only returns after the data is completely ready for
querying?
On Thu, Apr 10, 2014 at 8:43 AM, Christopher Allen <[email protected]>wrote:
> to add to my question adding a delay made it work:
>
> main :: IO ()
> main = do
> _ <- insertData
> threadDelay 1000000
> myTweet <- queryTweet
> print myTweet
>
>
>
> On Thu, Apr 10, 2014 at 12:41 AM, Christopher Allen <[email protected]>wrote:
>
>> Repro'd on GHC 7.8.1 and 7.6.3
>>
>> Original code is: https://github.com/bitemyapp/bloodhound/
>>
>> The code only works if I manually (out of band) run insertData (in a
>> REPL) and then run main with the insertData invocation stripped out. If I
>> run main with the insertData invocation included, it throws an exception
>> (head) because the search results are empty.
>>
>> The behavior is as if queryTweet was executing after insertData deleted
>> the index, but before it inserted the new data.
>>
>> The following is a stripped down example:
>>
>> insertData :: IO ()
>> insertData = do
>> let encoded = encode exampleTweet
>> _ <- deleteExampleIndex
>> created <- createExampleIndex
>> docCreated <- indexDocument (Server "http://localhost:9200") "twitter"
>> "tweet" exampleTweet "1"
>> print "test"
>> return ()
>> el
>> queryTweet :: IO (Either String Tweet)
>> queryTweet = do
>> let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)
>> <||> IdentityFilter
>> let search = Search Nothing (Just queryFilter)
>> reply <- searchByIndex testServer "twitter" search
>> let result = eitherDecode (responseBody reply) :: Either String
>> (SearchResult Tweet)
>> let myTweet = fmap (hitSource . head . hits . searchHits) result
>> return myTweet
>>
>> main :: IO ()
>> main = do
>> _ <- insertData
>> myTweet <- queryTweet
>> print myTweet
>>
>> further up the call chain, the http call is getting dispatched with
>> http-conduit's gear, the result returned with the expression:
>>
>> withManager $ httpLbs req
>>
>> Included this in case it affects the semantics.
>>
>> Can anybody help? This has stumped me for a couple hours and I couldn't
>> get anything clueful on IRC.
>>
>> Thanks to any that help.
>>
>> --- Chris
>>
>>
>
> _______________________________________________
> 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/20140410/f9ac277c/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 20
*****************************************