[Haskell-cafe] ANNOUNCE xml-conduit-generic

2013-03-12 Thread Dmitry Olshansky
Hello, cafe!

I made a package
xml-conduit-generichttps://github.com/odr/xml-conduit-generic to
provide conversion from ADT to xml and vice versa.
Conversion works as Conduit (ToXml) or Consumer (FromXml).

Example:

data T4 = T4 {v4 :: Int, n4 :: Maybe T4} deriving (Eq, Show, Generic)
instance ToXml T4
instance FromXml T4

 runToXml $ T4 5 $ Just $ T4 6 Nothing
T4 v4=\5\n4 v4=\6\//T4

 runFromXml $ T4 v4=\5\n4 v4=\6\//T4 :: IO (Either String T4)
Right $ T4 5 $ Just $ T4 6 Nothing

It would be great if someone look to the version on github and give me some
notes. Then I am going to put it on hackage.

Unfortunately, I didn't find a way to avoid OverlappingInstances (for
GFromXml class). Any ideas are welcome.

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


Re: [Haskell-cafe] Parser left recursion

2013-02-20 Thread Dmitry Olshansky
Did you see expression parser in parsec
packagehttp://hackage.haskell.org/packages/archive/parsec/3.1.3/doc/html/Text-Parsec-Expr.html?
Is it not enough?


2013/2/20 Martin Drautzburg martin.drautzb...@web.de

 Hello all,

 this was previously asked on haskell-beginners, but only partially
 answered.

 As an exercise I am writing a parser roughly following the expamples in
 Graham
 Hutton's book. The language contains things like:

 data Exp = Lit Int -- literal integer
  | Plus Exp Exp

 My naive parser enters an infinite recursion, when I try to parse 1+2. I
 do
 understand why:

 hmm, this expression could be a plus, but then it must start with an
 expression, lets check.

 and it tries to parse expression again and again considers Plus.

 Twan van Laarhoven told me that:

  Left-recursion is always a problem for recursive-descend parsers.

 and suggested to do something like:

  parseExp = do
lit - parseLit
pluses - many (parsePlusToken * parseLit)
return (combinePlusesWithLit lit pluses)
 
  combinePlusesWithLit = foldr Plus -- or foldl

 This indeed does the trick, but only when the first token is a Lit (literal
 integer).

 I then added the possibility to optionally put things in parentheses. But
 then
 I cannot parse (1+2)+3. The original code fails, because (1+2) is not a
 Lit and when I allow an expression as the first argument to + I get
 infinite
 recursion again.

 I am generally confused, that saying a plus expression is an integer
 followed
 by many plus somethings is not what the language says. So this requires a
 lot of paying attention to get right. I'd much rather say a plus
 expression
 is two expressions with a '+' in between.

 I do know for sure, that it is possible to parse (1+2)+3 (ghci does it
 just
 fine). But I seem to be missing a trick.

 Can anyone shed some light on this?

 --
 Martin

 ___
 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] I killed performance of my code with Eval and Strategies

2012-11-16 Thread Dmitry Olshansky
Just another definition of calculateSeq:

calculateSeq = zipWith ($) (cycle [sin,cos]) . map sqrt


2012/11/15 Janek S. fremenz...@poczta.onet.pl

  Do you really mean to calculate the 'sin . sqrt' of just the head of the
 list, or do you mean:
  calculateSeq = map (sin . sqrt)   ?
 Argh.. of course not! That's what you get when you code in the middle of a
 night. But in my code I
 will not be able to use map because elements will be processed in pairs,
 so let's say that my
 sequential function looks like this:

 calculateSeq :: [Double] - [Double]
 calculateSeq [] = []
 calculateSeq [x] = [sin . sqrt $ x]
 calculateSeq (x:y:xs) = (sin . sqrt $ x) : (cos . sqrt $ y) : calculateSeq
 xs

  I don't think there's a memory leak. It looks more like you're just
  allocating much more than is sane for such a simple function.
  On a recent processor, sin . sqrt is two instructions. Meanwhile, you
 have
  a list of (boxed?) integers being split up, then recombined. That's bound
  to hurt the GC.
 I am not entirely convinced that my idea of using eval+strategies is bound
 to be slow, because
 there are functions like parListChunk that do exactly this: split the list
 into chunks, process
 them in parallel and then concatenate the result. Functions in
 Control.Parallel.Strategies were
 designed to deal with list so I assume it is possible to process lists in
 parallel without GC
 problems. However I do not see a way to apply these functions in my
 setting where elements of
 lists are processed in pairs, not one at a time (parList and parMap will
 not do). Also, working
 on a list of tuples will not do.

  Also, you might want to configure criterion to GC between
  runs. That might help.
 The -g flag passed to criterion executable does that.

  What I'd suggest doing instead, is breaking the input into chucks of,
 say,
  1024, and representing it with a [Vector]. Then, run your sin.sqrt's on
  each vector in parallel. Finally, use Data.Vector.concat to combine your
  result.
 As stated in my post scriptum I am aware of that solution :) Here I'm
 trying to figure what am I
 doing wrong with Eval.

 Thanks!
 Janek

 
  Hope that helps,
- Clark
 
  On Wed, Nov 14, 2012 at 4:43 PM, Janek S. fremenz...@poczta.onet.pl
 wrote:
   Dear Haskellers,
  
   I am reading Simon Marlow's tutorial on parallelism and I have problems
   with correctly using Eval
   monad and Strategies. I *thought* I understand them but after writing
   some code it turns out that
   obviously I don't because parallelized code is about 20 times slower.
   Here's a short example
   (code + criterion benchmarks):
  
   {-# LANGUAGE BangPatterns #-}
   module Main where
  
   import Control.Parallel.Strategies
   import Criterion.Main
  
   main :: IO ()
   main = defaultMain [
   bench Seq $ nf calculateSeq xs
 , bench Par $ nf calculatePar xs ]
   where xs = [1..16384]
  
   calculateSeq :: [Double] - [Double]
   calculateSeq [] = []
   calculateSeq (x:xs) = (sin . sqrt $ x) : xs
  
   calculatePar :: [Double] - [Double]
   calculatePar xss = runEval $ go xss
   where
 go :: Strategy [Double]
 go [] = return []
 go xs = do
 lsh - (rpar `dot` rdeepseq) $ calculateSeq as
 lst - go bs
 return (lsh ++ lst)
 where
   !(as, bs) = splitAt 8192 xs
  
   Compiling and running with:
  
   ghc -O2 -Wall -threaded -rtsopts -fforce-recomp -eventlog evalleak.hs
   ./evalleak -oreport.html -g +RTS -N2 -ls -s
  
   I get:
  
   benchmarking Seq
   mean: 100.5990 us, lb 100.1937 us, ub 101.1521 us, ci 0.950
   std dev: 2.395003 us, lb 1.860923 us, ub 3.169562 us, ci 0.950
  
   benchmarking Par
   mean: 2.233127 ms, lb 2.169669 ms, ub 2.296155 ms, ci 0.950
   std dev: 323.5201 us, lb 310.2844 us, ub 344.8252 us, ci 0.950
  
   That's a hopeless result. Looking at the spark allocation everything
   looks fine:
  
   SPARKS: 202 (202 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
  
   But analyzing eventlog with ThreadScope I see that parallel function
   spends most of the time doing
   garbage collection, which suggests that I have a memory leak
 somewhere. I
   suspected that problem
   might be caused by appending two lists together in the parallel
   implementation, but replacing
   this with difference lists doesn't help. Changing granularity (e.g.
   splitAt 512) also brings no
   improvement. Can anyone point me to what am I doing wrong?
  
   Janek
  
   PS. This is of course not a real world code - I know that I'd be better
   of using unboxed data
   structures for doing computations on Doubles.
  
   ___
   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] Maximum bipartite matching: 24 lines

