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. Network.HTTP.Conduit - body in REST/POST request (Miro Karpis)
2. Re: Network.HTTP.Conduit - body in REST/POST request
(Miro Karpis)
3. Re: Network.HTTP.Conduit - body in REST/POST request
(Michael Snoyman)
4. Type class vs. Record: How do I model an interface in
Haskell? (Dimitri DeFigueiredo)
5. installing cabal 1.20 on linux mint debian edition (LMDE)
(Ovidiu Deac)
----------------------------------------------------------------------
Message: 1
Date: Wed, 28 May 2014 14:48:19 +0200
From: Miro Karpis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Network.HTTP.Conduit - body in REST/POST
request
Message-ID:
<cajnnbxgvnpryrky-vzd9alztgpeiq9cqcsojqayhh4bu01e...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi, I'm having difficulties with sending body parameters/values in a POST
request. It seems that the server does not receive in body.
ideas/comments very welcome ;-)
cheers,
m.
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit
import Data.Word(Word8)
import Data.ByteString.Lazy(pack)
import qualified Data.ByteString.Char8 as B
x :: B.ByteString
x = "?value=10"
post = do
r <- parseUrl "http://postcatcher.in/catchers/5385d4e0b6887c0200000071"
putStrLn $show r
let request = r
{ secure = True
, method = "POST"
, requestBody = RequestBodyBS s
, requestHeaders = (requestHeaders r) ++ [("Content-Type",
"application/json")]}
putStrLn $ show request
response <- withManager $ httpLbs request
print $ responseBody response
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140528/e9bd2f63/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 28 May 2014 15:21:18 +0200
From: Miro Karpis <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Network.HTTP.Conduit - body in
REST/POST request
Message-ID:
<CAJnnbxHg-g13H0_N=yzdop21mbeycrg-l_o00hzfv8-rgym...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
so this did the trick:
test :: IO ()
test = do
r <- parseUrl $ "http://localhost:3000/readbody"
let r_ = urlEncodedBody [("?nonce:", "2"), ("&method", "getInfo")] r
let request = r_
{ requestBody = (RequestBodyBS s)}
response <- withManager $ httpLbs request
putStrLn $ show request
print $ responseBody response
On Wed, May 28, 2014 at 2:48 PM, Miro Karpis <[email protected]>wrote:
> Hi, I'm having difficulties with sending body parameters/values in a POST
> request. It seems that the server does not receive in body.
>
> ideas/comments very welcome ;-)
>
> cheers,
> m.
>
>
> {-# LANGUAGE OverloadedStrings #-}
>
> import Network.HTTP.Conduit
> import Data.Word(Word8)
> import Data.ByteString.Lazy(pack)
> import qualified Data.ByteString.Char8 as B
>
> x :: B.ByteString
> x = "?value=10"
>
> post = do
> r <- parseUrl "http://postcatcher.in/catchers/5385d4e0b6887c0200000071"
> putStrLn $show r
> let request = r
> { secure = True
> , method = "POST"
> , requestBody = RequestBodyBS s
> , requestHeaders = (requestHeaders r) ++ [("Content-Type",
> "application/json")]}
> putStrLn $ show request
> response <- withManager $ httpLbs request
> print $ responseBody response
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140528/ea1d3974/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 28 May 2014 19:18:31 +0300
From: Michael Snoyman <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] Network.HTTP.Conduit - body in
REST/POST request
Message-ID:
<caka2jgldmkonpkm7xnuuaohmmjwpnetqmdbwezc7tmi-3al...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Just to clarify one point: you don't need to include the ?, :, or &
characters in the parameters to urlEncodedBody; urlEncodedBody will
automatically add the ? and &, and I'm guessing the colon was just a typo.
In other words, the following code is probably closer to what you were
looking for:
let request = urlEncodedBody [("nonce", "2"), ("method", "getInfo")] r
On Wed, May 28, 2014 at 4:21 PM, Miro Karpis <[email protected]>wrote:
> so this did the trick:
>
> test :: IO ()
> test = do
> r <- parseUrl $ "http://localhost:3000/readbody"
> let r_ = urlEncodedBody [("?nonce:", "2"), ("&method", "getInfo")] r
> let request = r_
> { requestBody = (RequestBodyBS s)}
>
> response <- withManager $ httpLbs request
> putStrLn $ show request
> print $ responseBody response
>
>
> On Wed, May 28, 2014 at 2:48 PM, Miro Karpis <[email protected]>wrote:
>
>> Hi, I'm having difficulties with sending body parameters/values in a POST
>> request. It seems that the server does not receive in body.
>>
>> ideas/comments very welcome ;-)
>>
>> cheers,
>> m.
>>
>>
>> {-# LANGUAGE OverloadedStrings #-}
>>
>> import Network.HTTP.Conduit
>> import Data.Word(Word8)
>> import Data.ByteString.Lazy(pack)
>> import qualified Data.ByteString.Char8 as B
>>
>> x :: B.ByteString
>> x = "?value=10"
>>
>> post = do
>> r <- parseUrl "http://postcatcher.in/catchers/5385d4e0b6887c0200000071"
>> putStrLn $show r
>> let request = r
>> { secure = True
>> , method = "POST"
>> , requestBody = RequestBodyBS s
>> , requestHeaders = (requestHeaders r) ++ [("Content-Type",
>> "application/json")]}
>> putStrLn $ show request
>> response <- withManager $ httpLbs request
>> print $ responseBody response
>>
>>
>
> _______________________________________________
> 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/20140528/d535f235/attachment-0001.html>
------------------------------
Message: 4
Date: Wed, 28 May 2014 18:26:18 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Type class vs. Record: How do I model an
interface in Haskell?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi All,
I have another modeling related question. This time is about how to
model an interface in haskell.
(full code in https://github.com/defigueiredo/interfaces-in-haskell)
I have an interface that I want any Stock Exchange to follow. I can
think of 3 different ways to do this in Haskell:
- write a type class and then instantiate it for 3 different types
- use a record and associate the appropriate function to each field
- use a module and define the appropriate function in each file
These options seem to go from most restrictive to least restrictive. In
the sense that in the last solution I can make two functions calls:
print $ NYSE.getPendingOrders
print $ NASDAQ.getPendingOrders
and the getPendingOrders functions don't even need to have exactly the
same types between the two modules. I can see how this could be useful
sometimes.
Using record syntax is more restrictive as the type signatures for the
functions have to match, but I am not sure what I get from having a type
class here, rather than just the records. Comparing the model
declarations, the type class solution has an extra parameter 'a'
clobbering up the signatures:
model.hs
---------------------------------------------------------------------
module Model where
import Data.Time.Clock.POSIX
-- Units
type Volume = Double
type Price = Double
type OrderID = Int
type Timestamp = POSIXTime
-- Orders
data OrderType = Buy | Sell deriving Show
data Order = Order { order::OrderType,
price ::Price,
volume ::Volume,
confirmation :: Maybe (OrderID, Timestamp) }
deriving Show
------ All versions identical until here ------
class Exchange a where
sellAt :: a -> Price -> Volume -> Order
buyAt :: a -> Price -> Volume -> Order
getPendingOrders :: a -> Maybe [Order] -- returns [Order] or
Nothing if can't get that information
cancelOrder :: a -> OrderID -> Order -> Maybe (Either Order
Order) -- returns canceled order (right) or
-- what was still pending if already executed (left)
-- or Nothing, if has no connectivity (or other error).
---------------------------------------------------------------------
whereas the record solution is...
------ All versions identical until here ------
data Exchange = Exchange {
sellAt :: Price -> Volume -> Order,
buyAt :: Price -> Volume -> Order,
getPendingOrders :: Maybe [Order]
cancelOrder :: OrderID -> Order -> Maybe (Either Order Order),
}
---------------------------------------------------------------------
instances look pretty similar:
where's the type class solution...
---------------------------------------------------------------------
module NYSE where
import Model
data NYSE = NYSE
instance Exchange NYSE where
sellAt = error "NYSE doesn't sell."
getPendingOrders a = Just [Order Buy 50 100 Nothing]
buyAt = undefined
cancelOrder = undefined
---------------------------------------------------------------------
here's the record solution...
---------------------------------------------------------------------
module NYSE where
import Model
nyse = Exchange {
sellAt = error "NYSE doesn't sell.",
getPendingOrders = Just [Order Buy 50 100 Nothing],
buyAt = undefined,
cancelOrder = undefined
}
---------------------------------------------------------------------
So, my questions are:
1) What do I get from making this a type class rather than using records?
2) Is there an even better solution I have overlooked?
(full code for 3 different solutions in
https://github.com/defigueiredo/interfaces-in-haskell)
Thanks!
Dimitri
------------------------------
Message: 5
Date: Thu, 29 May 2014 09:01:33 +0300
From: Ovidiu Deac <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] installing cabal 1.20 on linux mint
debian edition (LMDE)
Message-ID:
<CAKVsE7s1202kd=WLhK5uc1=hkVPWxoWOVZct-849Rj5X=r2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm trying to install cabal 1.20 like this:
I installed ghc and ghc-prof from apt repository so I got the following:
ii ghc 7.6.3-5 amd64 The Glasgow Haskell
Compilation s
ii ghc-prof 7.6.3-5 amd64 Profiling libraries for the
Glasg
Then I git cloned cabal and checked out Cabal-v1.20.0.0
Then I ran bootstrap.sh in cabal-install dir and I get the following error:
Using gcc for C compiler. If this is not what you want, set CC.
Using /usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 instead.
Checking installed packages for ghc-7.6.3...
deepseq is already installed and the version is ok.
time is already installed and the version is ok.
Cabal is already installed and the version is ok.
transformers is already installed and the version is ok.
mtl is already installed and the version is ok.
text is already installed and the version is ok.
parsec is already installed and the version is ok.
network is already installed and the version is ok.
HTTP is already installed and the version is ok.
zlib is already installed and the version is ok.
random is already installed and the version is ok.
stm is already installed and the version is ok.
[...skipping many lines]
package cabal-install-1.20.0.0 requires network-2.4.1.2
Building cabal-install-1.20.0.0...
Preprocessing executable 'cabal' for cabal-install-1.20.0.0...
<command line>: cannot satisfy -package-id
network-2.4.1.2-fc99093587d92370c7febe034504fb40:
network-2.4.1.2-fc99093587d92370c7febe034504fb40 is shadowed by package
network-2.4.1.2-040cee5ece44014a8574cb3f87b1eec4
(use -v for more information)
Error during cabal-install bootstrap:
Building the cabal-install package failed.
What am I doing wrong here?
Thanks,
Ovidiu
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140529/282b7bc3/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 71, Issue 35
*****************************************