News aggregator

Debugging Wreq/http-client https requests

haskell-cafe - 0 sec ago
I have a program that is POST'ing some data to a remote server. However, some part of the data I'm sending is wrong I believe. If this were plain http without encryption, wireshark would allow me to see the exact data being sent over the wire. However, with https it is encrypted. Is there an inbuilt way to debug requests sent by wreq or more likely, a way to output debug info for http-client? Alternatively, is there a way to use NSS support with either of these libraries: http://security.stackexchange.com/questions/35639/decrypting-tls-in-wireshark-when-using-dhe-rsa-ciphersuites Thanks in advance to all for your time.
Categories: Offsite Discussion

Why such a cool language doesn't use S-expression syntax?

Haskell on Reddit - 8 hours 24 min ago

One of the nice things of S-expression syntax is its simplicity. Why isn't it popular with Haskellers?

submitted by dmz
[link] [8 comments]
Categories: Incoming News

Read And Return A Number

Haskell on Reddit - 8 hours 49 min ago

Hello, i was wondering how I would go about asking the user to input a number and then returning that number to whatever called the function. I am having trouble finding anything similar to this problem online.

What I have so far -

getNumber :: IO(Int) getNumber = do putStr "Enter a number" xs <- getLine

Any help would be appreciated! Thank you.

submitted by con7con
[link] [10 comments]
Categories: Incoming News

I'd like to repeat u/Categoria's question from a few months back: How does everyone format their source code properly? This is usually the main weakness of any text editor with haskell.

Haskell on Reddit - 11 hours 21 min ago

/u/cameleon's answer is helpful but I wonder if there isn't something more?

For example, wouldn't it be nice in Vim if I could just type:

data BlaBla = BlaBla { blipity :: Integer , blerg0 :: String , blerg1 :: String , blerg2 :: String , blerg3 :: String , blerg4 :: String , blerg5 :: String , blerg6 :: String }

And then hit gqa{ and have it turn into

data BlaBla = Blabla { blipity :: Integer , blerg0 :: String , blerg1 :: String , blerg2 :: String , blerg3 :: String , blerg4 :: String , blerg5 :: String , blerg6 :: String } submitted by rdfox
[link] [43 comments]
Categories: Incoming News

Wolfgang Jeltsch: Grapefruit updated

Planet Haskell - 14 hours 9 min ago

Yesterday, I updated the Grapefruit FRP library once again, this time to make it compatible with GHC 7.8. The new version is 0.1.0.5. To install or update, you can use the following commands:

cabal update cabal install grapefruit-ui-gtk grapefruit-examples

Many thanks to Samuel Gélineau for providing several patches. (By the way, Samuel maintains an interesting page that compares different FRP libraries, the FRP Zoo.)

Grapefruit 0.1 is actually a phase-out model, which I only update to work with newer GHC versions. However, I am working on a new Grapefruit. This will be based on my research about FRP semantics and will be quite different from the old one. I expect that the sound theoretical foundation will lead to a more powerful library with a more sensible interface. One particular new feature will be integration of side effects into FRP, in a purely functional style.


Tagged: FRP, Grapefruit, Haskell, Samuel Gélineau
Categories: Offsite Blogs

Yesod Web Framework: Slides on conduit and GHCJS

Planet Haskell - Thu, 10/30/2014 - 11:00pm

I'm currently sitting in a hotel room in Poznan, Poland, getting ready to attend the second day of PolyConf. In the past two days, I've already had quite some fun. Wednesday- thanks to Matthias Fischmann and Adam Drake- I spoke to the Berlin Haskell users group about conduit. I had no idea that there were this many Haskellers in Berlin, and it was awesome to meet all of you. Yesterday I spoke about Haskell on the client side at PolyConf, mostly talking about how awesome GHCJS is (after Luite indoctrinated me at ICFP).

For those interested, the slides are now available online at:

I've also learnt quite a number of cool client side tricks at PolyConf, hopefully we'll get to take advantage of some of them in Yesod in the near future :).

Categories: Offsite Blogs

エラー処理の抽象化

del.icio.us/haskell - Thu, 10/30/2014 - 10:34pm
Categories: Offsite Blogs

Question about dependent types in haskell

Haskell on Reddit - Thu, 10/30/2014 - 7:55pm

I was reading this question on SO about the meaning of being dependently typed and this part of the 2nd answer confused me:

By contrast, it's much trickier (i.e., impossible) to implement the function which makes n copies of a given x (which would be pure to vApply's <*>)

vReplicate :: x -> Vec n x

because it's vital to know how many copies to make at run-time. Enter singletons.

data Natty :: Nat -> * where Zy :: Natty Z Sy :: Natty n -> Natty (S n)

For any promotable type, we can build the singleton family, indexed over the promoted type, inhabited by run-time duplicates of its values. Natty n is the type of run-time copies of the type-level n :: Nat. We can now write

vReplicate :: Natty n -> x -> Vec n x vReplicate Zy x = VNil vReplicate (Sy n) x = VCons x (vReplicate n x)

Why is the type signature of vReplicate not Nat -> x -> Vec n x?

Is vReplicate impossible because we need the type of Vec to be indexed by a Nat, and when we can't know which Nat it will be until run time? So the type signature Nat -> x -> Vec n x does not make sense because we wan't the Nat to be in the type signature like (n :: Nat) -> x -> Vec n x (excuse the invalid syntax).

So then I guess the singleton gives us the ability to express n :: Nat in a type signature in haskell. data Natty :: Nat -> * means Natty is a function from a Nat to a Kind at the type level. So when Zy has type Natty Z, since Natty is a function from Nat to Kind, so Natty Z is a Kind, so we can put it in the type signature.

And finally just to clarify, when the poster is talking about "run-time number", he does not mean that it the numbers will be checked at run-time, he just means whatever number the function is called with at run-time?

I think I ended up answering most of my question but I'm gonna post this anyway because I'm not sure and I already typed it up.

submitted by 0Il0I0l0
[link] [3 comments]
Categories: Incoming News

Scrap your boilerplate

del.icio.us/haskell - Thu, 10/30/2014 - 7:41pm
Categories: Offsite Blogs

Printing out a list without brackets

Haskell on Reddit - Thu, 10/30/2014 - 7:18pm

I created a new data type that takes in a parameter of a list so I can keep track of what is inside of it

Ex: data Info a = Info [a]

it is similar to a Set in a way, however for my purpose I am choosing not to import Data.Set

Now I want to display the contents from a however when I try to list them out, I want to not include the square brackets

Ex:

x = Data [99, 21, 7, 1, 30]

x

[99, 21, 7, 1, 30]

I am looking for a way so it only prints

99, 21, 7, 1, 30

In a similar way, if it were strings, I would want

Data ["a,b,c,d"]

Edit: Data ["a", "b", "c", "d"]

"a", "b", "c", "d"

What is a way to include printing them off (using Show) so I don't include the square brackets?

submitted by seps427
[link] [11 comments]
Categories: Incoming News

Proposal: Add Alternative adapter to Data.Monoid

libraries list - Thu, 10/30/2014 - 5:46pm
I found myself needing this type in my current overhaul of Data.Foldable, but it seems to be generally useful: newtype Alt f a = Alt { getAlt :: f a } deriving (Eq,Ord,Show,Read,Typeable,Data,Generic,Num,Real, Floating, Fractional, RealFrac, RealFloat, Integral, Enum, Bounded,Ix,Functor,Foldable,Traversable,Applicative, Alternative,Monad,MonadPlus,MonadFix, IsString, IsList)
Categories: Offsite Discussion

XML schema bindings for haskell

Haskell on Reddit - Thu, 10/30/2014 - 4:34pm

I'm a newbie to haskell.

I'm working on a vocabulary mapping and translation system and I thought that it would make a good project for giving haskell a whirl.

Part of what I want to do is be able to specify vocabularies in detail in a readily machine-readable format. I could use RDF and an ontology but haskell seems a little light-on in the semantics department. So I thought that an XML document, backed by a schema that can be used to validate the document and generate language bindings in a variety of languages would work nicely. (It also gives me a chance to use XLST for documentation and such-like.)

Ultimately, I want to be able to define a fairly comprehensively specified and documented schema so that its a straight-forward task to use it with a new tool. Interoperability is god. I'm not really wedded to XSD; anything that provides a similar level of comprehensiveness and tool support is fine (DTDs are not, since I want any documentation and restrictions to be clearly visible). The source of the information is also fine; something that takes a haskell module and artfully placed comments and can generate a schema for other systems is also fine.

I've been looking through HXT, which seems to be the latest and greatest for this kind of thing. But I'm not seeing anything that matches theses requirements. Could somebody point me in a suitable direction?

submitted by orlock
[link] [7 comments]
Categories: Incoming News

Advice wanted: list of polymorphic elements

Haskell on Reddit - Thu, 10/30/2014 - 4:17pm

First, a bit of boilerplate, just ignore the next three lines:

data Color = Red | Green | Blue deriving Show type Radius = Float type Length = Float

Now imagine I have a few sorts of Fruit, and I want a function that work on any of them. The obvious way is to use typeclass:

{- data Apple = Apple Color Radius data Orange = Orange Radius data Banana = Banana Length Radius class Eatable a where eat :: a -> IO () instance Eatable Apple where eat (Apple c r) = putStrLn $ "eating " ++ (show c) ++ " apple" instance Eatable Orange where eat (Orange r) = putStrLn $ "eating juicy orange" instance Eatable Banana where eat (Banana l r) = putStrLn $ "eating banana" -}

Now forget what I just did, and imagine I have a few sorts of Fruit, and I want to keep them in a Basket (that I will implement in a list). The logical way to do it is:

data Fruit = Apple Color Radius | Orange Radius | Banana Length Radius type Basket = [Fruit]

Now different sorts of Fruit are distinguishable by constructor rather than by type. It is still possible to have a common 'eat' function:

eat :: Fruit -> IO () eat (Apple c r) = putStrLn $ "eating " ++ (show c) ++ " apple" eat (Orange r) = putStrLn $ "eating juicy orange" eat (Banana l r) = putStrLn $ "eating banana"

This way, I can have a

basket = [Apple Red 5, Apple Green 6, Banana 2 30]

and eat them all like this:

main = mapM_ eat basket

The problem is that with the second approach, it is impossible to put fruit-specific implementations of the eat function into separate source modules. With the first approach, it is easy to have instances in separate modules, but in order to put them all in a list I have to create a wrapper type with alternative constructors essentially duplicating the meaning of the type of the value that they wrap:

{- data Fruit = AppleC Apple | OrangeC Orange | BananaC Banana

which makes thigs very very ugly, e.g.:

basket = [AppleC (Apple Red 5), AppleC (Apple Green 6), BananaC (Banana 2 30)]

and eat cannot be used with mapM_ directly, making the whole affair rather painful, and polymorphism - pointless:

eatfruit :: Fruit -> IO () eatfruit (AppleC x) = eat x eatfruit (OrangeC x) = eat x eatfruit (BananaC x) = eat x main = mapM_ eatfruit basket -}

Is there an idiomatic way to put the eat function for Apple, Orange and Banana into separate modules and stay "not ugly"?

Thanks!

EDIT: Thanks for the insights, and especially for the pointer to Luke Palmer's article. Looks like placing the IO action inside the Fruit is the way to go for me.

submitted by lukewarm
[link] [11 comments]
Categories: Incoming News

<|> that short-circuits in IO ?

haskell-cafe - Thu, 10/30/2014 - 2:42pm
Dear Haskell-Cafe, Is there a way to get Control.Applicative.<|> to short-circuit when combining two IO actions? E.g. A B Right 42 B A Right 42 (In the latter case I don't want A in the output…) Many thanks for your help, Semen
Categories: Offsite Discussion

Help on understanding how to translate a Python program to Haskell?

Haskell on Reddit - Thu, 10/30/2014 - 2:40pm

So the title sounds kind of stupid given how hugely different the languages are, basically I've got a small program I wrote in Python, and I'd like to translate it to Haskell to learn more about the language. It's a pretty basic program, it has a list of objects which have two attributes, a question and an answer. The user can either add a new item to that list, or get quizzed on the items already in there.

I've been going through the book Learn You a Haskell, and it's great so far, but I can't seem to wrap my head around how even a simple program like this can be made in Haskell. Would the list of question/answer pairs, which were classes in Python, just be a list of tuples instead? What about extra information tied to the class, like last time studied, % correct, etc.? Just a big list with a bunch of numbers for each item? It seems like that would get confusing very quickly, so I'd love to hear how someone more experienced with this language would go about implementing something like this.

EDIT : Also, I know 'do' is considered bad/dangerous, but how do I avoid it? For example, say I want to prompt the user to enter something, then get his input, the only way I know how to do it is this :

do print "what would you like to do?" someFunc getLine

Is there a way to change this to use functions instead? Is this the best way or is there a better way? Probably stupid questions, just started learning the language, I appreciate any help.

submitted by mbuffett1
[link] [13 comments]
Categories: Incoming News