Re: [Haskell-cafe] Proposal: New syntax for Haskell

2013-09-12 Thread Bob Ippolito
Have you tried AppleScript? I wouldn't say it's pleasant to use, but it's
easy to read.

On Thursday, September 12, 2013, David Thomas wrote:

> I've long been interested in a scripting language designed to be spoken.
> Not interested enough to go about making it happen... but the idea is
> fascinating and possibly useful.
>
>
> On Thu, Sep 12, 2013 at 2:57 PM, Andreas Abel 
>  'andreas.a...@ifi.lmu.de');>
> > wrote:
>
>> **
>>
>> +1
>>
>> Cucumber seems to be great if you mainly want to read your code over the
>> telephone, distribute it via national radio broadcast, or dictate it to
>> your secretary or your voice recognition software.  You can program thus
>> without having to use you fingers.  You can lie on your back on your sofa,
>> close your eyes, and utter your programs...
>>
>> We could have blind Haskell/Cucumber programming contests...
>>
>> Tons of new possiblilities...
>>
>> Strongly support this proposal. ;-)
>>
>> Andreas
>>
>> On 2013-09-10 22:57, Artyom Kazak wrote:
>>
>> On Wed, 11 Sep 2013 00:20:26 +0400, Thiago Negri > > wrote:
>>
>> I hope these jokes do not cause people to be afraid to post new ideas.
>>
>> Agreed. I would also like to clarify that my message was much more a joke
>> on
>> the incomprehensibility of legal acts than on the original proposal.
>>
>> By the way, I am pretty impressed with this piece of Cucumber
>> description/code:
>>
>>Scenario: Mislav creates a valid task with an upload
>>  When I go to the "Awesome Ruby Yahh" task list page of the "Ruby
>> Rockstars" project
>>  When I follow "+ Add Task"
>>  And I fill in "Task title" with "Ohhh upload"
>>  And I follow "Attachment"
>>  When I attach the file "features/support/sample_files/dragon.jpg" to
>> "upload_file"
>>  And I press "Add Task"
>>  And I wait for 1 second
>>  And I should see "Ohhh upload" as a task name
>>
>> I was much more sceptical when I had only seen the example in Niklas’s
>> message.
>> ___
>> Haskell-Cafe mailing listhaskell-c...@haskell.org > 'Haskell-Cafe@haskell.org');>http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>>
>> --
>> Andreas Abel  <>< Du bist der geliebte Mensch.
>>
>> Theoretical Computer Science, University of Munich 
>> http://www.tcs.informatik.uni-muenchen.de/~abel/
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org > 'Haskell-Cafe@haskell.org');>
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reasoning about performance

2013-09-03 Thread Bob Ippolito
Haskell's non-strict evaluation can often lead to unexpected results when
doing tail recursion if you're used to strict functional programming
languages. In order to get the desired behavior you will need to force the
accumulator (with something like Data.List's foldl', $!,
seq, BangPatterns, etc.).

One issue with the tail recursive version is that you're basically
sequencing it twice, forcing the result is going to force the whole spine
of the list, and then you're walking it again with deepseq. The overhead of
the deepseq call with that size list on my machine is 2.2 seconds, so
you're basically paying that cost twice with a tail recursive version.
allPairs2 only forces what is needed, so deepseq isn't traversing any data
structures that are already forced.

I think what's happening with allPairs2 is that GHC is throwing away the
the list during the traversal since the result of the computation isn't
used at all. I get very different timings (still fast, but no longer orders
of magnitude difference) for allPairs2 if the result is still around. You
could probably figure this out with the heap profiler.

h> deepseq (allPairs2 [1..1]) True
True
(2.47 secs, 4403724176 bytes)
h> let x = allPairs2 [1..1]
(0.00 secs, 510488 bytes)
h> deepseq x True
True
(10.47 secs, 4401625192 bytes)
h> deepseq x True
True
(2.21 secs, 1031864 bytes)

I'm no expert, but I think that allPairs2 is likely as good as you're going
to get with straightforward Haskell using lists. It doesn't build up a lot
of unevaluated computation, and if you only need to see the first n
elements it's not going to have to process the entire input. allPairs1 has
most of the good properties of allPairs2 but is a bit worse because of the
concatenation, though concatenating in this way isn't a disaster like it
would be in a strict functional programming language.

-bob



On Tue, Sep 3, 2013 at 3:28 PM, Scott Pakin  wrote:

> I'm a Haskell beginner, and I'm baffled trying to reason about code
> performance, at least with GHC.  For a program I'm writing I needed to
> find all pairs of elements of a list.  That is, given the list "ABCD"
> I wanted to wind up with the list
> [('A','B'),('A','C'),('A','D')**,('B','C'),('B','D'),('C','D')**], where
> the order of elements in the resulting list is immaterial, but I don't
> want both ('A', 'B') and ('B', 'A'), for example.
>
> My first attempt looked like this:
>
> allPairs1 :: [a] -> [(a, a)]
> allPairs1 [] = []
> allPairs1 (x:xs) = map (\a  -> (x, a)) xs ++ allPairs1 xs
>
> Benchmarking with ghci's ":set +s" reveals the following performance
> (median of three runs shown):
>
> $ ghci
> GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
> Prelude> :!ghc -c -O2 allpairs.hs
> Prelude> :load allpairs
> Ok, modules loaded: AllPairs.
> Prelude AllPairs> :m +Control.DeepSeq
> Prelude Control.DeepSeq AllPairs> :show modules
> AllPairs ( allpairs.hs, allpairs.o )
> Prelude Control.DeepSeq AllPairs> :set +s
> Prelude Control.DeepSeq AllPairs> deepseq (allPairs1 [1..1]) True
> True
> (4.85 secs, 4004173984 bytes)
>
> A colleague suggested getting rid of the list append as follows:
>
> allPairs2 :: [a] -> [(a, a)]
> allPairs2 [] = []
> allPairs2 (x:xs) = allPairs2' x xs xs
>   where allPairs2' x [] [] = []
> allPairs2' x (y:ys) zs = (x,y) : allPairs2' x ys zs
> allPairs2' x [] (z:zs) = allPairs2' z zs zs
>
> Not surprisingly, that runs faster:
>
> Prelude Control.DeepSeq AllPairs> deepseq (allPairs2 [1..1]) True
> True
> (2.14 secs, 4403686376 bytes)
>
> I then figured I could do even better by rewriting the code
> tail-recursively:
>
> allPairs3 :: [a] -> [(a, a)]
> allPairs3 [] = []
> allPairs3 (x:xs) = allPairs3' x xs xs []
>   where allPairs3' :: a -> [a] -> [a] -> [(a, a)] -> [(a, a)]
> allPairs3' h (x:xs) ys result = allPairs3' h xs ys ((h,
> x):result)
> allPairs3' _ [] (y:ys) result = allPairs3' y ys ys result
> allPairs3' _ [] [] result = result
>
> This takes half the memory as the above (yay!) but runs substantially
> *slower* (and appears to be thrashing my computer's memory system):
>
> Prelude Control.DeepSeq AllPairs> deepseq (allPairs3 [1..1]) True
> True
> (10.58 secs, 2403820152 bytes)
>
> What gives?  Why does my tail-recursive implementation run even slower
> and presumably produce more garbage than my initial, naive
> implementation?  Is there some optimization GHC is performing for
> allPairs1 and allPairs2 that it can't apply to allPairs3?
>
> Similarly, how should I, as a newcomer who wants to write efficient
> Haskell code, reason about whether a code change is likely to improve
> rather than d

Re: [Haskell-cafe] function arithmetic?

2013-08-31 Thread Bob Ippolito
Yes, you can do that, but you probably shouldn't.

See also:
http://www.haskell.org/haskellwiki/Num_instance_for_functions
http://hackage.haskell.org/package/applicative-numbers



On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard <
christopher.how...@frigidcode.com> wrote:

> Hi. I was just curious about something. In one of my math textbooks I see
> expressions like this
>
> f + g
>
> or
>
> (f + g)(a)
>
> where f and g are functions. What is meant is
>
> f(a) + g(a)
>
> Is there a way in Haskell you can make use of syntax like that (i.e.,
> expressions like f + g and f * g to create a new function), perhaps by
> loading a module or something?
>
> __**_
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Debugging ByteString and Data.Binary.Get memory usage

2013-08-29 Thread Bob Ippolito
foldl' is the right way to simulate the sequential IO action, foldr would
be doing it in reverse (and for large enough input will stack overflow).


On Thu, Aug 29, 2013 at 9:33 PM, Kyle Hanson  wrote:

> Thanks Bob,
>
> I made it foldr because it was meant to simulate the sequential IO action
> that my server uses to populate the Map.
>
> I found the problem to be that I need to force the map to evaluate so
> adding a little $! fixed the problem
>
> --
> Kyle Hanson
>
>
>
>
> On Thu, Aug 29, 2013 at 9:09 PM, Bob Ippolito  wrote:
>
>> Building a map with foldr seems unwise, have you tried doing it with
>> fromListWith instead? Or foldl'? In either case, since you don't even put
>> the map into WHNF, none of the computation is done at all in either case
>> until the first lookup.
>>
>>
>> On Thu, Aug 29, 2013 at 3:35 PM, Kyle Hanson  wrote:
>>
>>> OK
>>>
>>> I have a bunch of BSON documents that I convert to ByteStrings, put in a
>>> Map, and write to a socket based on the response. I noticed some high
>>> memory usage (in the GBs) so I decided to investigate. I simplified my
>>> problem into a small program that demonstrates clearer what is happening.
>>>
>>> I wrote two versions, one with a Lazy Map and Lazy ByteStrings and one
>>> with a Strict Map and Strict ByteStrings. Both share the same memory
>>> behavior (except the lazy BS one is faster)
>>>
>>> Here is the strict version:
>>>
>>> http://lpaste.net/92298
>>>
>>> And here is the lazy version:
>>>
>>> http://lpaste.net/92299
>>>
>>> I wrote this and compared the memory and speed behavior of ByteStrings
>>> generated by converting it from a BSON document and ByteStrings generated
>>> more purely.
>>>
>>> The length of the ByteString from a BSON document is 68k and the length
>>> of the "pure" BS is 70k.
>>>
>>> This is my weird memory behavior, both BSON and "pure" methods use the
>>> same amount of memory after inserting 10k of them (90mb)
>>>
>>> However when I go to lookup a value, the BSON Map explodes the memory to
>>> over 250mb. Even if I lookup just 1 value. Looking up any number of values
>>> in the "pure BS" keeps the memory usage stable (90mb).
>>>
>>> I am hoping someone can help me understand this. I have read some posts
>>> about Temporary ByteStrings causing memory issues but I don't know how to
>>> get started debugging.
>>>
>>> --
>>> Kyle Hanson
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Debugging ByteString and Data.Binary.Get memory usage

2013-08-29 Thread Bob Ippolito
Building a map with foldr seems unwise, have you tried doing it with
fromListWith instead? Or foldl'? In either case, since you don't even put
the map into WHNF, none of the computation is done at all in either case
until the first lookup.


On Thu, Aug 29, 2013 at 3:35 PM, Kyle Hanson  wrote:

> OK
>
> I have a bunch of BSON documents that I convert to ByteStrings, put in a
> Map, and write to a socket based on the response. I noticed some high
> memory usage (in the GBs) so I decided to investigate. I simplified my
> problem into a small program that demonstrates clearer what is happening.
>
> I wrote two versions, one with a Lazy Map and Lazy ByteStrings and one
> with a Strict Map and Strict ByteStrings. Both share the same memory
> behavior (except the lazy BS one is faster)
>
> Here is the strict version:
>
> http://lpaste.net/92298
>
> And here is the lazy version:
>
> http://lpaste.net/92299
>
> I wrote this and compared the memory and speed behavior of ByteStrings
> generated by converting it from a BSON document and ByteStrings generated
> more purely.
>
> The length of the ByteString from a BSON document is 68k and the length of
> the "pure" BS is 70k.
>
> This is my weird memory behavior, both BSON and "pure" methods use the
> same amount of memory after inserting 10k of them (90mb)
>
> However when I go to lookup a value, the BSON Map explodes the memory to
> over 250mb. Even if I lookup just 1 value. Looking up any number of values
> in the "pure BS" keeps the memory usage stable (90mb).
>
> I am hoping someone can help me understand this. I have read some posts
> about Temporary ByteStrings causing memory issues but I don't know how to
> get started debugging.
>
> --
> Kyle Hanson
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "translating" recursively defined sequence

2013-03-04 Thread Bob Ippolito
I suppose it depends on your definition of straightforward but you can use
the iterate function from Data.List to quickly define sequences like this.

a = iterate (\x -> (1/5) * (x**2)) 10


On Mon, Mar 4, 2013 at 9:19 PM, Christopher Howard <
christopher.how...@frigidcode.com> wrote:

> Hi. My Haskell is (sadly) getting a bit rusty. I was wondering what
> would be the most straightforward and easily followed "procedure" for
> translating a recursively defined sequence into a Haskell function. For
> example, this one from a homework assignment.
>
> quote:
> 
> a_1 = 10
> a_(k+1) = (1/5) * (a_k)**2
> 
>
> (The underscore is meant to represent subscripting what follows it.)
>
> --
> frigidcode.com
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How does one create an input handle bound to a string instead of a file?

2013-02-27 Thread Bob Ippolito
I haven't had time to make an example yet but it looks like if you go down
to GHC.IO.Handle.Internals there's a mkHandle function that takes a
BufferedIO and some other stuff and gives you an IO Handle.


On Wed, Feb 27, 2013 at 3:23 PM, Gregory Collins wrote:

> Hm, perhaps I stand corrected. Then how exactly do you make the bytestring
> Handle?
>
>
> On Thu, Feb 28, 2013 at 12:15 AM, Don Stewart  wrote:
>
>> I don't think that's right - Simon's buffer class rewrite should have
>> made this possible, I think.
>>
>>
>> http://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/GHC-IO-BufferedIO.html
>> On Feb 27, 2013 10:52 PM, "Gregory Collins" 
>> wrote:
>>
>>> On Wed, Feb 27, 2013 at 9:38 PM, John D. Ramsdell 
>>> wrote:
>>>
 How does one create a value of type System.IO.Handle for reading that
 takes its input from a string instead of a file?  I'm looking for the
 equivalent of java.io.StringReader in Java.  Thanks in advance.

>>>
>>> You can't. There are several libraries that purport to provide better
>>> interfaces for doing IO in Haskell, like conduit, pipes, enumerator, and my
>>> own io-streams library (http://github.com/snapframework/io-streams,
>>> soon to be released). You could try one of those.
>>>
>>> G
>>> --
>>> Gregory Collins 
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>
>
> --
> Gregory Collins 
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] performance question

2013-02-12 Thread Bob Ippolito
On Tuesday, February 12, 2013, wrote:

> On Tue, 12 Feb 2013 15:57:37 -0700
> Nicolas Bock > wrote:
>
> > >  Here is haskell version that is faster than python, almost as fast as
> c++.
> > > You need to install bytestring-lexing package for readDouble.
>
>
> I was hoping Branimir could comment on how the improvements were allocated.
>
> how much is due to text.regex.pcre (which looks to be a wrapper to
> libpcre) ?
>
> how much can be attributed to using data.bytestring ?
>
> you have to admit, it's amazing how well a byte-compiled, _dynamically
> typed_ interpreter can do against an actualy native code compiler.  Can't
> regex be done effectively in haskell ?  Is it something that can't be done,
> or is it just such minimal effort to link to pcre that it's not worth the
> trouble ?


I think that there are two bottlenecks: the regex engine, and converting a
bytestring to a double. There doesn't appear to be a fast and accurate
strtod implementation for Haskell, and the faster regex implementations
that I could find appear to be unmaintained.


>
>
> Brian
>
> > > import Text.Regex.PCRE
> > > import Data.Maybe
> > > import Data.Array.IO
> > > import Data.Array.Unboxed
> > > import qualified Data.ByteString.Char8 as B
> > > import Data.ByteString.Lex.Double (readDouble)
> > >
> > > strataBounds :: UArray Int Double
> > > strataBounds = listArray (0,10) [ 0.0, 1.0e-8, 1.0e-7, 1.0e-6, 1.0e-5,
> > > 1.0e-4, 1.0e-3, 1.0e-2, 1.0e-1, 1.0, 2.0 ]
> > >
> > > newStrataCounts :: IO(IOUArray Int Int)
> > > newStrataCounts = newArray (bounds strataBounds) 0
> > >
> > > main = do
> > > l <- B.getContents
> > > let a = B.lines l
> > > strataCounts <- newStrataCounts
> > > n <- calculate strataCounts a 0
> > > let
> > > printStrataCounts :: IO ()
> > > printStrataCounts = do
> > > let s = round $ sqrt (fromIntegral n::Double) :: Int
> > > printf "read %d matrix elements (%dx%d = %d)\n" n s s n
> > > printStrataCounts' 0 0
> > > printStrataCounts' :: Int -> Int -> IO ()
> > > printStrataCounts' i total
> > > | i < (snd $ bounds strataBounds) = do
> > > count <- readArray strataCounts i
> > > let
> > > p :: Double
> > > p = (100.0*(fromIntegral count) ::
> > > Double)/(fromIntegral n :: Double)
> > > printf "[%1.2e, %1.2e) = %i (%1.2f%%) %i\n"
> (strataBounds
> > > ! i) (strataBounds ! (i+1))
> > > count p
> > > (total + count)
> > > printStrataCounts' (i+1) (total+count)
> > > | otherwise = return ()
> > > printStrataCounts
> > >
> > > calculate :: IOUArray Int Int -> [B.ByteString] -> Int -> IO Int
> > > calculate _ [] n = return n
> > > calculate counts (l:ls) n = do
> > > let
> > > a = case getAllTextSubmatches $ l =~ B.pack "matrix.*=
> > > ([0-9eE.+-]+)$" :: [B.ByteString] of
> > > [_,v] -> Just (readDouble v) :: Maybe (Maybe
> > > (Double,B.ByteString))
> > > _ -> Nothing
> > > b = (fst.fromJust.fromJust) a
> > > loop :: Int -> IO()
> > > loop i
> > > | i < (snd $ bounds strataBounds) =
> > > if (b >= (strataBounds ! i)) && (b < (strataBounds !
> > > (i+1)))
> > > then do
> > > c <- readArray counts i
> > > writeArray counts i (c+1)
> > > else
> > > loop (i+1)
> > > | otherwise = return ()
> > > if isNothing a
> > > then
> > > calculate counts ls n
> > > else do
> > > loop 0
> > > calculate counts ls (n+1)
> > >
> > >
> > > --
> > > From: nicolasb...@gmail.com 
> > > Date: Fri, 8 Feb 2013 12:26:09 -0700
> > > To: haskell-cafe@haskell.org 
> > > Subject: [Haskell-cafe] performance question
> > >
> > > Hi list,
> > >
> > > I wrote a script that reads matrix elements from standard input, parses
> > > the input using a regular expression, and then bins the matrix
> elements by
> > > magnitude. I wrote the same script in python (just to be sure :) ) and
> find
> > > that the python version vastly outperforms the Haskell script.
> > >
> > > To be concrete:
> > >
> > > $ time ./createMatrixDump.py -N 128 | ./printMatrixDecay
> > > real0m2.655s
> > > user0m2.677s
> > > sys 0m0.095s
> > >
> > > $ time ./createMatrixDump.py -N 128 | ./printMatrixDecay.py -
> > > real0m0.445s
> > > user0m0.615s
> > > sys 0m0.032s
> > >
> > > The Haskell script was compiled with "ghc --make printMatrixDecay.hs".
> > >
> > > Could you have a look at the script and give me some pointers as to
> where
> > > I could improve it, both in terms of performance and also generally,
> as I
> > > am very new to Haskell.
> > >
> > > Thanks already,
> > >
> > > nick
> > >
> > >

Re: [Haskell-cafe] Problem installing cabal-dev

2013-02-12 Thread Bob Ippolito
The version of cabal-dev on Hackage doesn't work with recent versions of
Haskell due to https://github.com/creswick/cabal-dev/issues/74 - You have
to install from a recent git checkout.

These instructions were done on Mac but should be straightforward enough to
do the same on Windows:
http://bob.ippoli.to/archives/2013/01/11/getting-started-with-haskell/#install-cabal-dev



On Tue, Feb 12, 2013 at 2:45 AM, David Turner  wrote:

> Hi,
>
> From a clean install of Haskell Platform 2012.4.0.0 (on Windows) I have
> issued just:
>
> > cabal update
> > cabal install cabal-install
> > cabal install cabal-dev
>
> The last command fails with:
>
> Resolving dependencies...
> In order, the following would be installed:
> tar-0.3.2.0 (new package)
> transformers-0.2.2.0 (new version)
> mtl-2.0.1.0 (new version)
> parsec-3.1.3 (reinstall) changes: mtl-2.1.2 -> 2.0.1.0
> network-2.3.2.0 (new version)
> HTTP-4000.2.8 (new version)
> cabal-dev-0.9.1 (new package)
> cabal: The following packages are likely to be broken by the reinstalls:
> network-2.3.1.0
> haskell-platform-2012.4.0.0
> cgi-3001.1.7.4
> HTTP-4000.2.5
> Use --force-reinstalls if you want to install anyway.
>
>
> I *think* the problem is that cabal-dev has these dependencies:
>
>   mtl >= 1.1 && < 2.1,
>   transformers >= 0.2 && < 0.3,
>
> where the latest version of mtl and transformers are 2.1.2 and 0.3
> respectively. At least, if I download the latest cabal-dev package and
> relax those upper bounds I can get it to install.
>
> The irony is, of course, that I'm trying to install cabal-dev to get me
> out of a totally unrelated dependencies hole!
>
> What should I do now?
>
> Cheers,
>
> --
> David Turner
> Senior Consultant
> Tracsis PLC
>
> Tracsis PLC is a company registered in
> England and Wales with number 5019106.
>
> __**_
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ticking time bomb

2013-02-12 Thread Bob Ippolito
The Python and Ruby communities are actively working on improving the
security of their packaging infrastructure. I haven't paid close attention
to any of the efforts so far, but anyone working on cabal/hackage security
should probably take a peek. I lurk on Python's catalog-sig list and here's
the interesting bits I've noticed from the past few weeks:

[Catalog-sig] [Draft] Package signing and verification process
http://mail.python.org/pipermail/catalog-sig/2013-February/004832.html

[Catalog-sig] [DRAFT] Proposal for fixing PyPI/pip security
http://mail.python.org/pipermail/catalog-sig/2013-February/004994.html

Python PyPi Security Working Document:
https://docs.google.com/document/d/1e3g1v8INHjHsUJ-Q0odQOO8s91KMAbqLQyqj20CSZYA/edit

Rubygems Threat Model:
http://mail.python.org/pipermail/catalog-sig/2013-February/005099.html
https://docs.google.com/document/d/1fobWhPRqB4_JftFWh6iTWClUo_SPBnxqbBTdAvbb_SA/edit

TUF: The Update Framework
https://www.updateframework.com/



On Fri, Feb 1, 2013 at 4:07 AM, Christopher Done wrote:

> Hey dude, it looks like we made the same project yesterday:
>
>
> http://www.reddit.com/r/haskell/comments/17njda/proposal_a_trivial_cabal_package_signing_utility/
>
> Yours is nice as it doesn't depend on GPG. Although that could be a
> nice thing because GPG manages keys. Dunno.
>
> Another diff is that mine puts the .sig inside the .tar.gz, yours puts
> it separate.
>
> =)
>
> On 31 January 2013 09:11, Vincent Hanquez  wrote:
> > On 01/30/2013 07:27 PM, Edward Z. Yang wrote:
> >>
> >> https://status.heroku.com/incidents/489
> >>
> >> Unsigned Hackage packages are a ticking time bomb.
> >>
> > I agree this is terrible, I've started working on this, but this is
> quite a
> > bit of work and other priorities always pop up.
> >
> > https://github.com/vincenthz/cabal
> > https://github.com/vincenthz/cabal-signature
> >
> > My current implementation generate a manifest during sdist'ing in cabal,
> and
> > have cabal-signature called by cabal on the manifest to create a
> > manifest.sign.
> >
> > The main issue i'm facing is how to create a Web of Trust for doing all
> the
> > public verification bits.
> >
> > --
> > Vincent
> >
> >
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] performance question

2013-02-09 Thread Bob Ippolito
I've been playing with your example to optimize it a bit, I have to run but
here's what I have so far. It's about as fast as the Python code, I'll make
it faster when I have more time over the next few days.

See https://gist.github.com/etrepum/4747507 and
https://gist.github.com/etrepum/4747507/revisions


On Sat, Feb 9, 2013 at 2:35 PM, Nicolas Bock  wrote:

>
>
>
> On Fri, Feb 8, 2013 at 1:23 PM, Aleksey Khudyakov <
> alexey.sklad...@gmail.com> wrote:
>
>> On 08.02.2013 23:26, Nicolas Bock wrote:
>>
>>> Hi list,
>>>
>>> I wrote a script that reads matrix elements from standard input, parses
>>> the input using a regular expression, and then bins the matrix elements
>>> by magnitude. I wrote the same script in python (just to be sure :) )
>>> and find that the python version vastly outperforms the Haskell script.
>>>
>>>  General performance hints
>>
>> 1) Strings are slow. Fast alternatives are text[1] for textual data and
>> bytestrings[2] for binary data. I can't say anything about performance of
>> Text.Regex.Posix.
>>
>> 2) Appending list wrong operation to do in performance sensitive code.
>> (++) traverses its first argument so it's O(n) in its length.
>>
>>
>> What exactly are you tryeing to do? Create a histogram?
>>
>>
>>
>>  The Haskell script was compiled with "ghc --make printMatrixDecay.hs".
>>>
>>>  If you want performance you absolutely should use -O2.
>>
>> Another question: When I compile the code with --make and -O2, and then
> run it on a larger matrix, I get this error message:
>
> $ ./createMatrixDump.py -N 512 | ./printMatrixDecay
> Stack space overflow: current size 8388608 bytes.
> Use `+RTS -Ksize -RTS' to increase it.
>
> When I use "runghc" instead, I don't get an error. What does this error
> mean, and how do I fix it?
>
> Thanks,
>
> nick
>
>
>
>>
>> [1] 
>> http://hackage.haskell.org/**package/text
>> [2] 
>> http://hackage.haskell.org/**package/bytestring
>>
>> __**_
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/**mailman/listinfo/haskell-cafe
>>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] performance question

2013-02-08 Thread Bob Ippolito
Do you mind posting createMatrixDump.py and printMatrixDecay.py? That would
certainly make it easier to help you.


On Fri, Feb 8, 2013 at 11:26 AM, Nicolas Bock  wrote:

> Hi list,
>
> I wrote a script that reads matrix elements from standard input, parses
> the input using a regular expression, and then bins the matrix elements by
> magnitude. I wrote the same script in python (just to be sure :) ) and find
> that the python version vastly outperforms the Haskell script.
>
> To be concrete:
>
> $ time ./createMatrixDump.py -N 128 | ./printMatrixDecay
> real0m2.655s
> user0m2.677s
> sys 0m0.095s
>
> $ time ./createMatrixDump.py -N 128 | ./printMatrixDecay.py -
> real0m0.445s
> user0m0.615s
> sys 0m0.032s
>
> The Haskell script was compiled with "ghc --make printMatrixDecay.hs".
>
> Could you have a look at the script and give me some pointers as to where
> I could improve it, both in terms of performance and also generally, as I
> am very new to Haskell.
>
> Thanks already,
>
> nick
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ticking time bomb

2013-01-30 Thread Bob Ippolito
HTTPS doesn't really change anything if the server is compromised, it only
prevents bad things from happening in transit.

Sign the packages with GPG (or equivalent) before upload. The server never
sees the package author's private key, only the public key. Server and/or
client can warn or fail if the public key doesn't match their previous
credentials or the signature verification fails.


On Wed, Jan 30, 2013 at 11:44 AM, Niklas Hambüchen  wrote:

> As long as we upload packages via plain HTTP, signing won't help though.
>
> On Wed 30 Jan 2013 19:27:32 GMT, Edward Z. Yang wrote:
> > https://status.heroku.com/incidents/489
> >
> > Unsigned Hackage packages are a ticking time bomb.
> >
> > Cheers,
> > Edward
> >
> > ___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mobile app development?

2013-01-19 Thread Bob Ippolito
LLVM probably already supports producing native code for all of the
architectures for the mobile platforms. The non-trivial parts are probably
getting GHC to cross-compile and wrapping all of the libraries you need for
the platforms you want to support.


On Sat, Jan 19, 2013 at 12:41 PM, KC  wrote:

> Then it looks as if the easier implementation would be small Haskell
> VM's for the various platforms with a byte code compiler.
> I do not believe the JVM supports all the optimizations GHC can do.
>
> Oh wait!
> Can the LLVM be easily ported to do this?
>
>
> On Sat, Jan 19, 2013 at 11:40 AM, Andrew Pennebaker
>  wrote:
> >
> >> Might be easier to have the browser connect to a Haskell app.
> >
> >
> > Not all apps can be run as thin clients. 3D video games and other
> intensive
> > programs aren't easily done as thin clients. Mobile Haskell would be very
> > powerful, because concurrency and parallelism aren't something the
> C-family
> > languages are supporting that well.
> >
> >>
> >>
> >>
> >> On Sat, Jan 19, 2013 at 10:42 AM, Andrew Pennebaker
> >>  wrote:
> >> > There are currently very few options, especially free and open source
> >> > options, when it comes to developing cross-platform mobile
> applications.
> >> > It's basically web apps with JavaScript, or C++. If Haskell supported
> >> > app
> >> > development on Android, iOS, and Windows RT, that alone would bring in
> >> > more
> >> > developers.
> >> >
> >> > Similarly, there are very few languages for mobile development that
> take
> >> > advantage of multiple cores and multiple CPUs. Haskell's `parmap` is
> an
> >> > amazing selling point. Can we please prioritize mobile support? I'd
> much
> >> > rather write everything in ML than PhoneGap.
> >> >
> >> > --
> >> > Cheers,
> >> >
> >> > Andrew Pennebaker
> >> > www.yellosoft.us
> >> >
> >> > ___
> >> > Haskell-Cafe mailing list
> >> > Haskell-Cafe@haskell.org
> >> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >> >
> >>
> >>
> >>
> >> --
> >> --
> >> Regards,
> >> KC
> >
> >
> >
> >
> > --
> > Cheers,
> >
> > Andrew Pennebaker
> > www.yellosoft.us
>
>
>
> --
> --
> Regards,
> KC
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] regular expression sub-expression matching

2013-01-18 Thread Bob Ippolito
Note that Haskell doesn't convert "\(" to "\\(" like Python does, so the
regex string has been changed. It's not so easy to figure out how to use
this library from the documentation because of all the typeclass trickery.

h> import Text.Regexp.Posix (getAllTextSubmatches, (=~))
h> getAllTextSubmatches ("M(1,2) = 0.1e-3;" =~ "M\\(([0-9]+),([0-9]+)\\) *=
*([0-9.eE-]+);") :: [String]
["M(1,2) = 0.1e-3;","1","2","0.1e-3"]

If it doesn't match, you'll get an empty list. You can join the tail of the
match list together with Data.List.intercalate, and print it out with
putStrLn. The if null case would just return ().

To demonstrate some of the typeclass trickery going on here, you could ask
for the results as an Array with Int indexes of String.

h> import Text.Regexp.Posix (getAllTextSubmatches, (=~))
h> import Data.Array ((!), Array)
h> let matches = getAllTextSubmatches ("M(1,2) = 0.1e-3;" =~
"M\\(([0-9]+),([0-9]+)\\) *= *([0-9.eE-]+);") :: Array Int String
h> matches
array (0,3) [(0,"M(1,2) = 0.1e-3;"),(1,"1"),(2,"2"),(3,"0.1e-3")]
h> map (matches !) [1..3]
["1","2","0.1e-3"]

-bob

On Fri, Jan 18, 2013 at 3:25 PM, Nicolas Bock  wrote:

> Hello list,
>
> I was wondering whether there is a way to do what the following python
> code does in haskell:
>
> import re
>
> result = re.compile("M\(([0-9]+),([0-9]+)\) *=
> *([0-9.eE-]+);").search("M(1,2) = 0.1e-3;")
> if result:
>   print(result.group(1), result.group(2), result.group(3))
>
> Basically I would like to pattern match parts of a string and return the
> matches. I have looked at Text.Regex.Posix but (of course I might just not
> have understood the functions in there properly) it seems as if it does not
> provide anything like python's re module.
>
> Thanks already,
>
> nick
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generating random arguments for a function

2013-01-13 Thread Bob Ippolito
I think it's more complicated because he doesn't know what the return type
or arity of the function is. In QuickCheck they know the return type of a
property is Bool. In this case, we only know that the return type is an
instance of Show. I don't think that's enough to simply implement this.

On Sunday, January 13, 2013, Stephen Tetley wrote:

> Yes - I was just checking the first QuickCheck paper to see how the
> authors did this.
>
> You would need a new type class that works like `Testable` and the
> versions of associated machinery `forAll` and `evaluate` to unroll
> function application.
>
>
> On 13 January 2013 09:28, Roman Cheplyaka >
> wrote:
>
> >
> > This can be done with relatively simple type class hackery. In fact,
> > QuickCheck already does that in order to generate arguments and print
> > them in case of failure.
> >
> > Roman
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org 
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe