Re: [Haskell-cafe] regex-applicative library needs your help! (algorithmic challenge)

2011-09-14 Thread Roman Cheplyaka
* Eugene Kirpichov ekirpic...@gmail.com [2011-09-14 08:38:10+0400]
 Hi,
 I don't see how fallback to NFA simulation is really a failure wrt DoS
 attacks. It's not exponential in time or memory, just linear memory
 (in size of regex) instead of constant, and slower than DFA.

Hi Eugene, thanks for pointing that out.

Indeed, I now see that he uses breadth-first rather than depth-first
search. Then he has the same problem as I do. I shall study his code
more closely.

-- 
Roman I. Cheplyaka :: http://ro-che.info/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Daniel Gorín
On Sep 14, 2011, at 5:29 AM, Kazu Yamamoto (山本和彦) wrote:

 Hello,
 
 Of course, I use ByteString or Text for real programming. But I would
 like to know whether or not there are any efficient methods to remove
 a tail part of a list.
 
 --Kazu

In that case, I would prefer this version, since it is lazier:

lazyChop :: String - String
lazyChop s = pref ++ if null s' then [] else (mid_sp ++ lazyChop s')
  where
(pref,sp_suf) = break isSpace s
(mid_sp,s')   = span isSpace sp_suf

By lazier I mean:

*Main chopReverse $ hello world  ++ undefined
*** Exception: Prelude.undefined
*Main chopFoldr $ hello world  ++ undefined
*** Exception: Prelude.undefined
*Main lazyChop $ hello world  ++ undefined
hello world*** Exception: Prelude.undefined

Daniel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread 山本和彦
Hello,

My friend reached the following version:

chop :: String - String
chop = foldr go []
  where
go x xs
  | isSpace x  null xs = []
  | otherwise= x:xs

This version is faster than the reverse version in most cases.  The
point is checking isSpace first and falling into otherwise in many
cases, which is a natural co-recursion.

Thanks anyway.

--Kazu

 Hello,
 
 Of course, I use ByteString or Text for real programming. But I would
 like to know whether or not there are any efficient methods to remove
 a tail part of a list.
 
 --Kazu
 
 In that case, I would prefer this version, since it is lazier:
 
 lazyChop :: String - String
 lazyChop s = pref ++ if null s' then [] else (mid_sp ++ lazyChop s')
   where
 (pref,sp_suf) = break isSpace s
 (mid_sp,s')   = span isSpace sp_suf
 
 By lazier I mean:
 
 *Main chopReverse $ hello world  ++ undefined
 *** Exception: Prelude.undefined
 *Main chopFoldr $ hello world  ++ undefined
 *** Exception: Prelude.undefined
 *Main lazyChop $ hello world  ++ undefined
 hello world*** Exception: Prelude.undefined
 
 Daniel

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Roman Cheplyaka
* Kazu Yamamoto k...@iij.ad.jp [2011-09-14 15:59:05+0900]
 Hello,
 
 My friend reached the following version:
 
 chop :: String - String
 chop = foldr go []
   where
 go x xs
   | isSpace x  null xs = []
   | otherwise= x:xs
 
 This version is faster than the reverse version in most cases.  The
 point is checking isSpace first and falling into otherwise in many
 cases, which is a natural co-recursion.

This was exactly my first attempt on rewriting your foldr version.

Unfortunately, it doesn't seem faster at all (foldr2 below).
The test input was replicate 100 'a' ++ replicate 100 ' '.
GHC 7, -O2.

benchmarking all/foldr
mean: 2.808462 us, lb 2.807047 us, ub 2.810520 us, ci 0.950
std dev: 8.620822 ns, lb 6.535738 ns, ub 11.59552 ns, ci 0.950

benchmarking all/reverse
mean: 4.128217 us, lb 4.125409 us, ub 4.134086 us, ci 0.950
std dev: 20.07591 ns, lb 11.47572 ns, ub 38.33738 ns, ci 0.950

benchmarking all/foldr2
mean: 6.701714 us, lb 6.692093 us, ub 6.711627 us, ci 0.950
std dev: 50.06638 ns, lb 42.25004 ns, ub 64.84223 ns, ci 0.950


-- 
Roman I. Cheplyaka :: http://ro-che.info/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread 山本和彦
You can find the results of my friend:

https://gist.github.com/1215660

Please ignore the Japanese text. Please read the code and the results.
I'm not sure why you had the different result.

--Kazu

 This was exactly my first attempt on rewriting your foldr version.
 
 Unfortunately, it doesn't seem faster at all (foldr2 below).
 The test input was replicate 100 'a' ++ replicate 100 ' '.
 GHC 7, -O2.
 
 benchmarking all/foldr
 mean: 2.808462 us, lb 2.807047 us, ub 2.810520 us, ci 0.950
 std dev: 8.620822 ns, lb 6.535738 ns, ub 11.59552 ns, ci 0.950
 
 benchmarking all/reverse
 mean: 4.128217 us, lb 4.125409 us, ub 4.134086 us, ci 0.950
 std dev: 20.07591 ns, lb 11.47572 ns, ub 38.33738 ns, ci 0.950
 
 benchmarking all/foldr2
 mean: 6.701714 us, lb 6.692093 us, ub 6.711627 us, ci 0.950
 std dev: 50.06638 ns, lb 42.25004 ns, ub 64.84223 ns, ci 0.950
 
 
 -- 
 Roman I. Cheplyaka :: http://ro-che.info/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell] [ANNOUNCE] Haskdogs-0.1

2011-09-14 Thread Sergey Mironov
2011/9/14 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com:
 Re-cc'ing -cafe:

 On 14 September 2011 14:29, yi huang yi.codepla...@gmail.com wrote:
 On Wed, Sep 14, 2011 at 11:32 AM, Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com wrote:

 On 14 September 2011 13:27, yi huang yi.codepla...@gmail.com wrote:
  On Wed, Sep 14, 2011 at 10:18 AM, Ivan Lazar Miljenovic
  ivan.miljeno...@gmail.com wrote:
 
  On 14 September 2011 11:24, yi huang yi.codepla...@gmail.com wrote:
   Cabal compains about Unknown build tool hasktags.
   It seems not necessary to set Build-tools: hasktags in cabal file?
 
  cabal-install isn't capable of automatically building and installing
  build-tools for you.  So to install haskdogs, you need to do cabal
  install hasktags  cabal install haskdogs.
 
  I have installed hasktags, and .cabal/bin is in my PATH, i can run
  hasktags
  directly from shell.
  What else did i miss?

 How did you specify your PATH?  You can't use ~/.cabal/bin, you need
 either $HOME/.cabal/bin or the fully expanded path.

 It is $HOME/.cabal/bin , and `which hasktags' can find it without problem.
 Cabal 1.10.2, ghc 7.0.4, i'm trying to look into cabal source to find the
 problem.

 Actually... looks like you're right.  I can't build it either, he
 appears to have hard-coded some paths in and it appears that you need
 some kind of magic to register a program as a build tool (that's what
 the error is from: hasktags isn't a registered build-tool).

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


Yes, I forgot to mention PATH. I expect somthing like

export PATH=$HOME/.cabal/bin:$PATH

in .bash_profile or similar.

Also, I probably should remove hasktags from the build-tools. Better
check it's presense in tuntime.

Thanks a lot,
Sergey

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell] [ANNOUNCE] Haskdogs-0.1

2011-09-14 Thread Ivan Lazar Miljenovic
On 14 September 2011 19:18, Sergey Mironov ier...@gmail.com wrote:

 Yes, I forgot to mention PATH. I expect somthing like

 export PATH=$HOME/.cabal/bin:$PATH

 in .bash_profile or similar.

 Also, I probably should remove hasktags from the build-tools. Better
 check it's presense in tuntime.

You also seemed to have some hard-coded paths to have it in
~/.cabal/var; this assumes that people use cabal-install to install
your package rather than a system package manager or the like.  Is it
possible to change that?

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Daniel Fischer
On Wednesday 14 September 2011, 09:17:16, Kazu Yamamoto wrote:
 You can find the results of my friend:
 
 https://gist.github.com/1215660
 
 Please ignore the Japanese text. Please read the code and the results.
 I'm not sure why you had the different result.

Input size. The lazy foldr combinator gets compiled to a bigger, more 
complicated function. When the input is short, the code size makes it 
slower. But when the input is long, the lazy foldr wins because it can 
produce incremental results while the strict foldr combinator and revChop 
need to traverse the entire list before they can produce anything - except 
for the case of 'spaces', where indeed the strict foldr combinator is 
(slightly) faster.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Victor Nazarov
On Wed, Sep 14, 2011 at 6:45 AM, Casey McCann c...@uptoisomorphism.net wrote:
 On Tue, Sep 13, 2011 at 10:03 PM, Chris Smith cdsm...@gmail.com wrote:
 Ah, okay... then sure, you can do this:

 class Tuple a b c | a b - c where
    tuple :: a - b - c

 instance Tuple (a - b, a - c) a (b,c) where
    tuple (f,g) x = (f x, g x)

 This wouldn't actually work well in practice. There's no dependency
 between the various occurrences of a in the types, so unless they're
 already known to be the same, GHC will complain about an ambiguous
 instance (please excuse the silly GHCi prompt):

    Ok, modules loaded: Tupling.
    ∀x. x ⊢ tuple ((+3), show) 4

    interactive:0:1:
        No instance for (Tuple (a0 - a0, a1 - String) b0 c0)
          arising from a use of `tuple'

 Given that the class is only intended to be used where those types are
 equal, you really want it to unify them based on use of the tuple
 function.

 and so on...  You'll need fundeps (or type families if you prefer to
 write it that way), and probably at least flexible and/or overlapping
 instances, too, but of course GHC will tell you about those.

 I rather prefer type families in this case, both because the problem
 is easily expressed in type function style, and because it gives you
 an easy type equality constraint to use, rather than using arcane
 trickery with overlaps to force post-hoc unification. We'd probably
 want to do something like this:

    class Tuple t where
        type Arg t :: *
        type Result t :: *
        tuple :: t - Arg t - Result t

    instance (x1 ~ x2) = Tuple (x1 - a, x2 - b) where
        type Arg (x1 - a, x2 - b) = x1
        type Result (x1 - a, x2 - b) = (a, b)
        tuple (f, g) x = (f x, g x)

    instance (x1 ~ x2, x2 ~ x3) = Tuple (x1 - a, x2 - b, x3 - c) where
        type Arg (x1 - a, x2 - b, x3 - c) = x1
        type Result (x1 - a, x2 - b, x3 - c) = (a, b, c)
        tuple (f, g, h) x = (f x, g x, h x)

 Used like so:

    Ok, modules loaded: Tupling.
    ∀x. x ⊢ tuple ((+2), show, ( 2)) 3
    (5,3,False)

 Note that not only does this avoid ambiguity, it even unifies
 ambiguous types that are then defaulted by the usual means.

 That said, I question the utility of a class like this. The
 boilerplate instances are tedious to write and it's not flexible in
 any way; tuples not being defined inductively makes them a real pain
 to work with unless there's a particularly good reason to do so.
 Something equivalent to right-nested (,) with () as a terminator is
 much more pleasant, and since we're deep in the pits of
 non-portability anyway, might as well pull out bang patterns and
 UNPACK pragmas if avoiding extra bottoms was the reason for using
 plain tuples.