2012-10-29 Thread Dmitry Olshansky
I didn't analyze it but anytime I see M.insertWith I am just in doubt -
do you know about a strict version M.insertWith' ?

2012/10/24 Stefan Klinger all-li...@stefan-klinger.de

 On 2012-Oct-22 14:23 (-0700), Eugene Kirpichov wrote with possible
 deletions:
 
  fwd = foldr (\(x,y) - M.insertWith (++) x [y]) M.empty $ S.toList g
 
  Use foldl' here, foldr is absolutely useless here and it only consumes
  the stack space as your operation is strict.

 Thank you very much for that.  I'll review the code under strictness
 aspects.

  As for the actual code: I'd prefer the code itself to be more
  readable, rather than have a lot of literate comments around it;

 I like comments documenting why something's done, complementing the code
 which tells what's done.

  currently, IMO all the uncurry's, flips, eithers, maybes and
  point-free style hurt readability heavily.

 I agree.  Between babbling bloated and incomprehensible terse, my code
 is certainly towards the terse extreme.  For me, that's a balancing act
 that I find hard to do right.

  I'll probably try to write my own version as an exercise :)

 Cool!  I'd like to see that...

 Cheers!
 Stefan


 --
 Stefan Klinger  o/klettern
 /\/  bis zum
 send plaintext only - max size 32kB - no spam \   Abfallen
 http://stefan-klinger.de

 ___
 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] Data.Text and quasi quoting

2012-10-02 Thread Dmitry Olshansky
Hello,

if you change from
 test2 = [expr| test |]
to
 test2 = [expr| $test |]
then it will be compile.

Do you want that or what?





2012/10/2 Jake Wheat jakewheatm...@gmail.com

 Hello,

 I have a parser which parses to an ast which contains Text values. I
 am trying to use this parser with quasiquoting, but the implementation
 of Data for Text is incomplete. I've attached a smallish test case,
 when I try to compile Text.hs I get:

 Text.hs:17:9:
 Exception when trying to run compile-time code:
   Data.Text.Text.toConstr
   Code: Language.Haskell.TH.Quote.quoteExp expr  test 

 Is there a way to get this working?

 Thanks,
 Jake.

 ___
 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] not enough fusion?

2012-06-25 Thread Dmitry Olshansky
s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]

There are some posts from Joachim Breitner investigated fusion for
concatMap:
http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227



2012/6/25 Johannes Waldmann waldm...@imn.htwk-leipzig.de

 Dear all,

 while doing some benchmarking (*)
 I noticed that function  s1  is considerably faster than  s2
 (but I wanted  s2  because it looks more natural)
 (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)

 s1 :: Int - Int
 s1 n = sum $ do
x - [ 0 .. n-1 ]
return $ sum $ do
y - [ 0 .. n-1 ]
return $ gcd x y

 s2 :: Int - Int
 s2 n = sum $ do
  x - [ 0 .. n-1 ]
  y - [ 0 .. n-1 ]
  return $ gcd x y

 I was expecting that in both programs,
 all lists will be fused away (are they?)
 so the code generator essentially can produce straightforward
 assembly code (no allocations, no closures, etc.)


 For reference, I also wrote the equivalent imperative program
 (two nested loops, one accumulator for the sum)
 (with the straightforward recursive gcd)
 and runtimes are (for same input as above)

 C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s


 So, they sort of agree with each other, but disagree with ghc.
 Where does the factor 2 come from? Lists? Laziness?
 Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
 (I am looking at  -ddump-asm  but can't quite see through it.)


 (*) benchmarking to show that today's compilers are clever enough
 such that the choice of paradigm/language does not really matter
 for this kind of low-level programming.






 ___
 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] not enough fusion?

2012-06-25 Thread Dmitry Olshansky
In my test it works ~20% faster than s2 and ~20% slower than s1.
Did you use -O2 flag?

2012/6/25 Lorenzo Bolla lbo...@gmail.com

 I wonder why this performs really badly, though (I would expect it to be
 the same as s2):

 s3 :: Int - Int
 s3 n = sum [gcd x y | x - [ 0 .. n-1 ], y - [ 0 .. n-1 ]]

 From the links posted by Dmitry, it might be that the code generated is
 made of 2 recursive calls: in fact, what I observe is a stack space
 overflow error on runtime...

 L.




 On Mon, Jun 25, 2012 at 10:09 AM, Dmitry Olshansky 
 olshansk...@gmail.comwrote:

 s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
 s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]

 There are some posts from Joachim Breitner investigated fusion for
 concatMap:

 http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227



 2012/6/25 Johannes Waldmann waldm...@imn.htwk-leipzig.de

 Dear all,

 while doing some benchmarking (*)
 I noticed that function  s1  is considerably faster than  s2
 (but I wanted  s2  because it looks more natural)
 (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)

 s1 :: Int - Int
 s1 n = sum $ do
x - [ 0 .. n-1 ]
return $ sum $ do
y - [ 0 .. n-1 ]
return $ gcd x y

 s2 :: Int - Int
 s2 n = sum $ do
  x - [ 0 .. n-1 ]
  y - [ 0 .. n-1 ]
  return $ gcd x y

 I was expecting that in both programs,
 all lists will be fused away (are they?)
 so the code generator essentially can produce straightforward
 assembly code (no allocations, no closures, etc.)


 For reference, I also wrote the equivalent imperative program
 (two nested loops, one accumulator for the sum)
 (with the straightforward recursive gcd)
 and runtimes are (for same input as above)

 C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s


 So, they sort of agree with each other, but disagree with ghc.
 Where does the factor 2 come from? Lists? Laziness?
 Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
 (I am looking at  -ddump-asm  but can't quite see through it.)


 (*) benchmarking to show that today's compilers are clever enough
 such that the choice of paradigm/language does not really matter
 for this kind of low-level programming.






 ___
 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] Guide for converting existing code to Conduit 0.4?

2012-04-09 Thread Dmitry Olshansky
I transfered my code from 0.3 to 0.4 without any changes. There are type
synonyms in Conduit for that.

Changes were from 0.2 to 0.3. Michael discribed it here
http://www.yesodweb.com/blog/2012/03/announcing-conduit-0-3

Actually, in 0.4

no changes with Control.Monad.Trans.Resource.
type Source m a = Pipe Void a m ()
old Conduit-API use type synonyms and not changed




2012/4/9 Erik de Castro Lopo mle...@mega-nerd.com

 Hi all,

 Is there some sort of a guide for converting existing code Conduit 0.4?

 What happened to Control.Monad.Trans.Resource.with?

 What happens to stuff that used to to have a type C.Source m a which
 now seems to need type C.Pipe Void a (ResourceT m) a?

 Cheers,
 Erik
 --
 --
 Erik de Castro Lopo
 http://www.mega-nerd.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] is the evaluation order deterministic when using applicative with IO

2012-03-16 Thread Dmitry Olshansky
As usual you can check:

Prelude Control.Applicative pure (||) * pure True * undefined
*** Exception: Prelude.undefined

Prelude Control.Applicative (||) True undefined
True



2012/3/16 Rouan van Dalen rvda...@yahoo.co.uk

 Hi everyone.

 I was wondering if I can make assumptions about the evaluation order of
 the following code:

 isTrue :: Int - IO Bool
 isTrue val = pure (||) * boolTest1 val * boolTest2 val


 {- boolTest1 is an inexpensive, quick check -}
 boolTest1 :: Int - IO Bool
 boolTest1 val = undefined


 {- boolTest2 is a very expensive check -}
 boolTest2 :: Int - IO Bool
 boolTest2 val = undefined


 When using Applicative in the isTrue function, I would like to make use of
 the short-circuit behaviour of || and rely on the fact that the boolTest1
 will be executed first.  The reason I am asking is because the boolTest
 functions
 are in the IO monad, instead of just returning pure Bool values.

 Regards
 Rouan.


 ___
 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] Empty Input list

2012-03-13 Thread Dmitry Olshansky
Look also at safe package http://hackage.haskell.org/package/safe

2012/3/13 Chris Wong chrisyco+haskell-c...@gmail.com

 On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith cdsm...@gmail.com wrote:
  On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees k.cl...@web.de wrote:
  Now my function looks like this:
 
  tmp:: [(Int, Int)] - Int - (Int, Int)
  tmp [] y = (0,0)
  tmp xs y = xs !! (y-1)
 
  Just a warning that this will still crash if the list is non-empty by
  the index exceeds the length.  That's because your function is no
  longer recursive, so you only catch the case where the top-level list
  is empty.  The drop function doesn't crash when dropping too many
  elements though, so you can do this and get a non-recursive function
  that's still total:
 
  tmp :: [(Int,Int)] - Int - (Int, Int)
  tmp xs y = case drop (y-1) xs of
 [] - (0,0)
 Just (x:_) - x

 That last line should be

(x:_) - x

 without the Just. Hopefully that'll save a bit of confusion.

 Chris

  --
  Chris Smith
 
  ___
  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] need help with monad transformers

2012-03-01 Thread Dmitry Olshansky
 If I'm running register outside runWriterT everything will work.

Maybe just

 lift $ register $ print freed2

or I didn't catch something?



2012/3/1 Alexander V Vershilov alexander.vershi...@gmail.com

 Hello.

 I'm trying to add monad stack into network-conduit, and everything
 works except some details [1].

 I've run runReaderT $ runTCPServer (wrapper around runResourceT) and
 inside conduit I want to run writer to gather results of inner computation.
 In inner computation I want to use IO, data from outter stack (ReaderT)
 so I'm running {-1-}:

  (k,t) - lift $ runWriterT $ ask = \x - tell [x] {- 1 -}

 and {-2-}

  (k,t) - lift $ runWriterT $ do {- 2 -}
x - ask
liftIO $ print $x+1
tell [x]

 and that will work (except I've thought I should not lift runWriterT, but
 calling functions inside.

 And finally in computation that will run once I want to register cleaning
 function (for example register $ putStrLn cleaned) ({-3-})

  (k,t) - lift $ runWriterT $ do {- 3 -}
x - ask
liftIO $ print $x+1
register $ print freed2
tell [x]

 but I've got type error. If I'm running register outside runWriterT
 everything
 will work.

 I would apperated if there will be any suggestions how to make this code
 better or use register in internal computation (runWriterT)

 [1] https://gist.github.com/1941151
 --
 Best regards,
  Alexander V Vershilov

 ___
 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] need help with monad transformers

2012-03-01 Thread Dmitry Olshansky
Did you try to use transformers instead of mtl? I am just in doubt about it
in my work.

I've found that Conduit use it. So you remove extra dependency.
I hope that transformers have more readable messages (without FD) and you
can control what is lift more clear.

I have no experience although.



2012/3/2 Alexander V Vershilov alexander.vershi...@gmail.com

 I've found a solution, I should not use lift for runWriterT, and should
 explicilty lift all computation of level I need, i.e. (lift.lift) for ask
 and lift for register.

 Thu, Mar 01, 2012 at 02:19:29PM +0400, Dmitry Olshansky wrote
   If I'm running register outside runWriterT everything will work.
 
  Maybe just
 
   lift $ register $ print freed2
 
  or I didn't catch something?
 
 
 
  2012/3/1 Alexander V Vershilov alexander.vershi...@gmail.com
 
  Hello.
 
  I'm trying to add monad stack into network-conduit, and everything
  works except some details [1].
 
  I've run runReaderT $ runTCPServer (wrapper around runResourceT) and
  inside conduit I want to run writer to gather results of inner
 computation.
  In inner computation I want to use IO, data from outter stack
 (ReaderT)
  so I'm running {-1-}:
 
   (k,t) - lift $ runWriterT $ ask = \x - tell [x] {- 1 -}
 
  and {-2-}
 
   (k,t) - lift $ runWriterT $ do {- 2 -}
 x - ask
 liftIO $ print $x+1
 tell [x]
 
  and that will work (except I've thought I should not lift
 runWriterT, but
  calling functions inside.
 
  And finally in computation that will run once I want to register
 cleaning
  function (for example register $ putStrLn cleaned) ({-3-})
 
   (k,t) - lift $ runWriterT $ do {- 3 -}
 x - ask
 liftIO $ print $x+1
 register $ print freed2
 tell [x]
 
  but I've got type error. If I'm running register outside runWriterT
  everything
  will work.
 
  I would apperated if there will be any suggestions how to make this
 code
  better or use register in internal computation (runWriterT)
 
  [1] https://gist.github.com/1941151
  --
  Best regards,
   Alexander V Vershilov
 
  ___
  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


[Haskell-cafe] Fwd: XML modification

2011-11-23 Thread Dmitry Olshansky
Personally I prefer xml-enumerator. You can work with xml-stream or with
DOM through cursor (like XPath).

I think that in your case working with stream is preferrable.

You can just make an Enumeratee like

import qualified Data.Enumerator.List as EL

 myEnum = EL.map f
where
   f (EventBeginElement n ats) = ... -- parse attributes
   f e = e



2011/11/23 Andrew Coppin andrewcop...@btinternet.com

 Hi guys.

 I've got a folder with about 80 XML files in it. I want to take each file
 and make specific modifications to it. (Mostly just finding specific
 attributes and changing their values to make then all consistent.)

 Now I guess it wouldn't take me /that/ long to code something from
 scratch. But does anybody have a better suggestion for tools or libraries
 that might be useful?

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] Is it possible to get the information of instances of a type?

2011-11-07 Thread Dmitry Olshansky
For TH look also at
http://www.mail-archive.com/haskell-cafe@haskell.org/msg13057.html


2011/10/27 Magicloud Magiclouds magicloud.magiclo...@gmail.com

 On Thu, Oct 27, 2011 at 1:57 AM, Brent Yorgey byor...@seas.upenn.edu
 wrote:
  On Wed, Oct 26, 2011 at 09:10:23PM +0400, MigMit wrote:
  Can't be done. Even if this particular module doesn't contain
  instance Class Type, it's quite possible that the said instance
  would be defined in another module, about which this one knows
  nothing about.
 
  That doesn't mean it can't be done, only that you would have to be
  explicit about which modules to look in.
 
  -Brent
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 

 May I know more about this? Have not used TH on this subject.

 --
 竹密岂妨流水过
 山高哪阻野云飞

 ___
 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] Enumerators, Enumeratees and Iterators

2011-06-28 Thread Dmitry Olshansky
Hi,

for the first question you can look at combinators in
Data.Iteratee.ListLikehttp://hackage.haskell.org/packages/archive/iteratee/0.8.5.0/doc/html/Data-Iteratee-ListLike.html
for iteratee package or
Data.Enumerator.Listhttp://hackage.haskell.org/packages/archive/enumerator/0.4.10/doc/html/Data-Enumerator-List.html
for
enumerator package.

I doubt that I understand the second question. It seems that Map is more
natural here. You can transform list into enumerator for instance by
enumListhttp://hackage.haskell.org/packages/archive/enumerator/0.4.10/doc/html/Data-Enumerator.html#g:7.
But I wonder what is the reason for that in your case?


2011/6/28 Sævar Berg s.b.saevars...@gmail.com

 Hey Café.

 I've been playing with Enumerators, Iteratees and Enumeratees today after
 having spent a few days writing a server application using lazy IO, then
 reading slides from Oleg's DEFUN8 talk notes, and I quote: Lazy IO in
 serious, server-side programming is unprofessional, I can talk a lot how
 disturbingly, distressingly wrong lazy IO is theoretically, how it breaks
 all equational reasoning after which my OCD self has been eating me up to
 take a proper look at this, so here I am.

 I'm already beginning to see how Iteratees, Enumerators and Enumeratees can
 be nifty, but I have a couple of questions about a couple of ideas and
 whether, and if so how they can be implemented.

 The first question is, I think, to be solved with enumeratees but I can't
 really grok how.
 Let's say I have an iteratee that consumes all input. Is it possible to
 implement an enumeratee or something else to stick between the enumerator
 and the iteratee to basically modify the input to the iteratee to only be a
 part of the input?

 Something like this:

 enumFile someFile  printFileLines -- prints file with prepended line
 numbers
 enumFile someFile ?? onlyGet10Lines  printFileLines -- print only 10
 lines

 The second question could actually have an application in the server I'm
 writing. I was wondering if it was possible to write iteratees/enumerators
 that would only generate/consume when a certain something was the next chunk
 to be processed? It's a bit hard to explain, but let me try to give you an
 example.

 Let's say my application takes input from the network which contains
 commands that the server reacts to. Let's say I have a list of command
 handlers that I want to run this command through, but the handlers will only
 execute when they are passed the command that they are responsible for
 handling.
 Can this list of command handlers be enumerators/iteratees/enumeratees?
 E.g. is it possible to 'concat' them, making them each peek at the next
 chunk to see if it's theirs to handle and put it back if it isn't?

 I know this is possible to do differently and I have an idea for how I
 would do this, but I'm wondering if this is possible. If I can get answers
 to either or both of the questions it would help me a bit on my way to
 completely realize the roles that enumerators vs. iteratees vs. enumeratees
 have, as the lines seem a bit blurred -- sometimes, anyway.

 Thanks in advance. :)

 ___
 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] Enumerators, Enumeratees and Iterators

2011-06-28 Thread Dmitry Olshansky
If I've understood it correctly, concurrent is similar to functions
discussed here:
http://www.haskell.org/pipermail/haskell-cafe/2011-April/091474.html
and here
http://www.haskell.org/pipermail/haskell-cafe/2011-January/088319.html



2011/6/28 Ertugrul Soeylemez e...@ertes.de

 Sævar Berg s.b.saevars...@gmail.com wrote:

  The first question is, I think, to be solved with enumeratees but I can't
  really grok how.
  Let's say I have an iteratee that consumes all input. Is it possible to
  implement an enumeratee or something else to stick between the enumerator
  and the iteratee to basically modify the input to the iteratee to only be
 a
  part of the input?

 Yes, this is an enumeratee.  An enumeratee is neither a data producder
 nor a consumer.  It is an iteratee, which feeds another iteratee with
 input based on its own input, so it acts like a kind of map operation.


  enumFile someFile  printFileLines -- prints file with prepended line
  numbers
  enumFile someFile ?? onlyGet10Lines  printFileLines -- print only 10
  lines

 In fact an enumeratee can split the input stream into lines.  Another
 one can zip the stream with a list.  A final one can take 10 lines from
 the stream.  The code would look like this (in the 'enumerator'
 package):

enumFile myFile.txt $$
lines =$
zipWithList [1..] =$
take 10 =$
printLines

 where

lines   :: Monad m = Enumeratee Text Text m b
zipWithList :: Monad m = [a'] - Enumeratee a (a, a') m b
take:: Monad m = Int - Enumeratee a a m b
printLines  :: MonadIO m = Iteratee (Int, Text) m ()

 This is how I would do it.


  The second question could actually have an application in the server
  I'm writing. I was wondering if it was possible to write
  iteratees/enumerators that would only generate/consume when a certain
  something was the next chunk to be processed?

 You want concurrent iteratees here.  As far as I know in the
 'enumerator' package there is no builtin way to do it (you may be
 luckier in the 'iteratee' package, but I don't know).  However, I think
 it should be possible to write a 'concurrent' function, if the iteratees
 in question all have the same input type:

concurrent :: Monad m = [Step a m b] - Iteratee a m [b]

 A version, which doesn't collect the results is probably much easier to
 write:

concurrent_ :: Monad m = [Step a m b] - Iteratee a m ()


 Greets,
 Ertugrul


 --
 nightmare = unsafePerformIO (getWrongWife = sex)
 http://ertes.de/



 ___
 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] GHC 7.0.3 / Win32: Data.Time library?

2011-06-14 Thread Dmitry Olshansky
Could you look at
http://hackage.haskell.org/packages/archive/time/1.2.0.5/doc/html/Data-Time-Format.html
?
Is it enough?



2011/6/14 Dmitri O.Kondratiev doko...@gmail.com

 Sorry for typo - I need subtract dates (no 'abstracting') :


 On Tue, Jun 14, 2011 at 3:49 PM, Dmitri O.Kondratiev doko...@gmail.comwrote:

 It looks like GHC, 7.0.3 Haskell Hierarchical Libraries documentation
 generated for Win32, that goes with Haskell Platform installation package,
 does not have a section on Data.Time module.
 How  can that be?

 I need to convert a string of the form ,10/11/2009 7:04:28 PM to Haskell
 type that can be used for comparing and abstracting dates.
 What is the simplest way to day that?

 Thanks!





 ___
 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] Oracle Sessions in Takusen

2011-06-01 Thread Dmitry Olshansky
Hello,

Could anyone explain strange behavior of Takusen with OracleDB (OraClient
11.x)? Several sequential sessions give Seqmentation Fault error. In case
of nested sessions it works well.

{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Database.Oracle.Enumerator
import Control.Monad(replicateM)
import Control.Monad.Trans(liftIO)
main = do
{-
-- This gives an Segmentation Fault for the second session

replicateM 2 (do
res - withSession (connect x x x)  (do
doQuery (sql SELECT dummy FROM dual) (\(d::String)
(_::Maybe String) - result' $ Just d) Nothing
)
print res
)
-}

-- This is works well

withSession (connect x x x)  (do
r1 - doQuery (sql SELECT dummy FROM dual) (\(d::String)
(_::Maybe String) - result' $ Just d) Nothing
liftIO $ print r1
liftIO $ withSession (connect x x x)  (do
r2 - doQuery (sql SELECT dummy FROM dual)
(\(d::String) (_::Maybe String) - result' $ Just d) Nothing
liftIO $ print r2
)
)
Best regards,
Dmitry
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Iteratee: manyToOne

2011-04-29 Thread Dmitry Olshansky
Thank you!
Working implementation is even more than I've expected.



2011/4/28 Felipe Almeida Lessa felipe.le...@gmail.com

 On Thu, Apr 28, 2011 at 1:10 PM, Felipe Almeida Lessa
 felipe.le...@gmail.com wrote:
  On Thu, Apr 28, 2011 at 12:09 PM, Felipe Almeida Lessa
  felipe.le...@gmail.com wrote:
  I foresee one problem: what is the leftover of 'manyToOne xs' if each
  x in xs needs different lengths of input?
 
  One possible untested-but-compiling solution:
  [snip]
 
  Like I said, that manyToOne implementation isn't very predictable
  about leftovers.  But I guess that if all your iteratees consume the
  same input OR if you don't care about leftovers, then it should be
  okay.

 Sorry for replying to myself again. =)

 I think you can actually give predictable semantics to manyToOne:
 namely, the leftovers from the last iteratee are returned.  This new
 implementation should be better:

 import Data.Monoid (mappend)
 import qualified Data.Enumerator as E

 manyToOne :: Monad m = [E.Iteratee a m b] - E.Iteratee a m [b]
 manyToOne is = E.Iteratee $ mapM E.runIteratee is =
E.runIteratee . go
where
  go [step]  = fmap (:[]) (E.returnI step)
  go (E.Yield b _  : xs) = fmap (b:)  (go xs)
  go (E.Error exc  : _)  = E.returnI (E.Error exc)
  go (E.Continue f : xs) = E.continue $ go' (E.Continue f : xs)
  go []  = return []

  go' xs stream = manyToOne $ feed xs
where
  feed [E.Yield b s]   = [E.yield b (s `mappend` stream)]
  feed (E.Continue f : ys) = f stream   : feed ys
  feed (step : ys) = E.returnI step : feed ys
  feed []  = []

 With the same test as before:

 *Main E.run $ E.enumList 1 [5 :: Int, 6, 7] E.$$ manyToOne [return 1,
 maybe 2 id `fmap` E.head, return 3, maybe 4 id `fmap` (E.head 
 E.head)] = \xs - (,) xs `fmap` E.head
 Right ([1,5,3,6],Just 7)
 *Main E.run $ E.enumList 10 [5 :: Int, 6, 7] E.$$ manyToOne [return
 1, maybe 2 id `fmap` E.head, return 3, maybe 4 id `fmap` (E.head 
 E.head)] = \xs - (,) xs `fmap` E.head
 Right ([1,5,3,6],Just 7)

 When the last iteratee doesn't consume anything:

 *Main E.run $ E.enumList 1 [5 :: Int, 6, 7] E.$$ manyToOne [return 1,
 maybe 2 id `fmap` E.head, return 3, maybe 4 id `fmap` (E.head 
 E.head), return 10] = \xs - (,) xs `fmap` E.head
 Right ([1,5,3,6,10],Just 5)
 *Main E.run $ E.enumList 10 [5 :: Int, 6, 7] E.$$ manyToOne [return
 1, maybe 2 id `fmap` E.head, return 3, maybe 4 id `fmap` (E.head 
 E.head), return 10] = \xs - (,) xs `fmap` E.head
 Right ([1,5,3,6,10],Just 5)

 HTH,

 --
 Felipe.

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


Re: [Haskell-cafe] Iteratee: manyToOne

2011-04-29 Thread Dmitry Olshansky
In my case leftover is not important.

But in common case... Just an idea...

What if we provide
iterWhile :: Iteratee a m () - Iteratee a m b - Iteratee a m b

The first Iteratee only control when the result should be yeilded and feed
an input to second Iteratee.

Then we can change manyToOne to
manyToOne' :: Iteratee a m () - [Iteratee a m b] - Iteratee a m [b]
manyToOne' iw = iterWhile iw . manyToOne







2011/4/29 Felipe Almeida Lessa felipe.le...@gmail.com

 On Fri, Apr 29, 2011 at 6:32 AM, John Lato jwl...@gmail.com wrote:
  If you do this, the user needs to take care to order the iteratees so
 that
  the last iteratee has small leftovers.  Consider:
 
  manyToOne [consumeALot, return ()]
 
  In this case, the entire stream consumed by the first iteratee will need
 to
  be retained and passed on by manyToOne.  In many cases, the user may not
  know how much each iteratee will consume, which can make these semantics
  problematic.
 
  Iteratee has 'enumPair', (renamed 'zip' in HEAD) which returns the
 leftovers
  from whichever iteratee consumes more.  This avoids the problem of
 retaining
  extra data, and seems simpler to reason about.  Although if you really
 need
  to consume a predictable amount of data, the safest is probably to run
 the
  whole thing in a 'take'.

 My motivation is: in general it is difficult (impossible?) to choose
 the iteratee that consumed more data because you don't know what the
 data is.  For example, if you give 'Chunks [a,b]' to two iteratees and
 one of them returns 'Chunks [c]' and the other one returns 'Chunks
 [d]', which one consumed more data?  The answer is that it depends on
 the types.  If they are Ints, both consumed the same, if they are
 ByteStrings, you would need to check if one is prefix of the other.
 What if one returns 'Chunks [c]' and the other one returns 'Chunks
 [d,e]'?  If they are ByteStrings, should we compare 'c' against 'd ++
 e'?

 So I thought it would be easier to program with an API that is
 predictable and immune to changes in block sizes.  If you don't want
 leftovers, just use 'manyToOne [..., dropWhile (const True)]', which
 guarantees that you won't leak.

 Cheers,

 --
 Felipe.

 ___
 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] Iteratee: manyToOne

2011-04-28 Thread Dmitry Olshansky
Hello,

does somewhere exist function with type like this - manyToOne :: [Iteratee a
m b] - Iteratee a m [b] ?

I.e. I need to process one input through many Iteratees indepentently in
constant space and collect results.

It is similar by type with sequenceM but as far as I understand sequenceM
won't use the same input for all Iteratees.

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


[Haskell-cafe] Fwd: using IO monad in Iteratee

2011-04-02 Thread Dmitry Olshansky
-- Forwarded message --
From: Dmitry Olshansky olshansk...@gmail.com
Date: 2011/4/2
Subject: Re: [Haskell-cafe] using IO monad in Iteratee
To: wren ng thornton w...@freegeek.org


Well, in my case I can use probably

withBinaryFile fn (\h- run $ enumHandle h ...)




2011/4/2 wren ng thornton w...@freegeek.org

 On 4/1/11 3:59 PM, Dmitry Olshansky wrote:

 But enumFile use IO monad instead of MonadIO class.
 [...]

 Is it possible to change enumFile to using MonadIO class?


 Unless its changed significantly since I looked at it last (which it may
 well have), it's not possible. The problem is that what we'd really need is
 lowerIO :: m a - IO a for the m in question; liftIO goes the wrong way. Of
 course, getting a lowerIO with the right semantics will be tricky for most
 monads.

 --
 Live well,
 ~wren

 ___
 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] using IO monad in Iteratee

2011-04-02 Thread Dmitry Olshansky
Very interesting, thanks.

I didn't feel your classes yet... Do you think that provide these instances
for Iteratee is possible?

2011/4/2 Bas van Dijk v.dijk@gmail.com

 On 1 April 2011 21:59, Dmitry Olshansky olshansk...@gmail.com wrote:
  Is it possible to change enumFile to using MonadIO class?

 No because it uses the control operation Control.Exception.finally ::
 IO a - IO b - IO a internally. You can't lift control operations
 with liftIO :: MonadIO m = IO a - m a.

 However if you are able to define a MonadTransControl and
 MonadControlIO instance (from the monad-control package[1]) for
 Iteratee and use Control.Exception.Control.finally instead of the
 regular finally, you can use your MyMonad with the modified enumFile.

 Good luck,

 Bas

 [1] http://hackage.haskell.org/package/monad-control

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


Re: [Haskell-cafe] using IO monad in Iteratee

2011-04-02 Thread Dmitry Olshansky
Ertugrul,

thanks for information. I've found several decisions for my real problem
(using enumHandle and some more special decision).
But I'll be have in mind about monad-control.



2011/4/3 Ertugrul Soeylemez e...@ertes.de

 Bas van Dijk v.dijk@gmail.com wrote:

  On 1 April 2011 21:59, Dmitry Olshansky olshansk...@gmail.com wrote:
   Is it possible to change enumFile to using MonadIO class?
 
  No because it uses the control operation Control.Exception.finally ::
  IO a - IO b - IO a internally. You can't lift control operations
  with liftIO :: MonadIO m = IO a - m a.
 
  However if you are able to define a MonadTransControl and
  MonadControlIO instance (from the monad-control package[1]) for
  Iteratee and use Control.Exception.Control.finally instead of the
  regular finally, you can use your MyMonad with the modified enumFile.

 I don't think that's possible, because Iteratee is based on CPS.  I
 think, so far nobody has come up with an instance definition for
 monad-peel or monad-control for CPS-based monads like ContT or Iteratee.

 However, it is easy to write an own handle enumerator, which uses
 monad-peel or monad-control exception handling to convert errors to
 iteratee exceptions.  On the other hand, as has been noted, there is
 enumHandle, which does that by itself.


 Greets,
 Ertugrul


 --
 nightmare = unsafePerformIO (getWrongWife = sex)
 http://ertes.de/



 ___
 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] using IO monad in Iteratee

2011-04-01 Thread Dmitry Olshansky
Dear collegues,

I use Iteratee with Monad Transformer stack in this way:

type MyMonad a b = Iteratee a (StateT StateType IO) b

I've wrote some Enumeratees using this type. Then I want to compose it with
standard enumerator like Data.Enumerator.Binary.enumFile.
But enumFile use IO monad instead of MonadIO class.

I didn't see (maybe I'm blind...) a way to compose my Enumeratees with
enumFile.

How I can do that?
Is it possible to change enumFile to using MonadIO class?

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


[Haskell-cafe] fetching BLOBs

2011-02-07 Thread Dmitry Olshansky
Hello, cafe,

Is there a way to get BLOB fields from OracleDB using Takusen?
What about other possibilities (through HDBC - ODBC)?

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


[Haskell-cafe] Takusen and QuickCheck

2011-01-26 Thread Dmitry Olshansky
Hello,

I have a problem with using Takusen in my current project because it uses
old QuickCheck 1.*. This leads to conflict with other packages which use
QuickCheck 2.*.
Could someone help me to decide this problem?

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


[Haskell-cafe] Bug with [Double]

2010-05-19 Thread Dmitry Olshansky
Hello all,

It seems that I saw something like this in Cafe recevtly. But I am not sure...
In GHC 6.12.1 (Platform 2010 on Windows Vista) I have

Prelude [1,1+2/3..10]
[1.0,1.6665,2.333,2.9996,3.666,4.332,4.998,5.664,6.33,6.9964,7.6625,8.329,8.995,9.66,10.327]

-- It is a bug!

Prelude [1,5/3..10]
[1.0,1.6667,2.3335,3.0,3.6665,4.333,5.0,5.667,6.334,7.001,7.668,8.336,9.004,9.671]

-- correct, but...

Prelude [1,5/3..4]
[1.0,1.6667,2.3335,3.0,3.6665,4.333]

-- ... wrong again

Prelude [1,1+2/3..10] :: [Float]
[1.0,1.667,2.335,3.002,3.67,4.34,5.01,5.68,6.35,7.02,7.69,8.36,9.03,9.7]

-- correct

Prelude [1,1+2/3..10] :: [Double]
[1.0,1.6665,2.333,2.9996,3.666,4.332,4.998,5.664,6.33,6.9964,7.6625,8.329,8.995,9.66,10.327]

-- wrong

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


Re: [Haskell-cafe] Bug with [Double]

2010-05-19 Thread Dmitry Olshansky
But

Prelude Data.List [1,1+2/3..4] :: [Double]
[1.0,1.6665,2.333,2.9996,3.666,4.332]

Prelude Data.List unfoldr (\n - let n'=n+2/3 in if n' = 4 then Just
(n',n') else Nothing) 1 :: [Double]
[1.6665,2.333,2.9996,3.666]

Prelude Data.List takeWhile (=4) $ iterate (+2/3) 1 :: [Double]
[1.0,1.6665,2.333,2.9996,3.666]

How 'dodgy' it should be to produce different result?
How [a,b..c] works in this case?



 2010/5/19 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com:
 Dmitry Olshansky olshansk...@gmail.com writes:

 Hello all,

 It seems that I saw something like this in Cafe recevtly. But I am not 
 sure...
 In GHC 6.12.1 (Platform 2010 on Windows Vista) I have

 Prelude [1,1+2/3..10]
 [1.0,1.6665,2.333,2.9996,3.666,4.332,4.998,5.664,6.33,6.9964,7.6625,8.329,8.995,9.66,10.327]

 -- It is a bug!

 No it isn't, because of the dodgy Ord instance for Float and Double values.

 --
 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] Bug with [Double]

2010-05-19 Thread Dmitry Olshansky
Thanks, it's clear now.

2010/5/19 Serguey Zefirov sergu...@gmail.com:
 2010/5/19 Erik de Castro Lopo mle...@mega-nerd.com:
 Dmitry Olshansky wrote:

 It seems that I saw something like this in Cafe recevtly. But I am not 
 sure...
 In GHC 6.12.1 (Platform 2010 on Windows Vista) I have

 snip


 Any comments?

 The problem you point out is not a problem with Haskell, but a problem
 with the whole concept of floating point arithmetic as implemented on
 all modern CPUs. See:

    http://docs.sun.com/source/806-3568/ncg_goldberg.html

 You would have got similar problems with just about any language running
 on the same hardware.

 This is what used for Double list generation (Haskell Platform 2010):
 --
 numericEnumFromThenTo   :: (Ord a, Fractional a) = a - a - a - [a]
 numericEnumFromThenTo e1 e2 e3
    = takeWhile predicate (numericEnumFromThen e1 e2)
                                where
                                 mid = (e2 - e1) / 2
                                 predicate | e2 = e1  = (= e3 + mid)
                                           | otherwise = (= e3 + mid)
 --
 So normal C loop like for {double i = 1; i = 10; i += 1+2/3) {
 insert_list(i); } won't generate the same list, as Haskell does in
 [1,1+2/3..10].

 PS
 Rationals:
 Prelude [1,1+2/3..10] :: [Rational]
 [1 % 1,5 % 3,7 % 3,3 % 1,11 % 3,13 % 3,5 % 1,17 % 3,19 % 3,7 % 1,23 %
 3,25 % 3,9 % 1,29 % 3,31 % 3]

 Same result.
 ___
 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] instance reification in TH

2010-04-22 Thread Dmitry Olshansky
Hello cafe,

Could you say can I determine in Template Haskell that datatype X has
instance of class Y?

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


[Haskell-cafe] ErrorT instance of MonadPlus

2010-02-26 Thread Dmitry Olshansky
Hello,

ErrorT instance of MonadPlus define that in case of fail both arguments of
mplus a value of Error will be the Error of second computation:

m `mplus` n = ErrorT $ doa - runErrorT mcase a of
   Left  _ - runErrorT nRight r - return (Right
r)

Could it be changed in this way:

m `mplus` n = ErrorT $ doa - runErrorT mcase a of
   Left  e - do

  b - runErrorT n

  case b of

  Left e' - return $ Left (e `eplus` e')

  r - return r

r - return r

where `eplus` could be placed in class Error a:

eplus :: a - a - a

eplus x y = y -- default implementation


In this case we could combine Errors more flexible.


Best regards,

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


Re: [Haskell-cafe] Haskell2Xml - Suggest looking at HXT

2009-08-11 Thread Dmitry Olshansky
Hi Max, thanks for your suggestion. I also have a not pretty code which
used Text.XML.Light and TH. I am going to rewrite it. HXT by my opinion is
too big.
The question is a requirements. Which correlations exist between Haskell
types and XML-Schema possibilities? How to prepare XML for different Haskell
types? How to generate Haskell types from XML-Schema, which restrictions
in schema could be authomatically modeled in Haskell? And so on...


2009/8/8 Max Cantor mxcan...@gmail.com

 Hi Dmitry,

 I've been using HXT and its XmlPickler class for encoding and decoding
 between XML - Haskell types.  It takes a while to wrap your brain around
 the arrows based API for HXT (something I'm still working on) but it seems
 to be quite powerful and well maintained.

 Also, I've written some Template Haskell code to derive instances for the
 XmlPickler class (so that types can automatically be encoded and decoded as
 XML.  Its not pretty, has bugs, and is far from perfect but I can send that
 to you if you'd like a way to get stared.

 Max

 On Aug 7, 2009, at 7:04 PM, Dmitry Olshansky wrote:

  Well, great thanks for interesting links.

 But definitely at first I need a time to try to understand what Generic
 Haskell and EMGM are.

 Does it stronger than Template Haskell? Could it be explained briefly and
 simplistic for first impression? Could it be compared with SYB or TH?

 Would it be applied to realisation of translation or to target Haskell
 code?

 Regards,
 Dmitry


 2009/8/7 Sean Leather leat...@cs.uu.nl

 On Fri, Aug 7, 2009 at 12:05, John Lask jvl...@hotmail.com wrote:
 the paper:

 Scripting XML with Generic Haskell
 Frank Atanassow, Dave Clarke and Johan Jeuring
 October 14, 2003

 describes a translation from XML Schema to Haskell data types (like
 dtd2haskell) in generic haskell, I believe that the code for the tool
 described may also be available, how hard it would be to migrate over to
 vanilla haskell+generics is another question

 It looks like this almost might work in EMGM. They use a Label in addition
 to all the other representation structure elements. EMGM doesn't have a
 Label, but it might be useful to add it...

 With any needed changes such as the Label done, migrating this Generic
 Haskell code to EMGM would not be difficult.

 Sean

 ___
 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] Network.Curl and posting XML data

2009-08-11 Thread Dmitry Olshansky
Hi, Erik,

Did you try Network.HTTP? Is it not enough?

2009/8/12 Erik de Castro Lopo mle...@mega-nerd.com mle%2...@mega-nerd.com


 Hi all,

 I need to do a HTTP post of XML data (Content-type == text/xml) to
 a HTTP (eventually HTTPS) server and to retrieve both the response
 code and some returned XML data.

 I have had an extensive read of the haskell-curl docs:


 http://hackage.haskell.org/packages/archive/curl/1.3.5/doc/html/Network-Curl.html

 as well as playing around with some code, but haskell-curl doesn't
 seem to support this. I've tried curlPost which along with not
 returning a response also insists on encoding my XML data as
 application/x-www-form-urlencoded which simply doesn't work.

 Anyone ben able to get something like this to work? Are there any
 alternatives to haskell-curl which will work for my application?

 Cheers,
 Erik
 --
 --
 Erik de Castro Lopo
 http://www.mega-nerd.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] Haskell2Xml

2009-08-07 Thread Dmitry Olshansky
Like in Keith proposal I need it for working with web-services, maybe Xml
transformations and so on. And I tried to make it by self with a partial
success. To work with xml I only used xml package (Text.XML.Light).

Now I am going to work a little (?) on this task to provide more standard
and regular tool than I have now. So it is very interesting for me to learn
any ideas (if exists) on this thing from community.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell2Xml

2009-08-07 Thread Dmitry Olshansky
Well, great thanks for interesting links.

But definitely at first I need a time to try to understand what Generic
Haskell and EMGM are.

Does it stronger than Template Haskell? Could it be explained briefly and
simplistic for first impression? Could it be compared with SYB or TH?

Would it be applied to realisation of translation or to target Haskell
code?

Regards,
Dmitry


2009/8/7 Sean Leather leat...@cs.uu.nl


 On Fri, Aug 7, 2009 at 12:05, John Lask jvl...@hotmail.com wrote:

 the paper:

 Scripting XML with Generic Haskell
 Frank Atanassow, Dave Clarke and Johan Jeuring
 October 14, 2003

 describes a translation from XML Schema to Haskell data types (like
 dtd2haskell) in generic haskell, I believe that the code for the tool
 described may also be available, how hard it would be to migrate over to
 vanilla haskell+generics is another question


 It looks like this almost might work in EMGM. They use a Label in addition
 to all the other representation structure elements. EMGM doesn't have a
 Label, but it might be useful to add it...

 With any needed changes such as the Label done, migrating this Generic
 Haskell code to EMGM would not be difficult.

 Sean

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


Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Dmitry Olshansky
My measurements show that
- using strict version of insertWith doesn't improve performance. - in case
of compilation with -O2 flag foldl' also is equal to foldl (-O2 gives approx
2 time impovements).- using RandomGen and State monad to generate a list
gives at least 4 times improvements (on 1 000 000 items).

More complicated improvements (using Array, PRNG and so on) were not tested
by me.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient functional idiom for histogram

2009-08-05 Thread Dmitry Olshansky
 I got the impression Dmitry was using Haskell's standard RNG, not
 Mersenne Twister. If so, then we'd get further improvements with MT,
 but that's still a hit against Haskell, as I'd interpret it as meaning
 that Haskell supplies as default a PRNG which costs noticeable
 performance in order to provide guarantees that ordinary programs
 don't need.

 Paul.

Yes, I used standard RNG just made corrections from the second Daniel
Fischer's post. My file is attached. Commented strings are from original
version and next lines are from Daniel. (Note that simulation and
simulate types depend on type of dice).
Just compile with ghc --make -O2 histogram.hs
and run
histogram +RTS -s

As a pre-intermediate ;-) I just check some proposals...


histogram.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell2Xml

2009-08-05 Thread Dmitry Olshansky
Hello all,
I need a convenient tool to generate Haskell types from XML W3C Schema
Definition (xsd) and vice versa - generate instances for Haskell ADT's to
make corresponding XML.
It is just the same that HaXml do with DTD.

I need
- using XSD
- support for unicode
- using xml-attributes as far as elements are very desirable
- by my opinion TemplateHaskell for generate instances is prefferable than
using DrIFT (which used in HaXml) - both possibilities is great of course
- generation of xsd by Haskell type is a good feature also
and so on...

Does this tool exist?

Do some articles / thoughts / standards / recomendations about
correspondence between XML and Haskell ADT's exist?

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