I've just tried another approach (code below). And GHC even inferred
type for tupleF. But I think GHC inferred the wrong type and I can't
formulate the right one, it seems to require infinite number of
constraints. With GHC inferred type this function is not usable,
though:

*Tuples tupleF ((+2), show, (2)) 3

interactive:1:0:
Couldn't match expected type `TTail
(a - a, a1 - String, a2 - Bool)'
   against inferred type `(a - a, a1 - String, a2 - Bool)'
  NB: `TTail' is a type function, and may not be injective
When generalising the type(s) for `it'

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
module Tuples where

class Tuple t
class (Tuple t, Tuple (TTail t)) = NTuple t
  where
type THead t :: *
type TTail t :: *
thead :: t - THead t
ttail :: t - TTail t
tcons :: THead t - TTail t - t

newtype Tuple1 a = Tuple1 a

instance Tuple ()
instance Tuple (Tuple1 a)
instance NTuple (Tuple1 a)
  where
type THead (Tuple1 a) = a
type TTail (Tuple1 a) = ()
thead (Tuple1 a) = a
ttail (Tuple1 a) = ()
tcons a b = Tuple1 a
instance Tuple (a, b)
instance NTuple (a, b)
  where
type THead (a, b) = a
type TTail (a, b) = Tuple1 b
thead (a, b) = a
ttail (a, b) = Tuple1 b
tcons a (Tuple1 b) = (a, b)
instance Tuple (a, b, c)
instance NTuple (a, b, c)
  where
type THead (a, b, c) = a
type TTail (a, b, c) = (b, c)
thead (a, b, c) = a
ttail (a, b, c) = (b, c)
tcons a (b, c) = (a, b, c)

tupleF t a = thead t a `tcons` tupleF (ttail t) a


-- 
Victor Nazarov

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Final CFP: PEPM12 - Workshop on Partial Evaluation and Program Manipulation

2011-09-14 Thread oleg

Final Call For Papers
Paper submission deadline: Mon, October 10, 2011, 23:59, GMT

ACM SIGPLAN 2012 Workshop on Partial Evaluation and Program Manipulation
January 23-24, 2012. Philadelphia, Pennsylvania, USA (co-located with POPL'12)

http://www.program-transformation.org/PEPM12

The PEPM Symposium/Workshop series aims to bring together researchers
and practitioners working in the broad area of program transformation,
which spans from refactoring, partial evaluation, supercompilation,
fusion and other metaprogramming to model-driven development, program
analyses including termination, inductive programming, program
generation and applications of machine learning and probabilistic
search. PEPM focuses on techniques, supporting theory, tools, and
applications of the analysis and manipulation of programs. Each
technique or tool of program manipulation should have a clear,
although perhaps informal, statement of desired properties, along with
an argument how these properties could be achieved.

Topics of interest for PEPM'12 include, but are not limited to:

 - Program and model manipulation techniques such as:
   supercompilation, partial evaluation, fusion, on-the-fly program 
   adaptation, active libraries, program inversion, slicing, 
   symbolic execution, refactoring, decompilation, and obfuscation.

 - Program analysis techniques that are used to drive program/model
   manipulation such as: abstract interpretation, termination
   checking, binding-time analysis, constraint solving, type systems, 
   automated testing and test case generation.

 - Techniques that treat programs/models as data objects including
   metaprogramming, generative programming, embedded domain-specific
   languages, program synthesis by sketching and inductive programming, staged
   computation, and model-driven program generation and transformation.

 - Application of the above techniques including case studies of
   program manipulation in real-world (industrial, open-source)
   projects and software development processes,  descriptions of
   robust tools capable of effectively handling realistic applications,
   benchmarking. Examples of application domains include legacy
   program understanding and transformation, DSL implementations, 
   visual languages and end-user programming, scientific computing, 
   middleware frameworks and infrastructure needed for distributed and 
   web-based applications, resource-limited computation, and security.

To maintain the dynamic and interactive nature of PEPM, we will
continue the category of `short papers' for tool demonstrations and
for presentations of exciting if not fully polished research, and of
interesting academic, industrial and open-source applications that are
new or unfamiliar.

Student attendants with accepted papers can apply for a SIGPLAN PAC grant to
help cover travel expenses and other support.

All accepted papers, short papers included, will appear in formal
proceedings published by ACM Press and will be included in the ACM Digital
Library. Selected papers may later on be invited for a journal special
issue dedicated to PEPM'12.


Submission Categories and Guidelines

Authors are strongly encouraged to consult the advice for authoring
research papers and tool papers before submitting. The PC Chairs
welcome any inquiries about the authoring advice.

Regular research papers must not exceed 10 pages in ACM Proceedings
style.  Short papers are up to 4 pages in ACM Proceedings
style. Authors of tool demonstration proposals are expected to present
a live demonstration of the described tool at the workshop (tool
papers should include an additional appendix of up to 6 extra pages
giving the outline, screenshots, examples, etc.  to indicate the
content of the proposed live demo at the workshop).

Important Dates

 - Paper submission: Mon, October 10, 2011, 23:59, GMT
 - Author notification: Tue, November 8, 2011
 - Workshop: Mon-Tue, January 23-24, 2012


Invited Speakers

 - Markus Pueschel (ETH Zurich, Switzerland)
 - Martin Berger   (University of Sussex, UK)


Program Chairs

 - Oleg Kiselyov (Monterey, CA, USA)
 - Simon Thompson (University of Kent, UK)

Program Committee Members

 - Emilie Balland (INRIA, France)
 - Ewen Denney (NASA Ames Research Center, USA)
 - Martin Erwig (Oregon State University, USA)
 - Sebastian Fischer (National Institute of Informatics, Japan)
 - Lidia Fuentes (Universidad de Malaga, Spain)
 - John Gallagher (Roskilde University, Denmark and IMDEA Software, Spain)
 - Dave Herman (Mozilla Research, USA)
 - Stefan Holdermans (Vector Fabrics, the Netherlands)
 - Christian Kaestner (University of Marburg, Germany)
 - Emanuel Kitzelmann (International Computer Science Institute, USA)
 - Andrei Klimov (Keldysh Institute of Applied Mathematics, Russian Academy of
Sciences)
 - Shin-Cheng Mu (Academia Sinica, Taiwan)
 - Alberto Pardo (Universidad de la Repu'blica, Uruguay)
 - Kostis Sagonas (Uppsala University, Sweden and National Technical
  

Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Casey McCann
On Wed, Sep 14, 2011 at 9:32 AM, Victor Nazarov
asviraspossi...@gmail.com wrote:
 I've just tried another approach (code below). And GHC even inferred
 type for tupleF. But I think GHC inferred the wrong type and I can't
 formulate the right one, it seems to require infinite number of
 constraints. With GHC inferred type this function is not usable,
 though:

GHC can't actually infer your type with that implementation of tcons.
There's no way for it to get from the arguments THead t and TTail
t to the tuple type t, because (unlike type constructors) type
families aren't necessarily injective, so there could be more than one
type t that THead and TTail map to the types received. Furthermore,
the open world assumption for type families means that even if there's
only one valid t in scope, it can't simply select that because it
must account for the possibility of more instances being introduced in
other scopes.

On the other hand, it can get from t to THead t and TTail t just
fine, so if you give a type annotation that fixes the result type it
should work. But that can be clumsy for actual use.

The above issue is exactly why the implementation that I gave uses a
slightly peculiar approach to calculate the other types based only on
the type of the tuple argument. A slightly more complicated approach
could probably be used to get some inference going in both directions,
but in most cases the direction I gave will be what you want most.

That said, the essential idea of what you're trying to do is a good
one. Why not try separating the steps, though? Use one type family to
give a bijection between standard tuples and some sort of right-nested
pair representation (which is easy to infer both ways), then use
standard type-level recursion to process the latter form however you
like. You can do generic equivalents of map, fold, zip, c. this way
pretty easily.

- C.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Sean Leather
On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote:

 I would like to have an efficient implementation of the chop function.


[...]


 Are there any more efficient implementations of chop? Any suggestions?


  chop xs = go xs id 
where
  go  _   = id
  go (c:cs) ss | isSpace c  = go cs (ss . (:) c)
  go (c:cs) ss | otherwise  = ss . (:) c . go cs id

I haven't looked at the performance, but I would like to know how well it
fares.

Regards,
Sean
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Ivan Lazar Miljenovic
On 15 September 2011 01:24, Sean Leather leat...@cs.uu.nl wrote:
 On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote:

 I would like to have an efficient implementation of the chop function.

 [...]


 Are there any more efficient implementations of chop? Any suggestions?

   chop xs = go xs id 
     where
       go      _               = id
       go (c:cs) ss | isSpace c  = go cs (ss . (:) c)
       go (c:cs) ss | otherwise  = ss . (:) c . go cs id

Why the extra case for go?  The otherwise guard can be part of the
second case...

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Undefined symbol error coming from shared, dynamic library.

2011-09-14 Thread Captain Freako
Hi Sergiy,

*I thought having static library to solve my problem. And I'm looking for
how to build static library, but no luck.
*
I was also, originally trying to build a shared *static* library.
(I wanted to distribute a plug-in, which could be used by people knowing
nothing about Haskell working on machines that did not have the Haskell
Platform installed.)

Then, I happened across this nugget in section 4.11.3 of the GHC 6.12.3
User's 
Guidefile:///usr/share/doc/ghc6-doc/html/users_guide/using-shared-libs.html#id2620284
:

In principle you can use -shared without -dynamic in the link step. That
 means to statically link the rts all the base libraries into your new shared
 library. This would make a very big, but standalone shared library. Indeed
 this is exactly what we must currently do on Windows where -dynamic is not
 yet supported (see Section 11.6, “Building and using Win32 DLLs ”). On
 most platforms however that would require all the static libraries to have
 been built with -fPIC so that the code is suitable to include into a
 shared library and we do not do that at the moment.


That is when I changed strategies and started trying to make a shared *
dynamic* version of my library work.

*A question to the group:

*With regard to:

... that would require all the static libraries to have been built with
-fPIC ...,

is this something I can do myself by re-cabaling with the proper options set
in my *~/.cabal/config* file, or is this more involved than that?

Thanks,
-db

On Sun, Sep 11, 2011 at 8:55 AM, Sergiy Nazarenko 
nazarenko.ser...@gmail.com wrote:

 Hi, Captain,

 As far as I see you try to build static library.
 If this correct, what did not work in static library?
 Why do you decide compile with -dynamic option?

 I was trying to build shared library. Other python library has used
 some functions from library which I had written using Haskell. But
 some software which we use in my company had crached after attempts to
 import python module. Under pure python it works OK, but software has
 crached. I thought having static library to solve my problem. And I'm
 looking for how to build static library, but no luck.

 Cheers,
 Sergiy

 On 11 September 2011 17:56, Captain Freako capn.fre...@gmail.com wrote:
  Sergiy, Tom,
 
  Thanks for your replies.
 
  Sergiy, I was able to get this working without having to recompile my
  installed Haskell libraries.
 
  Tom, you were correct; I needed to explicitly link against the Haskell
  run-time system, as well as a few other things:
 
  I changed my ghc link options from this:
 
  HC_LOPTS = -no-hs-main -shared -package parsec -package dsp -static
 
  to this:
 
  HC_LOPTS = -shared -dynamic -package parsec-3.1.1 -package dsp -lHSrts
  -L/usr/lib/ghc-6.12.3/ -lm -lffi -lrt
 
  and things are working.
 
  (The command that builds my mixed language, shared object library,
  `libami.so', is:
 
  ghc -o libami.so $(HC_LOPTS) {object files, compiled from both C and
 Haskell}
  )
 
  I can understand why I'd have to explicitly link against `libHSrts',
  since I'm asking ghc for a shared object library and not an
  executable. However, I'm not sure about the following:
  - Why do I need to give the `-L/usr/lib/ghc-6.12.3/' option? (It seems
  like ghc ought to know about that, implicitly.)
  - Why do I need to explicitly link against the 3 standard C libraries:
  `m', `ffi', and `rt'? (I've never needed to do this, previously, when
  I was building/testing this project statically.)
 
  Thanks, in advance, for any insights!
 
  -db
 
 
  On 9/10/11, Sergiy Nazarenko nazarenko.ser...@gmail.com wrote:
  I've recompiled my library again and now it works without any problem.
  Probably I made mistake somewhere.
 
  Cheers,
  Sergiy
 
  ___
  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] Undefined symbol error coming from shared, dynamic library.

2011-09-14 Thread Sergiy Nazarenko
Hi, Captain !
I got haskell shared libraries with following cabal command:

cabal install --global --reinstall --disable-library-profiling
--enable-shared  --ghc-option=-dynamic mtl
and so on.

It allowed me to get haskell libraries and I could compile my own
shared libraries. And ldd helps me to know which libraries need me to
use them on users computers with my library. I believe this cabal
options can set in ~/.cabal/config or somethisg like this. In my case
I merely create shell script and call it cabal-shared.sh. :)

There is my options to compile my library:

ghc -O2 --make -no-hs-main -dynamic -shared -fPIC -optl '-shared'
-optc '-DMODULE=MyLibModule' -o MyLibModule.so MyLibModule.hs
module_init.c -optl-Wl -lHSrts-ghc7.0.2

where module_init.c has contents:

#define CAT(a,b) XCAT(a,b)
#define XCAT(a,b) a ## b
#define STR(a) XSTR(a)
#define XSTR(a) #a

#include HsFFI.h

extern void CAT (__stginit_, MODULE) (void);

static void library_init (void) __attribute__ ((constructor));
static void library_init (void)
{
  /* This seems to be a no-op, but it makes the GHCRTS envvar work. */
  static char *argv[] = { STR (MODULE) .so, 0 }, **argv_ = argv;
  static int argc = 1;

  hs_init (argc, argv_);
  hs_add_root (CAT (__stginit_, MODULE));
}

static void library_exit (void) __attribute__ ((destructor));
static void library_exit (void) {  hs_exit (); }


Cheers,
Sergiy

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Turn GC off

2011-09-14 Thread Andreas Voellmy
Hi everyone,

Is there a way to completely turn garbage collection off in the Haskell
runtime system? I'm aware of the -A runtime option, but I'd like to
completely turn it off, if possible. I'm OK with running the program until
it runs out of memory, and I'm willing to recompile GHC if needed.

Regards,
Andreas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Donn Cave
Quoth Ivan Lazar Miljenovic ivan.miljeno...@gmail.com,

 Why the extra case for go?  The otherwise guard can be part of the
 second case...

I noticed that myself, so I thought let's see if it's just a matter of
style that comes out the same after compilation ...

... and after a few minutes fooling around with that, I'm none the wiser.
I could not, within the time allotted, make out what's going on in the
-fvia-C .hc files.  I guess the way to answer questions like this is to
apply the function in question to massive amounts of data and infer the
answer from resulting performance?

Donn

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] cabal-install to produce a dependency tree

2011-09-14 Thread Ozgur Akgun
Dear Cafe,

What would be the easiest way of generating the following output, given a
package name optionally with additional constraints?

$- foo X  3
X  3 depends on A-2.2, B-1.0, C-1.2
A-2.2 depends on D-1.2.3
...

I assume cabal-install internally does this anyway while creating the
installation plan, so is there an easy way to get this info out of cabal
install?

Thanks,
Ozgur
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] efficient chop

2011-09-14 Thread wren ng thornton

On 9/13/11 11:03 PM, Kazu Yamamoto (山本和彦) wrote:

Hello Cafe,

I would like to have an efficient implementation of the chop function.
As you guess, the chop function drops spaces in the tail of a list.

chop  foo  bar baz   
- foo  bar baz

A naive implementation is as follows:

 chopReverse :: String -  String
 chopReverse = reverse . dropWhile isSpace . reverse

But this is not elegant.


Just consider it as an automaton/transducer problem, namely a PDA:

chop = go 0 []
where
-- go :: State - Stack - String - String
go 0 _ [] = []
go 0 _ (x:xs)
| isSpace x = go 1 [x] xs
| otherwise = x : go 0 xs

go 1 ss [] = []
go 1 ss (x:xs)
| isSpace c = go 1 (x:ss) xs
| otherwise = reverse ss ++ x : go 0 xs

Of course you can optimize this implementation. You don't actually need 
the state argument, since it's encoded by the emptiness/non-emptiness of 
the remembered spaces. And if you only care about (==' ') instead of 
isSpace, then you don't need to reverse the spaces when adding them back 
on. Also, if you only care about (==' '), you could just keep track of 
the number of spaces instead of the actual list of them; or if you do 
care about isSpace you could also use a difference list instead of doing 
the reversal--- though I'm not sure which is more optimal here.


As a transducer, this version can produce the output with minimal 
delays; whereas your foldr implementation needs to traverse the whole 
string before it can return the first character. If you want proper 
list-fusion (instead of just laziness), you could also use the `build` 
function to abstract over (:) and [].


--
Live well,
~wren

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Weekly News: Issue 199

2011-09-14 Thread Daniel Santa Cruz
   Welcome to issue 199 of the HWN, a newsletter covering developments in
   the Haskell community. This release covers the week of September 4 to
   10, 2011.

Announcements

   Johannes Waldmann open the invitation to the 6th Haskell in Leipzig
   workshop, on October 7, 2011. It will present an absolutely thrilling
   mixture of tutorials and talks, with special enphasis on parallel
   programming.
   [1] http://goo.gl/u0PwF

New and Updated Projects

   * Hs2lib (Phyx; v-0.5.5) A preprocesor and library which allow you
 to create dynamic libs from arbitrary annotated Haskell programs
 with one click. It also allows you to use the generated lib in C,
 C++, and C# just by including the generated header files.
 [2] http://goo.gl/xCSXc

   * Netwire (Ertugrul Soeylemez; 1.2.0) Lots of new features!
 [3] http://goo.gl/VCwb1

   * network-address (Sebastian Nowicki; 0.2.0) Provides data
 structures and textual representation of network addresses (IPv4,
 IPv6, subnets).
 [4] http://goo.gl/DBRI6

   * Webrexp (Vincent Berthoux; 1.1) A web scraping command line
 utility.
 [5] http://goo.gl/OlovQ

   * eddie (Mike Meyer; 0.5) Is a tool for applying haskell filters
 to text files via the unix command line.
 [6] http://goo.gl/NPc0b

   * cabal-ghci (Etienne Laurin; 0.1) Package to ease the development
 of projects using cabal.
 [7] http://goo.gl/fiDKZ

Quotes of the Week

   * gosu: Type parameters are covariant. This is not sound, and that
 does not matter.
   * turtlesalltheway: if haskell is so great why cant it improve itself
   * mm_freak: bosses are generally quite strong, static and lazy
   * cmccann: newtype Natural = N { denature :: Integer }

Top Reddit Stories

   * Constraint Kinds for GHC
 Domain: blog.omega-prime.co.uk, Score: 115, Comments: 12
 On Reddit: [8] http://goo.gl/bCXgf
 Original: [9] http://goo.gl/7aWzn

   * Yesod :: The Limitations of Haskell
 Domain: yesodweb.com, Score: 108, Comments: 42
 On Reddit: [10] http://goo.gl/5q7wW
 Original: [11] http://goo.gl/gisIh

   * Frege: haskell like language on JVM
 (tries to adhere to haskell 2010 where possible)
 Domain: code.google.com, Score: 58, Comments: 58
 On Reddit: [12] http://goo.gl/6KWEg
 Original: [13] http://goo.gl/56AkX

   * Sharing in Haskell – How the let and lambda constructs give
 a precise way to control sharing
 Domain: neilmitchell.blogspot.com, Score: 34, Comments: 18
 On Reddit: [14] http://goo.gl/Uf1vq
 Original: [15] http://goo.gl/4Hmfu

   * Let's play a game : How to implement functions from their type
 signatures
 Domain: blog.ezyang.com, Score: 24, Comments: 13
 On Reddit: [16] http://goo.gl/T2FiD
 Original: [17] http://goo.gl/SmbYO

   * Impredicativity + injectivity + type case analysis = inconsistency
 (Russell paradox) :: Oleg
 Domain: okmij.org, Score: 23, Comments: 10
 On Reddit: [18] http://goo.gl/zoThI
 Original: [19] http://goo.gl/jFr5U

   * Functional Pearls
 Domain: haskell.org, Score: 23, Comments: 1
 On Reddit: [20] http://goo.gl/RVyng
 Original: [21] http://goo.gl/1A7t0

   * An EventSource broker written in Haskell
 Domain: mathias-biilmann.net, Score: 22, Comments: 0
 On Reddit: [22] http://goo.gl/7yywu
 Original: [23] http://goo.gl/Y5mGj

   * Haskell For Kids: Week 4
 Domain: cdsmith.wordpress.com, Score: 22, Comments: 2
 On Reddit: [24] http://goo.gl/KwlqD
 Original: [25] http://goo.gl/xlNh2

   * apfelmus - Vault - a persistent store for values of arbitrary types
 Domain: apfelmus.nfshost.com, Score: 19, Comments: 2
 On Reddit: [26] http://goo.gl/VAE4n
 Original: [27] http://goo.gl/vvQ7A

   * Tau is available in Haskell, you can safely avoid Pi
 Domain: hackage.haskell.org, Score: 19, Comments: 26
 On Reddit: [28] http://goo.gl/u5GN8
 Original: [29] http://goo.gl/VnrMh

   * Zipper from any Traversable :: Oleg
 Domain: okmij.org, Score: 18, Comments: 2
 On Reddit: [30] http://goo.gl/xi4ZF
 Original: [31] http://goo.gl/nqZ3T

Top StackOverflow Questions

   * More on generic Scala functions
 votes: 20, answers: 4
 Read on SO: [32] http://goo.gl/DGH14

   * Why is a “type class” called “type class”?
 votes: 20, answers: 2
 Read on SO: [33] http://goo.gl/YbVXX

   * Is there a Haskell idiom for updating a nested data structure?
 votes: 14, answers: 2
 Read on SO: [34] http://goo.gl/jKEjv

   * How to tell if a list is infinite?
 votes: 14, answers: 4
 Read on SO: [35] http://goo.gl/fc3e6

   * Select random element from a set, faster than linear time (Haskell)
 votes: 9, answers: 5
 Read on SO: [36] http://goo.gl/IRJf3

   * GHC not optimising modules other than the main module
 votes: 9, answers: 0
 Read on SO: [37] http://goo.gl/8Ephm

   * A chess board representation in Haskell
 votes: 8, answers: 4
 Read on SO: [38] 

Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Richard O'Keefe

On 14/09/2011, at 2:45 PM, Casey McCann wrote:

 
class Tuple t where
type Arg t :: *
type Result t :: *
tuple :: t - Arg t - Result t
 
instance (x1 ~ x2) = Tuple (x1 - a, x2 - b) where
type Arg (x1 - a, x2 - b) = x1
type Result (x1 - a, x2 - b) = (a, b)
tuple (f, g) x = (f x, g x)

That's it, that's what I was after.  Thanks.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe