[Haskell-cafe] Parsec question

2013-07-24 Thread C K Kashyap
Dear Cafe,

I am trying to implement[1] parsec in go using the Monadic Parser
Combinators paper [2] . I've been able to implement plus bind and
many
While doing the implementation - I looked at bind closely

bind :: Parser a - (a - Parser b) - Parser b
p `bind` f = \inp - concat [f v inp' | (v,inp') - p inp]

I wondered if the result needs the complete list - wouldn't just the first
successful value suffice?
Perhaps -
p `bind` f = \inp - take 1 $ concat [f v inp' | (v,inp') - p inp]

Will this miss out matches?


Regards,
Kashyap

[1] https://github.com/ckkashyap/parsec/blob/master/parsec.go
[2] Monadic Parser Combinators: Graham Hutton, Erik Meijer
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec question

2013-07-24 Thread C K Kashyap
Thanks Kyle,

My initial implementation was evaluating the whole list - the current one
though just returns the first successful result. Anyway, I think I need the
backtracking - I would want the aaa as the result :)

I will now explore using go-routines to implement laziness.

Thank you so much for your input.

Regards,
Kashyap




On Thu, Jul 25, 2013 at 1:44 AM, Kyle Miller kmill31...@gmail.com wrote:

 Because of laziness, you do in a sense only take the first successful
 value.  When I've made parser combinators for Python before, I've used
 either generators or exceptions to get lazy evaluation, since computing the
 whole list of possibilities for each bind would ruin the running time of
 the algorithm (or make it never terminate).  From your go code, it looks
 like you're evaluating the entire list.

 The bind you give looks like it's for a backtracking parser.  For
 non-backtracking, though, I believe it would be possible to use Maybe.
  Parsec has a different bind operator which only lets backtracking happen
 when you explicitly allow it with 'try'.

 Assuming you're wanting a full backtracking parser, here's a
 counterexample for the take 1:

 needsList = do
   v - many (char 'a')
   a - return v  -- just to make sure the take 1 bind happens at least
 once before the next step
   guard $ length a == 3
   return a

 If my input string is , then many (char 'a') will produce matches of
 '', 'a', 'aa', 'aaa', and '', but the bind will probably force the
 incorrect one of these before it reaches the guard.

 I can't guarantee this is any good, and I haven't looked at it in a while,
 but at [1] I have an example of using exceptions to get a parsec-like
 backtracking-when-explicitly-allowed parser.  I was planning on writing an
 article about how to do this technique, but I never got around to it.

 Kyle

 [1] https://github.com/kmill/metaview/blob/master/src/mparserlib/parser.py


 On Wed, Jul 24, 2013 at 10:26 AM, C K Kashyap ckkash...@gmail.com wrote:

 Dear Cafe,

 I am trying to implement[1] parsec in go using the Monadic Parser
 Combinators paper [2] . I've been able to implement plus bind and
 many
 While doing the implementation - I looked at bind closely

 bind :: Parser a - (a - Parser b) - Parser b
 p `bind` f = \inp - concat [f v inp' | (v,inp') - p inp]

 I wondered if the result needs the complete list - wouldn't just the
 first successful value suffice?
 Perhaps -
 p `bind` f = \inp - take 1 $ concat [f v inp' | (v,inp') - p inp]

 Will this miss out matches?


 Regards,
 Kashyap

 [1] https://github.com/ckkashyap/parsec/blob/master/parsec.go
 [2] Monadic Parser Combinators: Graham Hutton, Erik Meijer

 ___
 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] Parsec question

2013-07-24 Thread C K Kashyap
Thanks Roman .. I'll try and implement laziness to retain the whole list.
Regards,
Kashyap


On Thu, Jul 25, 2013 at 3:41 AM, Roman Cheplyaka r...@ro-che.info wrote:

 To construct such an example, you have to ask yourself: when can we get a
 list of more than one element?

 Consider this:

   a = char 'a'

   ((a  a) | a)  a

 Suppose that our input is aa. The result of ((a  a) | a) would be
 the list

   [('a', ), ('a', a)]

 If you proceed with the first element of the list, the overall parse
 will fail. It can only succeed if you then try the second element.

 By the way, you shouldn't confuse Parsec (the library) with the general
 concept of parser combinators or the implementation from the paper you
 reference. The above parse would fail in Parsec as well, despite the
 fact that Parsec allows backtracking.

 Roman

 * Kashyap CK ckkash...@gmail.com [2013-07-24 08:38:53-0700]
  There is reference in the paper that empty list indicates failure...so
  could we just use it like Maybe? I'd like it very much if I could get
  an example of a missed match by not using the complete match.
 
  regards,
  Kashyap
 
  Sent from my Windows Phone
  From: Roman Cheplyaka
  Sent: 24/07/2013 8:19 PM
  To: C K Kashyap
  Cc: Haskell Cafe
  Subject: Re: [Haskell-cafe] Parsec question
  Think about this: if you always take only the first element, why do you
  need lists at all?
 
  Roman
 
  * C K Kashyap ckkash...@gmail.com [2013-07-24 19:56:29+0530]
   Dear Cafe,
  
   I am trying to implement[1] parsec in go using the Monadic Parser
   Combinators paper [2] . I've been able to implement plus bind and
   many
   While doing the implementation - I looked at bind closely
  
   bind :: Parser a - (a - Parser b) - Parser b
   p `bind` f = \inp - concat [f v inp' | (v,inp') - p inp]
  
   I wondered if the result needs the complete list - wouldn't just the
 first
   successful value suffice?
   Perhaps -
   p `bind` f = \inp - take 1 $ concat [f v inp' | (v,inp') - p inp]
  
   Will this miss out matches?
  
  
   Regards,
   Kashyap
  
   [1] https://github.com/ckkashyap/parsec/blob/master/parsec.go
   [2] Monadic Parser Combinators: Graham Hutton, Erik Meijer
 
   ___
   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] Implementing an embedded language that threads a global structure.

2013-04-22 Thread C K Kashyap
Hi Ian,
I have a couple of questions for you -

1. Could you explain why a lambda calculus like language embedded in
Haskell would be useful - I ask this because, the way I understand, Haskell
is already such a language - one could easily chose to restrict oneself to
just function definition and application. Perhaps an example problem which
can be expressed more clearly in your described embedded language but not
in Haskell would help me understand your point of view better.

2. Have you considered using the state monad?

I am personally attempting to figure out a way to embed Perl in Haskell -
as in, describe Perl like code (but statically checked) in Haskell and then
generate Perl that I could use to execute on server farms which run on old
Linux kernels where I cannot run Haskell code.

I totally get that edge of understanding feeling :)

Regards,
Kashyap




On Mon, Apr 22, 2013 at 3:22 AM, Ian Bloom ianmbl...@gmail.com wrote:

 Hi,

 I've been working on this problem for some time and I was hoping for some
 feedback. I'm trying to implement an embedded language that can thread a
 global structure through the evaluation of a term.

 A mini version of this language only includes three functions, lam, app
 and ext (lambda, apply and extension respectively). The only difference
 between this and other embedded languages is that terms embedded in an
 extension have access to a global variable that is invisible to the terms
 themselves.

 The writer of a term in this language can only access the global variable
 by applying an extension. The writer extensions insures that the effect of
 evaluation on the global variable is commutative and insures that the
 effect of the global variable on terms is constant regardless of the order
 of evaluation.

 For example the global variable could be a map with some sort of lazy
 processing. An extension that queries the map for an element might cause a
 change in the state of the map and return some information about an
 element, but as long as the change in state are commutative and the same
 information is returned about elements regardless of the order of
 evaluation then the concept is safe.

 My motivation for experimenting with such a language comes from a belief
 that certain complicated programs would be easier to express in such a
 language and that there might be very useful code transformations that
 could eventually be applied to such a language that would be possible
 because of the constraints on the behavior of extensions.

 However I have yet to properly implement a language in Haskell and so I
 decided to post what I have and look for comments.

 Basically the language takes a common form of embedded languages; a lambda
 expression such as

 \x y-x y

 would have the form:

 lam (\x - lam (\y - app x y))

 however in order to evaluate an expression the need to also apply it to a
 global term:

 lam (\x - lam (\y - app x y)) global

 Ideally the result of evaluating this would be a (global', \x y- x y), a
 modified version of global paired with the term. So the type of the term:

 lam (\x - lam (\y - app x y)) is something like g - (g, (a - b) - a
 - b) where g is the type of global.

 From that came the first idea of the types of the evaluator functions:

 lam :: ( (g-(g,a)) - (g-(g,b)) )- (g-(g, a-b))
 app :: (g-(g,a-b)) - (g-(g, a)) - (g-(g,b))

 with some additional parenthesis for sake of clarity. Each sub-term has
 the type g-(g,t)

 any function can be included as an extension as long as the function has
 the type:
 (g-(g,a)) - (g-(g,b))

 This seems to work well except that it seems to be impossible (as far as
 I've tried) to construct a definition for the lam function that both fits
 this type and properly passes the global through the entire evaluation. For
 example it's easy to define app like this:

 app :: (g-(g,a-b)) - (g-(g,a)) - (g-(g,b))
 app = (\ eA eB - \ g0 - let (gB, fB) = eB g0
  in let (gA, fA) = eA gB
  in (gA, fA fB) )

 but so far the definition of lam has eluded me. This is the closest I've
 come:

 lam :: ((g-(g,a)) - (g-(g,b))) - (g-(g,a-b))
 lam = (\ f - \ g0 - (g0, \x - snd $ (f (\ gv-(gv,x))) g0 ))

 This fits the type but I fear this definition does not return the properly
 modified version of global.

 I tried some other iterations of this idea. In one effort the first
 argument of a function is extracted into the type of a term. So a term of
 type a-b has the type (g-a-(g,b)). And a term of type a has the type
 (g-((g, a)) such that:

 lam2 :: ((g-(g,a)) - (g-(g,b))) - (g-a-(g,b))
 lam2 = (\ f - \ g x - (f (\ gv - (gv, x))) g)

 app2 :: (g-a-(g,b)) - (g-(g,a)) - (g-(g,b))
 app2 = (\ eA eB - \ g0 - let (gB, fB) = eB g0
in  eA gB fB )

 This seems like a step in the right direction unfortunately because the
 return type of lam is now (g-a-(g,b)) and not (g-(g-c)) we cannot type
 the term lam (\x - lam 

[Haskell-cafe] Assembly EDSL in Haskell

2013-04-01 Thread C K Kashyap
Hi Cafe,
I am trying to embed x86 assembly in Haskell. I'd like the EDSL to not
allow invalid movements into registers - for example, should not allow
moving into RIP. I was not able to get it to work. I ended up using
DataTypeContexts - which is considered misfeature anyway. I was wondering
if I could get some suggestions.

{-# LANGUAGE DatatypeContexts #-}

data SREG = RIP
data DREG = RBX
data SNDREG = RAX


data (Source s, Destination d) = Instruction s d = MOV s d


class Source a
class Destination a

instance Source SREG
instance Source SNDREG

instance Destination DREG
instance Destination SNDREG


move :: (Source s, Destination d) = s - d - Instruction s d
move s d = MOV s d

hello = [move RAX RAX, move RAX RAX]

hello = [move RAX RAX, move RAX RBX] -- this is still not allowed.

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


Re: [Haskell-cafe] Assembly EDSL in Haskell

2013-04-01 Thread C K Kashyap
Wow ... thanks Serguey  that gets rid of DatatypeContexts as well!

Regards,
Kashyap


On Mon, Apr 1, 2013 at 9:12 PM, Serguey Zefirov sergu...@gmail.com wrote:

 You have fixed the type of list by move RAX RAX. Now it has type
 Instruction SNDREG SNDREG

 Make your Instruction a GADT and require that MOV should have appropriate
 constraints:

 {-# LANGUAGE DatatypeContexts, GADTs #-}


 data SREG = RIP
 data DREG = RBX
 data SNDREG = RAX


 data Instruction where
 MOV :: (Source s, Destination d) = s - d - Instruction



 class Source a
 class Destination a

 instance Source SREG
 instance Source SNDREG

 instance Destination DREG
 instance Destination SNDREG


 move :: (Source s, Destination d) = s - d - Instruction
 move s d = MOV s d

 hello = [move RAX RAX, move RAX RAX]

 hello2 = [move RAX RAX, move RAX RBX] -- this is still not allowed.




 2013/4/1 C K Kashyap ckkash...@gmail.com

 Hi Cafe,
 I am trying to embed x86 assembly in Haskell. I'd like the EDSL to not
 allow invalid movements into registers - for example, should not allow
 moving into RIP. I was not able to get it to work. I ended up using
 DataTypeContexts - which is considered misfeature anyway. I was wondering
 if I could get some suggestions.

 {-# LANGUAGE DatatypeContexts #-}

 data SREG = RIP
 data DREG = RBX
 data SNDREG = RAX


 data (Source s, Destination d) = Instruction s d = MOV s d


 class Source a
 class Destination a

 instance Source SREG
 instance Source SNDREG

 instance Destination DREG
 instance Destination SNDREG


 move :: (Source s, Destination d) = s - d - Instruction s d
 move s d = MOV s d

 hello = [move RAX RAX, move RAX RAX]

 hello = [move RAX RAX, move RAX RBX] -- this is still not allowed.

 Regards,
 Kashyap


 ___
 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 some advice around lazy IO

2013-03-24 Thread C K Kashyap
Thanks for the pointer Mukesh  I'll go over the blog.

Changing the xml parser to another one from hackage - xml - helped but not
fully. I think I would need to change to bytestring. But for now, I split
the program into smaller programs and it seems to work.

Regards,
Kashyap


On Sat, Mar 23, 2013 at 11:55 AM, mukesh tiwari 
mukeshtiwari.ii...@gmail.com wrote:

 Hi Kashyap
 I am not sure if this solution to your problem but try using Bytestring
 rather than String in

 parseXML' :: String - XMLAST
 parseXML' str =
   f ast where
   ast = parse (spaces  xmlParser)  str
   f (Right x) = x

   f (Left x) = CouldNotParse


 Also see this post[1] My Space is Leaking..

 Regards,
 Mukesh Tiwari

 [1] http://www.mega-nerd.com/erikd/Blog/


 On Sat, Mar 23, 2013 at 11:11 AM, C K Kashyap ckkash...@gmail.com wrote:

 Oops...I sent out the earlier message accidentally.

 I got some profiling done and got this pdf generated. I see unhealthy
 growths in my XML parser.
 https://github.com/ckkashyap/haskell-perf-repro/blob/master/RSXP.hs
 I must be not using parsec efficiently.

 Regards,
 Kashyap




 On Sat, Mar 23, 2013 at 11:07 AM, C K Kashyap ckkash...@gmail.comwrote:

 I got some profiling done and got this pdf generated. I see unhealthy
 growths in my XML parser.



 On Fri, Mar 22, 2013 at 8:12 PM, C K Kashyap ckkash...@gmail.comwrote:

 Hi folks,

 I've run into more issues with my report generation tool  I'd
 really appreciate some help.

 I've created a repro project on github to demonstrate the problem.
 git://github.com/ckkashyap/haskell-perf-repro.git

 There is a template xml file that needs to be replicated several times
 (3000 or so) under the data directory and then driver needs to be run.
 The memory used by driver keeps growing until it runs out of memory.

 Also, I'd appreciate some tips on how to go about debugging this
 situation. I am on the windows platform.


 Regards,
 Kashyap


 On Tue, Mar 19, 2013 at 1:11 PM, Kim-Ee Yeoh k...@atamo.com wrote:

 On Tue, Mar 19, 2013 at 2:01 PM, Konstantin Litvinenko
 to.darkan...@gmail.com wrote:
  Yes. You (and Dan) are totally right. 'Let' just bind expression, not
  evaluating it. Dan's evaluate trick force rnf to run before hClose.
 As I
  said - it's tricky part especially for newbie like me :)

 To place this in perspective, one only needs to descend one or two
 more layers before the semantics starts confusing even experts.

 Whereas the difference between seq and evaluate shouldn't be too hard
 to grasp, that between evaluate and (return $!) is considerably more
 subtle, as Edward Yang notified us 10 days ago. See the thread titled
 To seq or not to seq.

 -- Kim-Ee

 ___
 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] A question about data declaration

2013-03-22 Thread C K Kashyap
Thanks Eric and Brent,

Even with GADT, it appears that I'd need extra data definitions. I'll go
without GADT then ...

Brent, my use case is not particularly complicated. I am trying to model
the pdf spec - which says that pdf contains Objects that could of of types
Number, String, Name, Array and Dictionary - while array is list of
objects, the Disctionary is a list of tuples (Name, Object) not (Object,
Object) - hence my situation.

Regards,
Kashyap


On Thu, Mar 21, 2013 at 8:58 PM, Brent Yorgey byor...@seas.upenn.eduwrote:

 On Thu, Mar 21, 2013 at 06:18:46PM +0530, C K Kashyap wrote:
  Hi,
 
  I have a situation where I need to define a data type T such that
 
  data T = C1 Int | C2 Char | C3 T
 
  However, I want to enforce a constraint that C3 only allows (C2 Char) and
  not (C1 Int). That is

 If C3 should only be able to hold a C2 Char, then why have it hold a T
 at all?  i.e. why not

   data T = C1 Int | C2 Char | C3 Char

 but I suppose your real problem is probably more complicated, in which
 case I would recommend using a GADT as others have suggested.

 -Brent

 ___
 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 some advice around lazy IO

2013-03-22 Thread C K Kashyap
Hi folks,

I've run into more issues with my report generation tool  I'd really
appreciate some help.

I've created a repro project on github to demonstrate the problem.
git://github.com/ckkashyap/haskell-perf-repro.git

There is a template xml file that needs to be replicated several times
(3000 or so) under the data directory and then driver needs to be run.
The memory used by driver keeps growing until it runs out of memory.

Also, I'd appreciate some tips on how to go about debugging this situation.
I am on the windows platform.


Regards,
Kashyap


On Tue, Mar 19, 2013 at 1:11 PM, Kim-Ee Yeoh k...@atamo.com wrote:

 On Tue, Mar 19, 2013 at 2:01 PM, Konstantin Litvinenko
 to.darkan...@gmail.com wrote:
  Yes. You (and Dan) are totally right. 'Let' just bind expression, not
  evaluating it. Dan's evaluate trick force rnf to run before hClose. As I
  said - it's tricky part especially for newbie like me :)

 To place this in perspective, one only needs to descend one or two
 more layers before the semantics starts confusing even experts.

 Whereas the difference between seq and evaluate shouldn't be too hard
 to grasp, that between evaluate and (return $!) is considerably more
 subtle, as Edward Yang notified us 10 days ago. See the thread titled
 To seq or not to seq.

 -- Kim-Ee

 ___
 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 some advice around lazy IO

2013-03-22 Thread C K Kashyap
I got some profiling done and got this pdf generated. I see unhealthy
growths in my XML parser.



On Fri, Mar 22, 2013 at 8:12 PM, C K Kashyap ckkash...@gmail.com wrote:

 Hi folks,

 I've run into more issues with my report generation tool  I'd really
 appreciate some help.

 I've created a repro project on github to demonstrate the problem.
 git://github.com/ckkashyap/haskell-perf-repro.git

 There is a template xml file that needs to be replicated several times
 (3000 or so) under the data directory and then driver needs to be run.
 The memory used by driver keeps growing until it runs out of memory.

 Also, I'd appreciate some tips on how to go about debugging this
 situation. I am on the windows platform.


 Regards,
 Kashyap


 On Tue, Mar 19, 2013 at 1:11 PM, Kim-Ee Yeoh k...@atamo.com wrote:

 On Tue, Mar 19, 2013 at 2:01 PM, Konstantin Litvinenko
 to.darkan...@gmail.com wrote:
  Yes. You (and Dan) are totally right. 'Let' just bind expression, not
  evaluating it. Dan's evaluate trick force rnf to run before hClose. As I
  said - it's tricky part especially for newbie like me :)

 To place this in perspective, one only needs to descend one or two
 more layers before the semantics starts confusing even experts.

 Whereas the difference between seq and evaluate shouldn't be too hard
 to grasp, that between evaluate and (return $!) is considerably more
 subtle, as Edward Yang notified us 10 days ago. See the thread titled
 To seq or not to seq.

 -- Kim-Ee

 ___
 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 some advice around lazy IO

2013-03-22 Thread C K Kashyap
Oops...I sent out the earlier message accidentally.

I got some profiling done and got this pdf generated. I see unhealthy
growths in my XML parser.
https://github.com/ckkashyap/haskell-perf-repro/blob/master/RSXP.hs
I must be not using parsec efficiently.

Regards,
Kashyap




On Sat, Mar 23, 2013 at 11:07 AM, C K Kashyap ckkash...@gmail.com wrote:

 I got some profiling done and got this pdf generated. I see unhealthy
 growths in my XML parser.



 On Fri, Mar 22, 2013 at 8:12 PM, C K Kashyap ckkash...@gmail.com wrote:

 Hi folks,

 I've run into more issues with my report generation tool  I'd really
 appreciate some help.

 I've created a repro project on github to demonstrate the problem.
 git://github.com/ckkashyap/haskell-perf-repro.git

 There is a template xml file that needs to be replicated several times
 (3000 or so) under the data directory and then driver needs to be run.
 The memory used by driver keeps growing until it runs out of memory.

 Also, I'd appreciate some tips on how to go about debugging this
 situation. I am on the windows platform.


 Regards,
 Kashyap


 On Tue, Mar 19, 2013 at 1:11 PM, Kim-Ee Yeoh k...@atamo.com wrote:

 On Tue, Mar 19, 2013 at 2:01 PM, Konstantin Litvinenko
 to.darkan...@gmail.com wrote:
  Yes. You (and Dan) are totally right. 'Let' just bind expression, not
  evaluating it. Dan's evaluate trick force rnf to run before hClose. As
 I
  said - it's tricky part especially for newbie like me :)

 To place this in perspective, one only needs to descend one or two
 more layers before the semantics starts confusing even experts.

 Whereas the difference between seq and evaluate shouldn't be too hard
 to grasp, that between evaluate and (return $!) is considerably more
 subtle, as Edward Yang notified us 10 days ago. See the thread titled
 To seq or not to seq.

 -- Kim-Ee

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






driver.pdf
Description: Adobe PDF document
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] A question about data declaration

2013-03-21 Thread C K Kashyap
Hi,

I have a situation where I need to define a data type T such that

data T = C1 Int | C2 Char | C3 T

However, I want to enforce a constraint that C3 only allows (C2 Char) and
not (C1 Int). That is

x = C3 (C1 10) -- should not compile - but my above definition will let it
compile


I was thinking of this -

data C1 = C1 Int
data C2 = C2 Char
data T = TC1 C1 | TC1 C2 | TC3 C2

Is there a better way to do it?

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


Re: [Haskell-cafe] Need some advice around lazy IO

2013-03-18 Thread C K Kashyap
Thanks Konstantin ... I'll try that out too...



Regards,
Kashyap


On Mon, Mar 18, 2013 at 3:31 PM, Konstantin Litvinenko 
to.darkan...@gmail.com wrote:

 On 03/17/2013 07:08 AM, C K Kashyap wrote:

 I am working on an automation that periodically fetches bug data from
 our bug tracking system and creates static HTML reports. Things worked
 fine when the bugs were in the order of 200 or so. Now I am trying to
 run it against 3000 bugs and suddenly I see things like - too  many open
 handles, out of memory etc ...

 Here's the code snippet - http://hpaste.org/84197

 It's a small snippet and I've put in the comments stating how I run into
 out of file handles or simply file not getting read due to lazy IO.

 I realize that putting ($!) using a trial/error approach is going to be
 futile. I'd appreciate some pointers into the tools I could use to get
 some idea of which expressions are building up huge thunks.


 You problem is in

 let bug = ($!) fileContents2Bug str

 ($!) evaluate only WHNF and you need NF. Above just evaluate to first char
 in a file, not to all content. To fully evaluate 'str' you need something
 like

 let bug = Control.DeepSeq.rnf str `seq` fileContents2Bug str






 __**_
 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] Need some advice around lazy IO

2013-03-17 Thread C K Kashyap
Thanks everyone,

Dan, MapMI worked for me ...

Regards,
Kashyap


On Mon, Mar 18, 2013 at 12:42 AM, Petr Pudlák petr@gmail.com wrote:

 Hi Kashyap,

 you could also use iteratees or conduits for a task like that. The beauty
 of such libraries is that they can ensure that a resource is always
 properly disposed of. See this simple example:
 https://gist.github.com/anonymous/5183107
 It prints the first line of each file given as an argument. After each
 line is printed, the `fileConduit` pipe ensures that the handle is closed.
 It also makes the program nicely composable.

 Best regards,
 Petr


 import Control.Monad
 import Control.Monad.Trans.Class

 import Control.Monad.IO.Class
 import Data.Conduit

 import Data.Conduit.List
 import System.Environment

 import System.IO


 {- | Accept file paths on input, output opened file handle, and ensure that 
 the
  - handle is always closed after its downstream pipe finishes whatever work 
 on it. -}

 fileConduit :: MonadResource m = IOMode - Conduit FilePath m Handle

 fileConduit mode = awaitForever process

   where
 process file = bracketP (openFile file mode) closeWithMsg yield

 closeWithMsg h = do

 putStrLn Closing file


 hClose h

 {- | Print the first line from each handle on input. Don't care about the 
 handle. -}

 firstLine :: MonadIO m = Sink Handle m ()

 firstLine = awaitForever (liftIO . (hGetLine = putStrLn))


 main = do

 args - getArgs


 runResourceT $ sourceList args =$= fileConduit ReadMode $$ firstLine




 2013/3/17 C K Kashyap ckkash...@gmail.com

 Hi,

 I am working on an automation that periodically fetches bug data from our
 bug tracking system and creates static HTML reports. Things worked fine
 when the bugs were in the order of 200 or so. Now I am trying to run it
 against 3000 bugs and suddenly I see things like - too  many open handles,
 out of memory etc ...

 Here's the code snippet - http://hpaste.org/84197

 It's a small snippet and I've put in the comments stating how I run into
 out of file handles or simply file not getting read due to lazy IO.

 I realize that putting ($!) using a trial/error approach is going to be
 futile. I'd appreciate some pointers into the tools I could use to get some
 idea of which expressions are building up huge thunks.


 Regards,
 Kashyap

 ___
 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] Need some advice around lazy IO

2013-03-16 Thread C K Kashyap
Hi,

I am working on an automation that periodically fetches bug data from our
bug tracking system and creates static HTML reports. Things worked fine
when the bugs were in the order of 200 or so. Now I am trying to run it
against 3000 bugs and suddenly I see things like - too  many open handles,
out of memory etc ...

Here's the code snippet - http://hpaste.org/84197

It's a small snippet and I've put in the comments stating how I run into
out of file handles or simply file not getting read due to lazy IO.

I realize that putting ($!) using a trial/error approach is going to be
futile. I'd appreciate some pointers into the tools I could use to get some
idea of which expressions are building up huge thunks.


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


Re: [Haskell-cafe] ANNOUNCE: netpbm

2013-03-02 Thread C K Kashyap
That sounds cool Way to go Niklas!!!

Regards,
Kashyap


On Sat, Mar 2, 2013 at 6:24 AM, Niklas Hambüchen m...@nh2.me wrote:

 I'm happy to announce a new library, netpbm, a full implementation of
 the netpbm image formats (PPM, PGM, PBM) in pure Haskell.

 The P*N formats describe themselves as as easy as possible; they
 mainly consist of dimensions + uncompressed data and are used especially
 in between graphics programs, e.g. between ImageMagick and its
 ghostscript part as well as in ffmpeg.

 There are six formats (bitmap, greyscale, color, each of them coming in
 binary and ASCII variants). This parses all of them.

 The main focus of this library is *pedantic* adherence to the spec
 (http://netpbm.sourceforge.net/doc/pbm.html) - in fact I claim that all
 implementations out there do not properly implement the spec correctly,
 not even the netpbm project itself. I have not properly verified this
 yet, but my library can parse valid PPM files that don't display in my
 image viewer (which is built on top of the C library in question).
 To be honest, one cannot really blame anybody for this since netpbm
 allows pretty insane things (such as comments inside numeric literals)
 and its claim to be simple is absolutely hilarious.

 haskell-netpbm is backed by an extensive test suite that checks its
 compatibility with images created by common programs (GIMP, convert),
 public data sets, and random pictures I found on the Internet.

 It is built using attoparsec. You can find it on

 http://hackage.haskell.org/package/netpbm

 Any contributions in form of code, tests images or claims that I don't
 implement the spec right are highly welcome at

 https://github.com/nh2/haskell-netpbm

 Please note that I just finished the implementation and that I will
 clean up (break) the API in the next release, but I found it made sense
 to announce it as early as possible now that the format implementation
 is complete.

 Niklas

 ___
 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] Question about forkIO

2013-02-28 Thread C K Kashyap
Hi All,

Say I have a haskell function 'f' that does a forkIO and starts an action
a.  I create a DLL of this haskell code and inovke f from C. Can I
expect the a to continue to run once f has returned to C?

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


Re: [Haskell-cafe] Question about forkIO

2013-02-28 Thread C K Kashyap
Just to clarify, here is the sample haskell code that I am using -
{-# LANGUAGE ForeignFunctionInterface #-}
module Glue where
import Foreign.C.String
import qualified Control.Concurrent as CC

funHaskell :: CString - IO Int
funHaskell cstr = do
 putStrLn Haskell function called
 str - peekCString cstr
 CC.forkIO $ doForever str
 CC.threadDelay 200
 return 0

doForever str = do
  putStrLn Hello World forever
  CC.threadDelay 100
  doForever str

foreign export stdcall funHaskell :: CString - IO Int


When I call funHaskell from my C program, Hello World forever gets
printed about twice - I think its because funHaskell waits for about 2
seconds before returning. However, once back in C land, the doForever
function stops to execute. I was wondering if there is some setting that
would allow the threads sparked to continue execute.

Regards,
Kashyap


On Thu, Feb 28, 2013 at 4:39 PM, C K Kashyap ckkash...@gmail.com wrote:

 Hi All,

 Say I have a haskell function 'f' that does a forkIO and starts an action
 a.  I create a DLL of this haskell code and inovke f from C. Can I
 expect the a to continue to run once f has returned to C?

 Regards,
 Kashyap

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


Re: [Haskell-cafe] How to return a network connection to C

2013-02-28 Thread C K Kashyap
I am using http://hackage.haskell.org/package/connection.
So I create network connection in Haskell

getConnection :: IO Connection

I'd like this connection to be returned to C so that subsequent calls from
C can send in the connection handle.

Regards,
Kashyap


On Thu, Feb 28, 2013 at 9:04 PM, Niklas Hambüchen m...@nh2.me wrote:

 What data type are you dealing with exactly?

 If you have a socket, I guess you can just use it from C (via FFI).

 PS:
 By Network.Connection, do you mean
 http://hackage.haskell.org/package/network-connection-0.1.1 ? Seems
 deprecated.

 On 28/02/13 06:14, C K Kashyap wrote:
  Hi,
  I am using Network.Connection to connect to gmail in my Haskell module -
  that's compiled to DLL and invoked from C.
 
  I need a mechanism to return the connection handle to C so that it can
  pass it in the subsequent calls. How can I achieve this?
 
  Regards,
  Kashyap
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 

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


Re: [Haskell-cafe] How to return a network connection to C

2013-02-28 Thread C K Kashyap
Okay, for now I have figured out a working solution to the original problem
I was facing .

I just forkIO another IO action that does the actual network work and in
addition, it opens a server socket and waits for commands.

The calls from C reach Haskell, from where a connection is made to the
server and command is sent. A little convoluted but works. I have the whole
implementation here - https://github.com/ckkashyap/gmail
So now I am able to create a standalone, self sufficient DLL that I can
just hand off to the folks in my org and they can write a C program and
connect to gmail

Hey Donn ... when you say, implement the IO in C, you also imply
implementing the SSL stuff too right? ... that's one thing I wanted to
avoid - and I was also reluctant to use something like openSSL because that
would come in the way of making standalone, self - sufficient DLL.

I really have to see what kind of performance hit my DLL has ...

Regards,
Kashyap


On Fri, Mar 1, 2013 at 12:07 AM, Donn Cave d...@avvanta.com wrote:

 Quoth C K Kashyap ckkash...@gmail.com,

  I am using http://hackage.haskell.org/package/connection.
  So I create network connection in Haskell
 
  getConnection :: IO Connection
 
  I'd like this connection to be returned to C so that subsequent calls
 from
  C can send in the connection handle.

 According to the documentation, he doesn't export enough of the
 Connection type to access the handle inside, and there appears to
 be no function provided to do that either.  So it looks to me like
 you'd have to 1) make the connection by hand with Network.Socket.connect
 etc., 2) get the Socket fd, 3) make a Handle from the Socket,
 4) pass that to connectFromHandle, and 5) use the fd with your
 C function.

 Note that the socket connection itself, represented by the fd that
 you return to C, will simply transmit data back and forth without
 modification.  Specifically without SSL encryption.  If you need
 SSL encryption in both Haskell and C, it would probably be simpler
 to implement the I/O in C and call it from Haskell.

 Donn

 ___
 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] Question about forkIO

2013-02-28 Thread C K Kashyap
Hey Donn .. thanks, it turns out that threads do resume!!! This is how
I got my gmail stuff working.
I only have a doubt if the TCP keep/alive stuff continues to happen or
not

Regards,
Kashyap


On Thu, Feb 28, 2013 at 9:07 PM, Donn Cave d...@avvanta.com wrote:

 Quoth C K Kashyap ckkash...@gmail.com,
 ...
  Say I have a haskell function 'f' that does a forkIO and starts an action
  a.  I create a DLL of this haskell code and inovke f from C. Can I
  expect the a to continue to run once f has returned to C?

 Once control returns to f's caller, outside of the Haskell runtime,
 then there isn't any way to dispatch IO threads - that's done by
 the runtime, so it can happen only while executing in the runtime.
 I am not a forkIO expert, that's just how it appears to me from my
 limited understanding of how they work.

 For extra credit - do the old IO threads resume if you call 'f' again,
 so you'd have more each time?  (I don't know!)

 Donn

 ___
 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] Running out of space while concatinating a list of bytestring

2013-02-27 Thread C K Kashyap
Hi,

I have the following code - It looks like things go okay until
concatination is attempted. I get the following output

There are 2258 ByteStrings
*** Exception: stdout: hPutBuf: resource exhausted (Not enough space)

I am thinking that I should do strict concatination at each point in the
support function - how can I go about doing so? (BS is the lazy.char8
bytestring)


connectionGetNBytes :: NC.Connection - Int - IO ByteString
connectionGetNBytes c n = do
bs - connectionGetNBytes' c n
putStrLn (There are  ++ (show (length bs)) ++ 
ByteStrings)
return (BS.concat bs)

connectionGetNBytes' :: NC.Connection - Int - IO [ByteString]
connectionGetNBytes' _ 0 = return []
connectionGetNBytes' c n = do
l - NC.connectionGet c n
let ll = BS.length l
remaining - connectionGetNBytes' c (n - ll)
return (l:crlfStr:remaining)


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


Re: [Haskell-cafe] Running out of space while concatinating a list of bytestring

2013-02-27 Thread C K Kashyap
Oops, false alarm.
Please ignore - and sorry about it.
Regards,
Kashyap


On Wed, Feb 27, 2013 at 1:32 PM, C K Kashyap ckkash...@gmail.com wrote:

 Hi,

 I have the following code - It looks like things go okay until
 concatination is attempted. I get the following output

 There are 2258 ByteStrings
 *** Exception: stdout: hPutBuf: resource exhausted (Not enough space)

 I am thinking that I should do strict concatination at each point in the
 support function - how can I go about doing so? (BS is the lazy.char8
 bytestring)


 connectionGetNBytes :: NC.Connection - Int - IO ByteString
 connectionGetNBytes c n = do
 bs - connectionGetNBytes' c n
 putStrLn (There are  ++ (show (length bs)) ++ 
 ByteStrings)
 return (BS.concat bs)

 connectionGetNBytes' :: NC.Connection - Int - IO [ByteString]
 connectionGetNBytes' _ 0 = return []
 connectionGetNBytes' c n = do
 l - NC.connectionGet c n
 let ll = BS.length l
 remaining - connectionGetNBytes' c (n - ll)
 return (l:crlfStr:remaining)


 Regards,
 Kashyap

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


[Haskell-cafe] How to return a network connection to C

2013-02-27 Thread C K Kashyap
Hi,
I am using Network.Connection to connect to gmail in my Haskell module -
that's compiled to DLL and invoked from C.

I need a mechanism to return the connection handle to C so that it can pass
it in the subsequent calls. How can I achieve this?

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


[Haskell-cafe] Need urgent help with Network.tls

2013-02-23 Thread C K Kashyap
Hi,

I am trying to use Haskell to download email/attachments from gmail. For
which I am exploring Network.TLS. I got this sample from the net that
connects to gmail smtp and works just fine -
http://hpaste.org/82890

However, when I modify it a bit to try to connect to imap, it simply does
not work. To debug, I tried to connect to a webserver, even that seems to
not work. I modified the function as follows.


emailGmail2 = do
let host = localhost
let port = 443
let params = defaultParamsClient{pCiphers = ciphers}
g - RNG.makeSystem
h - connectTo host (PortNumber (fromIntegral port))
hSetBuffering h LineBuffering
cWrite h GET / HTTP/1.0
cWrite h 
cWaitFor h ABCD
con - contextNewOnHandle h params g
handshake con
bye con


And I get a BAD request response from the server - Can some please give
me a sample code that uses Network.TLS to connect to a imap.google.com (or
even a webserver for that matter)?

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


Re: [Haskell-cafe] Need urgent help with Network.tls

2013-02-23 Thread C K Kashyap
The reason I want to use TLS is that I'd want to pack the whole thing in a
DLL and give it off to a friend for use.

What I am really looking for is a small sample code that demonstrates how
TLS package can be used to connect to a webserver or imapserver.

Regards,
Kashyap


On Sat, Feb 23, 2013 at 10:46 PM, satvik chauhan mystic.sat...@gmail.comwrote:

 You can use HaskellNet http://hackage.haskell.org/package/HaskellNet or
 imapget http://hackage.haskell.org/package/imapget directly or look
 into their source code for connecting to imap manually.

 -Satvik

 On Sat, Feb 23, 2013 at 8:58 PM, C K Kashyap ckkash...@gmail.com wrote:

 Hi,

 I am trying to use Haskell to download email/attachments from gmail. For
 which I am exploring Network.TLS. I got this sample from the net that
 connects to gmail smtp and works just fine -
 http://hpaste.org/82890

 However, when I modify it a bit to try to connect to imap, it simply does
 not work. To debug, I tried to connect to a webserver, even that seems to
 not work. I modified the function as follows.


 emailGmail2 = do
 let host = localhost
 let port = 443
 let params = defaultParamsClient{pCiphers = ciphers}
  g - RNG.makeSystem
 h - connectTo host (PortNumber (fromIntegral port))
 hSetBuffering h LineBuffering
  cWrite h GET / HTTP/1.0
 cWrite h 
 cWaitFor h ABCD
  con - contextNewOnHandle h params g
 handshake con
 bye con


 And I get a BAD request response from the server - Can some please give
 me a sample code that uses Network.TLS to connect to a imap.google.com(or 
 even a webserver for that matter)?

 Regards,
 Kashyap

 ___
 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 urgent help with Network.tls

2013-02-23 Thread C K Kashyap
What I am looking to achieve is - create a DLL that would do the complete
gmail thing that could be linked to a standard C program (on windows) and
could be used to download emails from gmail.
What I gathered from HsOpenSSL (which is required for HaskellNet) depends
on some native ssl dll  That is the reason I wanted to get a standalone
library ... again, I might have got the whole thing wrong.

Regards,
Kashyap


On Sun, Feb 24, 2013 at 3:54 AM, Jason Dusek jason.du...@gmail.com wrote:

 2013/2/23 C K Kashyap ckkash...@gmail.com:
  The reason I want to use TLS is that I'd want to pack the whole thing in
 a
  DLL and give it off to a friend for use.

 Why does this requirement compel you to forego the imapget or HaskellNet
 packages?

 --
 Jason Dusek
 pgp // solidsnack // C1EBC57DC55144F35460C8DF1FD4C6C1FED18A2B

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


Re: [Haskell-cafe] Need urgent help with Network.tls

2013-02-23 Thread C K Kashyap
Thank you so much Vincent,

I think this is what I need ... I tried to use it to connect to a local web
server running in 443 - http://hpaste.org/82943 however, I get the
following error -

ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))

Am I missing something?

Regards,
Kashyap


On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez t...@snarc.org wrote:

 On 02/23/2013 06:58 PM, C K Kashyap wrote:

 The reason I want to use TLS is that I'd want to pack the whole thing in a
 DLL and give it off to a friend for use.

 What I am really looking for is a small sample code that demonstrates how
 TLS package can be used to connect to a webserver or imapserver.

 Regards,
 Kashyap


 Kashyap,

 I suggest you look at the connection package [1] which is made for this
 specific purpose, and comes with examples on how to use it [2].

 If you want to only use tls, i suggest to look at connection's code [3],
 or the tls-debug [4] package, which got many small utils that use tls.

 [1] 
 http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection
 [2] 
 https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
 https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples
 [3] https://github.com/vincenthz/**hs-connection/blob/master/**
 Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs
 [4] 
 https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src

 --
 Vincent

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


Re: [Haskell-cafe] Need urgent help with Network.tls

2013-02-23 Thread C K Kashyap
Okay ... looks like connection is exactly what I want  The examples
work just fine on Linux .. however, on Windows, I continue to get the
WSACONNECTIONREFUSED eror.

Even adding a withSocketsDo does not seem to help.

Regards,
Kashyap


On Sun, Feb 24, 2013 at 8:58 AM, C K Kashyap ckkash...@gmail.com wrote:

 Thank you so much Vincent,

 I think this is what I need ... I tried to use it to connect to a local
 web server running in 443 - http://hpaste.org/82943 however, I get the
 following error -

 ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))

 Am I missing something?

 Regards,
 Kashyap


 On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez t...@snarc.org wrote:

 On 02/23/2013 06:58 PM, C K Kashyap wrote:

 The reason I want to use TLS is that I'd want to pack the whole thing in
 a
 DLL and give it off to a friend for use.

 What I am really looking for is a small sample code that demonstrates how
 TLS package can be used to connect to a webserver or imapserver.

 Regards,
 Kashyap


 Kashyap,

 I suggest you look at the connection package [1] which is made for this
 specific purpose, and comes with examples on how to use it [2].

 If you want to only use tls, i suggest to look at connection's code [3],
 or the tls-debug [4] package, which got many small utils that use tls.

 [1] 
 http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection
 [2] 
 https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
 https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples
 [3] https://github.com/vincenthz/**hs-connection/blob/master/**
 Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs
 [4] 
 https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src

 --
 Vincent



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


Re: [Haskell-cafe] Need urgent help with Network.tls

2013-02-23 Thread C K Kashyap
Okay ... now magically, I stopped seeing the WSACONNECTIONREFUSED
error!!! ..

Regards,
Kashyap


On Sun, Feb 24, 2013 at 10:03 AM, C K Kashyap ckkash...@gmail.com wrote:

 Okay ... looks like connection is exactly what I want  The examples
 work just fine on Linux .. however, on Windows, I continue to get the
 WSACONNECTIONREFUSED eror.

 Even adding a withSocketsDo does not seem to help.

 Regards,
 Kashyap


 On Sun, Feb 24, 2013 at 8:58 AM, C K Kashyap ckkash...@gmail.com wrote:

 Thank you so much Vincent,

 I think this is what I need ... I tried to use it to connect to a local
 web server running in 443 - http://hpaste.org/82943 however, I get the
 following error -

 ssl_client.hs: connect: failed (Connection refused (WSAECONNREFUSED))

 Am I missing something?

 Regards,
 Kashyap


 On Sun, Feb 24, 2013 at 3:42 AM, Vincent Hanquez t...@snarc.org wrote:

 On 02/23/2013 06:58 PM, C K Kashyap wrote:

 The reason I want to use TLS is that I'd want to pack the whole thing
 in a
 DLL and give it off to a friend for use.

 What I am really looking for is a small sample code that demonstrates
 how
 TLS package can be used to connect to a webserver or imapserver.

 Regards,
 Kashyap


 Kashyap,

 I suggest you look at the connection package [1] which is made for this
 specific purpose, and comes with examples on how to use it [2].

 If you want to only use tls, i suggest to look at connection's code [3],
 or the tls-debug [4] package, which got many small utils that use tls.

 [1] 
 http://hackage.haskell.org/**package/connectionhttp://hackage.haskell.org/package/connection
 [2] 
 https://github.com/vincenthz/**hs-connectionhttps://github.com/vincenthz/hs-connection
 https://github.**com/vincenthz/hs-connection/**tree/master/exampleshttps://github.com/vincenthz/hs-connection/tree/master/examples
 [3] https://github.com/vincenthz/**hs-connection/blob/master/**
 Network/Connection.hshttps://github.com/vincenthz/hs-connection/blob/master/Network/Connection.hs
 [4] 
 https://github.com/vincenthz/**hs-tls/tree/master/debug/srchttps://github.com/vincenthz/hs-tls/tree/master/debug/src

 --
 Vincent




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


Re: [Haskell-cafe] Chordify, a new web startup using Haskell

2013-01-17 Thread C K Kashyap
Very cool :)
I tried this one http://chordify.net/chords/jamelia-superstar-emimusic
Not sure if the places it showed E flat - was it really E flat minor?

What next - index all the songs using their chordification and then
search them using a hum as input :)

Regards,
Kashyap


On Fri, Jan 18, 2013 at 4:37 AM, José Pedro Magalhães j...@cs.uu.nl wrote:

 Hi all,

 I'd like to introduce Chordify http://chordify.net/ [1], an online
 music player that extracts chords from musical sources like Soundcloud,
 Youtube or your own files, and shows you which chord to play when. Here's
 an example song:
 http://chordify.net/chords/passenger-let-her-go-official-video-passengermusic

 The aim of Chordify is to make state-of-the-art music technology
 accessible to a broader audience. Behind the scenes, Chordify uses the
 HarmTrace Haskell package to compute chords from audio. I've been working
 on this project with a couple of colleagues for a while now, and recently
 we have made the website public, free to use for everyone.

 We do not use Haskell for any of the frontend/user interface, but the
 backend is entirely written in Haskell (and it uses pretty advanced
 features, such as GADTs and type families [3]). We're particularly
 interested in user feedback at this stage, so if you're interested in music
 and could use an automatic chord transcription service, please try Chordify!


 Cheers,
 Pedro

 [1] http://chordify.net/
 [2] http://hackage.haskell.org/package/HarmTrace
 [3] José Pedro Magalhães and W. Bas de Haas. Functional Modelling of
 Musical Harmony: an Experience Report. In Proceedings of the 16th ACM
 SIGPLAN International Conference on Functional Programming (ICFP'11), pp.
 156–162, ACM, 2011. http://dreixel.net/research/pdf/fmmh.pdf


 ___
 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] Is Hackage down?

2012-09-13 Thread C K Kashyap
Is it just me or is Hackage indeed been going down more frequently of late?

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


[Haskell-cafe] Code review request - using ErrorT

2012-08-31 Thread C K Kashyap
Dear gentle Haskellers,

I'd appreciate it very much if you could please take a look the my code
here and give me some feedback -

https://github.com/ckkashyap/haskell-websocket/blob/master/src/lib/Net/WebSocket/Request.hs

I am particularly looking for advice around what would be a good type for a
server handler function that does IO and needs to short circuit if it fails
at any point also needs to thread a state along. I am considering this -

ErrorT String (StateT Int IO) Data


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


Re: [Haskell-cafe] Capturing the parent element as I parse XML using parsec

2012-07-30 Thread C K Kashyap
Thank you Richard and Antoine.

I think I see the pointlessness of my ask.

Regards,
Kashyap

On Mon, Jul 30, 2012 at 4:14 AM, Richard O'Keefe o...@cs.otago.ac.nz wrote:


 On 29/07/2012, at 6:21 PM, C K Kashyap wrote:
  I am struggling with an idea though - How can I capture the parent
 element of each element as I parse? Is it possible or would I have to do a
 second pass to do the fixup?

 Why do you *want* the parent element of each element?
 One of the insanely horrible aspects of the Document Object Model is that
 every
 element is nailed in place by pointers everywhere, with the result that you
 cannot share elements, and even moving an element was painful.
 I still do a fair bit of SGML/XML process in C using a Document Value
 Model
 library that uses hash consing, and it's so much easier it isn't funny.

 While you are traversing a document tree it is useful to keep track of the
 path from the root.  Given

 data XML
= Element String [(String,String)] [XML]
| Text String

 you do something like

 traverse :: ([XML] - [a] - a) - ([XML] - String - a) - XML - a
 traverse f g xml = loop [] xml
   where loop ancs (Text s)   = g ancs  s
 loop ancs e@(Element _ _ ks) = f ancs' (map (loop ancs') ks)
where ancs' = e:ancs

 (This is yet another area where Haskell's non-strictness pays off.)
 If you do that, then you have the parent information available without
 it being stored in the tree.





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


Re: [Haskell-cafe] Current state of garbage collection in Haskell

2012-07-30 Thread C K Kashyap
Thank you so much Alexander and Thomas.

Regards,
Kashyap

On Sun, Jul 29, 2012 at 11:59 PM, Thomas Schilling
nomin...@googlemail.comwrote:

 GHC does not provide any form of real-time guarantees (and support for
 them is not planned).

 That said, it's not as bad as it sounds:

  - Collecting the first (young) generation is fast and you can control
 the size of that first generation via runtime system (RTS) options.

  - The older generation is collected rarely and can be collected in
 parallel.

  - You can explicitly invoke the GC via System.Mem.performGC

 In a multi-threaded / multi-core program collecting the first
 generation still requires stopping all application threads even though
 only one thread (CPU) will perform GC (and having other threads help
 out usually doesn't work out due to locality issues). This can be
 particularly expensive if the OS decides to deschedule an OS thread,
 as then the GHC RTS has to wait for the OS. You can avoid that
 particular problem by properly configuring the OS via (linux boot
 isolcpus=... and taskset(8)). The GHC team has been working on a
 independent *local* GC, but it's unlikely to make it into the main
 branch at this time. It turned out to be very difficult to implement,
 with not large enough gains. Building a fully-concurrent GC is
 (AFAICT) even harder.

 I don't know how long the pause times for your 500MB live heap would
 be. Generally, you want your heap to be about twice the size of your
 live data. Other than that it depends heavily on the characteristics
 of you heap objects. E.g., if it's mostly arrays of unboxed
 non-pointer data, then it'll be very quick to collect (since the GC
 doesn't have to do anything with the contents of these arrays). If
 it's mostly many small objects with pointers to other objects, GC will
 be very expensive and bound by the latency of your RAM. So, I suggest
 you run some tests with realistic heaps.

 Regarding keeping up, Simon Marlow is the main person working on GHC's
 GC (often collaborating with others) and he keeps a list of papers on
 his homepage: http://research.microsoft.com/en-us/people/simonmar/

 If you have further questions about GHC's GC, you can ask them on the
 glasgow-haskell-us...@haskell.org mailing list (but please consult the
 GHC user's guide section on RTS options first).

 HTH

 On 29 July 2012 08:52, C K Kashyap ckkash...@gmail.com wrote:
  Hi,
  I was looking at a video that talks about GC pauses. That got me curious
  about the current state of GC in Haskell - say ghc 7.4.1.
  Would it suffer from lengthy pauses when we talk about memory in the
 range
  of 500M +?
  What would be a good way to keep abreast with the progress on haskell GC?
  Regards,
  Kashyap
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 



 --
 Push the envelope. Watch it bend.

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


[Haskell-cafe] Capturing the parent element as I parse XML using parsec

2012-07-29 Thread C K Kashyap
Hi,

With the help of the cafe I've been able to write up the xml parser using
parsec -
https://github.com/ckkashyap/really-simple-xml-parser/blob/master/RSXP.hs

I am struggling with an idea though - How can I capture the parent element
of each element as I parse? Is it possible or would I have to do a second
pass to do the fixup?

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


[Haskell-cafe] Current state of garbage collection in Haskell

2012-07-29 Thread C K Kashyap
Hi,
I was looking at a video that talks about GC pauses. That got me curious
about the current state of GC in Haskell - say ghc 7.4.1.
Would it suffer from lengthy pauses when we talk about memory in the range
of 500M +?
What would be a good way to keep abreast with the progress on haskell GC?
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need help with learning Parsec

2012-07-23 Thread C K Kashyap
Thank you so much Christian for your feedback ... I shall incorporate them.

Regards,
Kashyap

On Mon, Jul 23, 2012 at 3:17 PM, Christian Maeder
christian.mae...@dfki.dewrote:

 Am 22.07.2012 17:21, schrieb C K Kashyap:

  I've updated the parser here -
 https://github.com/ckkashyap/**LearningPrograms/blob/master/**
 Haskell/Parsing/xml_3.hshttps://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_3.hs

 The whole thing is less than 100 lines and it can handle comments as well.


 This code is still not nice: Duplicate code in openTag and
 withoutExplictCloseTag.

 The toplevel-try in
   try withoutExplictCloseTag |  withExplicitCloseTag
 should be avoided by factoring out the common prefix.

 Again, I would avoid notFollowedBy by using many1.

   tag - try(char ''  many1 (letter | digit))

 In quotedChar you do not only want to escape the quote but at least the
 backslash, too. You could allow to escape any character by a backslash
 using:
   quotedChar c =
 try (char '\\'  anyChar) | noneOf [c, '\\']

 Writing a separate parser stripLeadingSpaces is overkill. Just use
   spaces  parseXML

 (or apply dropWhile isSpace to the input string)

 C.

 [...]

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


Re: [Haskell-cafe] Need help with learning Parsec

2012-07-22 Thread C K Kashyap
I've updated the parser here -
https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_3.hs

The whole thing is less than 100 lines and it can handle comments as well.

I have an outstanding question - What's the second parameter of the parse
function really for?

Regards,
Kashyap

On Thu, Jul 19, 2012 at 8:31 PM, C K Kashyap ckkash...@gmail.com wrote:

 Thank you so much ... I've updated my monad version here -


 https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_1.hshttps://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_2.hs


 and the Applicative version here -
 https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_2.hs


 The applicative version however does not seem to work.

 Is there a good tutorial that I can look up for Parsec - I am checking out
 http://legacy.cs.uu.nl/daan/download/parsec/parsec.html but  I am looking
 for a tutorial where a complex parser would be built ground up.

 Next I'd like to take care of escaped angular brackets.

 Regards,
 Kashyap


 On Thu, Jul 19, 2012 at 7:40 PM, Christian Maeder 
 christian.mae...@dfki.de wrote:

 Am 19.07.2012 15:41, schrieb Simon Hengel:

  On Thu, Jul 19, 2012 at 03:34:47PM +0200, Simon Hengel wrote:

  openTag :: Parser String
  openTag = char '' * many (noneOf ) * char ''


 if you disallow empty tags and / within tags, then you can avoid the
 notFollowedBy construct by:

openTag = try (char '' * many1 (noneOf /)) * char ''

 C.



  endTag :: String - Parser String
  endTag str = string / * string str * char ''


 Well yes, modified to what Christian Maeder just suggested.

 Cheers,
 Simon




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


Re: [Haskell-cafe] Need help with learning Parsec

2012-07-22 Thread C K Kashyap
What's the function to access it?

On Sun, Jul 22, 2012 at 9:16 PM, Simon Hengel s...@typeful.net wrote:

  I have an outstanding question - What's the second parameter of the
  parse function really for?

 It's used to refer to the source file on parse errors.

 Cheers,
 Simon

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


Re: [Haskell-cafe] Need help with learning Parsec

2012-07-22 Thread C K Kashyap
Thanks a lot Antonie and Simon.

Regards,
Kashyap
On Mon, Jul 23, 2012 at 12:15 AM, Antoine Latter aslat...@gmail.com wrote:

 On Sun, Jul 22, 2012 at 11:00 AM, C K Kashyap ckkash...@gmail.com wrote:
  What's the function to access it?
 

 The function 'runParser' returns either a result or a ParseError. You
 can extract the error position with the 'errorPos' function, and then
 you can extract the name of the file from the position with
 'sourceName'.

 The the 'Show' instance of ParseError does this.

 Antoine

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


[Haskell-cafe] Need help with learning Parsec

2012-07-19 Thread C K Kashyap
Dear gentle Haskellers,

I was trying to whet my Haskell by trying out Parsec today to try and parse
out XML. Here's the code I cam up with -

I wanted some help with the gettext parser that I've written. I had to do
a dummy char '  ') in there just to satisfy the many used in the xml
parser. I'd appreciate it very much if someone could give me some feedback.


data XML =  Node String [XML]
  | Body String deriving Show

gettext = do
 x - many (letter | digit )
 if (length x)  0 then
return (Body x)
 else (char ' '  (return $ Body ))

xml :: Parser XML
xml = do {
  name - openTag
; innerXML - many innerXML
; endTag name
; return (Node name innerXML)
 }

innerXML = do
 x - (try xml | gettext)
 return x

openTag :: Parser String
openTag = do
char ''
content - many (noneOf )
char ''
return content

endTag :: String - Parser String
endTag str = do
char ''
char '/'
string str
char ''
return str

h1 = parse xml  aA/a
h2 = parse xml  abA/b/a
h3 = parse xml  abc/c/b/a
h4 = parse xml  ab/bc/c/a

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


Re: [Haskell-cafe] Need help with learning Parsec

2012-07-19 Thread C K Kashyap
Thank you so much ... I've updated my monad version here -

https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_1.hshttps://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_2.hs


and the Applicative version here -
https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_2.hs


The applicative version however does not seem to work.

Is there a good tutorial that I can look up for Parsec - I am checking out
http://legacy.cs.uu.nl/daan/download/parsec/parsec.html but  I am looking
for a tutorial where a complex parser would be built ground up.

Next I'd like to take care of escaped angular brackets.

Regards,
Kashyap


On Thu, Jul 19, 2012 at 7:40 PM, Christian Maeder
christian.mae...@dfki.dewrote:

 Am 19.07.2012 15:41, schrieb Simon Hengel:

  On Thu, Jul 19, 2012 at 03:34:47PM +0200, Simon Hengel wrote:

  openTag :: Parser String
  openTag = char '' * many (noneOf ) * char ''


 if you disallow empty tags and / within tags, then you can avoid the
 notFollowedBy construct by:

openTag = try (char '' * many1 (noneOf /)) * char ''

 C.



  endTag :: String - Parser String
  endTag str = string / * string str * char ''


 Well yes, modified to what Christian Maeder just suggested.

 Cheers,
 Simon



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


[Haskell-cafe] Non-greedy match in Text.Regx.Posix

2012-07-17 Thread C K Kashyap
Hi all,

I was exploring Text.Regex.Posix and found that I was not able to do a
non-greedy match by modifying the quantifier with a ?. How can I achieve
non-greedy match in Text.Regex.Posix?

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


Re: [Haskell-cafe] Non-greedy match in Text.Regx.Posix

2012-07-17 Thread C K Kashyap
Thanks Roman,

I guess I better invest my time in Parsec then :)

Regards,
Kashyap

On Tue, Jul 17, 2012 at 5:05 PM, Roman Cheplyaka r...@ro-che.info wrote:

 * C K Kashyap ckkash...@gmail.com [2012-07-17 13:31:05+0530]
  I was exploring Text.Regex.Posix and found that I was not able to do a
  non-greedy match by modifying the quantifier with a ?. How can I
 achieve
  non-greedy match in Text.Regex.Posix?

 POSIX regular expressions semantics doesn't have a notion of a
 greedy/non-greedy match.
 Use an engine that implements Perl semantics if you need one.

 Refer to [1] for more detail.

 [1]:
 http://www.haskell.org/haskellwiki/Regular_expressions#.28apple.7Corange.29

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

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


[Haskell-cafe] Is haskell.org down?

2012-07-05 Thread C K Kashyap
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OpenShift a free PaaS from RedHat

2012-07-05 Thread C K Kashyap
Hi Folks,

I just found out about OpenShift - its a free PaaS from RedHat. It has some
interesting offerings. It does not support Haskell out of the box as of now.
Please do check it out and if you like it - vote for Haskell support on it
here - https://openshift.redhat.com/community/content/support-for-haskell

Meanwhile, I am trying to get complied Haskell executable to run on that
platform.

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


Re: [Haskell-cafe] Is haskell.org down?

2012-07-05 Thread C K Kashyap
Thanks!
Regards,
Kashyap

On Thu, Jul 5, 2012 at 4:20 PM, Ivan Lazar Miljenovic 
ivan.miljeno...@gmail.com wrote:

 Not anymore!

 On 5 July 2012 15:13, C K Kashyap ckkash...@gmail.com wrote:
  Regards,
  Kashyap
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 



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

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


Re: [Haskell-cafe] OpenShift a free PaaS from RedHat

2012-07-05 Thread C K Kashyap
Hey Shakti,
OpenShift gives access to Linux virtual machines on the cloud. However, we
do not have root access so we cannot install any new package.
I was trying to get my haskell code compiled into native on my local linux
box and taking it to those machines. That does not seem to work because of
two things -
1. GLIBC version mismatch
2. libgmp missing on the openshift box
Regards,
Kashyap

On Thu, Jul 5, 2012 at 9:19 PM, Shakthi Kannan shakthim...@gmail.comwrote:

 Hi,

 --- On Thu, Jul 5, 2012 at 8:41 PM, C K Kashyap ckkash...@gmail.com
 wrote:
 | I just found out about OpenShift - its a free PaaS from RedHat. It has
 some
 | interesting offerings. It does not support Haskell out of the box as of
 now.
 | Please do check it out and if you like it - vote for Haskell support on
 it
 | here -
 https://openshift.redhat.com/community/content/support-for-haskell
 |
 | Meanwhile, I am trying to get complied Haskell executable to run on that
 | platform.
 \--

 We already have a Fedora Haskell SIG [1] where we are working on
 shipping Haskell packages in Fedora. Recently, support for EL-6 was
 added, and one can get Haskell packages through the EPEL [2]
 repository.

 Please feel free to ping us on #fedora-haskell on irc.freenode.net.

 SK

 [1] Fedora Haskell SIG. http://fedoraproject.org/wiki/Haskell_SIG

 [2] Extra Packages for Enterprise Linux (EPEL).
 http://fedoraproject.org/wiki/EPEL

 --
 Shakthi Kannan
 http://www.shakthimaan.com

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


Re: [Haskell-cafe] OpenShift a free PaaS from RedHat

2012-07-05 Thread C K Kashyap
Thank you Micheal and Satvik. I think cde should solve the problem - I'll
confirm later - for some reason, I do not have SSH connectivity from my
office.

What'll be best though is - yesod on OpenShift :)

Regards,
Kashyap

On Fri, Jul 6, 2012 at 10:51 AM, satvik chauhan mystic.sat...@gmail.comwrote:


 OpenShift gives access to Linux virtual machines on the cloud. However,
 we do not have root access so we cannot install any new package.
 I was trying to get my haskell code compiled into native on my local
 linux box and taking it to those machines. That does not seem to work
 because of two things -
 1. GLIBC version mismatch
 2. libgmp missing on the openshift box
 Regards,
 Kashyap


 I think you might want to check out CDE.
 http://www.pgbovine.net/cde.html

 This will take care of the version mismatch of the libraries.

 - Satvik

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


[Haskell-cafe] An attempt at an EDSL for platform independent 3D animation

2012-06-03 Thread C K Kashyap
Hi All,

I've written a Haskell program that allows you to describe dance
movements and it spits out javascript that does animation on an HTML 5
canvas (that's the platform independent bit).

https://github.com/ckkashyap/Dancer

Please do check it out and let me know what you think - all you'd need is
Haskell platform. It's really preliminary at this point - The only
animation that I've built using it is walk - this makes a matchstick man
walk (you have to stretch your imagination a bit).

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


Re: [Haskell-cafe] Need inputs for a Haskell awareness presentation

2012-06-02 Thread C K Kashyap
Thank you all very much,

I am sitting now and collating all your responses. I'll revert with
questions if I may have.

Indeed, it may be better to have this kind of collateral ready for future
use.

I am going to put my stuff on github  considering markdown + pandoc.

Regards,
Kashyap

On Sat, Jun 2, 2012 at 3:06 AM, Claus Reinke claus.rei...@talk21.comwrote:

 I have the opportunity to make a presentation to folks (developers and
 managers) in my organization about Haskell - and why it's important - and
 why it's the only way forward.


 Haskell is important, but not the only way forward. Also, there have been
 other great languages, with limited impact - incorporating great ideas is
 no guarantee for takeup. If you want to be convincing, you need to be
 honest.


  1. Any thoughts around the outline of the presentation - target audience
 being seasoned imperative programmers who love and live at the pinnacle of
 object oriented bliss.


 If you approach this from the Haskell side (what is Haskell good at),
 you might get some people curious, but you won't connect their interest
 to their daily work. You don't want to give them a show, you want to
 inspire them to want to try coding in that language.

 If you really want to understand what is good about Haskell, stop using
 it for a while, and work in something like Javascript (or whatever your
 audience is comfortable with, but for me Javascript was an eye opener).

 You won't believe how basic the issues are that conventional coders
 are struggling with until you realize that you do not have them in Haskell.

 If you have felt that pain, have understood that you can't make those
 issues go away by saying that wouldn't be an issue in Haskell, then
 you can understand that their struggles and issues are real.

 If you respect that, you can take one of their problems/source bases,
 and translate it to Haskell. That step tells them (and you!) that Haskell
 is adequate for their problem domains (which won't always be the
 case - no point showing them a wonderful language that they won't
 be able to apply).

 The next step is to go through some of those pain points in that code
 and show how to get rid of them in the Haskell version. Instead of
 presenting ready-made solutions, show them how to work with code
 they understand, much more confidently than they would be used to.

 Go slowly, and focus on their daily pain points (which they probably
 have stopped feeling because they can't do anything against them).
 Explain why you are confident in your modifications, compare against
 the obstacles that their current language would throw up against such
 modifications. Some examples:

 - types can replace basic documentation and documentation lookup

 - no need to test things that the type system can check, not in test suites
   and not in the prelude of every function definition; you still need
 tests,
   but those can focus on interesting aspects; you don't need to run 10
   minutes of tests to verify that a refactoring in a large code base hasn't
   broken scoping by misspelling a variable name, or that function calls
   have the proper number and type of parameters

 - thanks to decades of development, Haskell's static type system does
   not (usually) prevent you from writing the code you mean (this is
   where the proof comes in - you've rewritten their code in Haskell),
   nor does it clutter the code with type annotations; types of functions
   can be inferred and checked, unlike missing or outdated documentation;

   (careful here: language weaknesses are often compensated for through
   extensive tool usage; some IDEs may check type annotations within
   comments, or try to cover other gaps in dynamic languages)

 - part of the trick is to work with the type system instead of against it:
   document intentions in code, not comments

 - separation of expressions and statements

 - instead of every expression being a statement (side effects everywhere),
   every statement is an expression (functional abstraction works
   everywhere)

 - since functional abstraction works everywhere, once you see repeated
   code, you know you can factor it out

 - you can build libraries of useful abstractions

 - building abstraction libraries in the language is so easy that you
   can build domain-specific abstraction libraries

 - domain-specific abstraction libraries become embedded DSLs;
   no need to write parsers, no risk to useful program properties
   from overuse of introspection

 - ..

 I better stop here - I hope you can see the direction:-)

 Many of these do not even touch on the advanced language features,
 but all of them rely on the simplicity and careful design of the core
 language. All of these advantages carry over to concurrent and
 parallel programming, without having to switch to another language.

 Also, both functions and threads are so cheap (and controllable in
 terms of side-effects) that you do not have to break your head to
 avoid 

[Haskell-cafe] Need inputs for a Haskell awareness presentation

2012-05-31 Thread C K Kashyap
Hi folks,

I have the opportunity to make a presentation to folks (developers and
managers) in my organization about Haskell - and why it's important - and
why it's the only way forward. I request you to share your
experiences/suggestions for the following -
1. Any thoughts around the outline of the presentation - target audience
being seasoned imperative programmers who love and live at the pinnacle of
 object oriented bliss.
2. Handling questions/comments like these in witty/interesting ways -
a) It looks good and mathematical but practically, what can we do with
it, all our stuff is in C++
b) Wow, what do you mean you cannot reason about its space complexity?
c) Where's my inheritance?
d) Debugging looks like a nightmare - we cannot even put a print in the
function?
e) Static types - in this day and age - come on - productivity in X is
so much more - and that's because they got rid of type mess.
f)  Is there anything serious/large written in it? [GHC will not
qualify as a good answer I feel]
g) Oh FP, as in Lisp, oh, that's AI stuff right ... we don't really do
AI.
h) Any other questions/comments that you may have heard.
3. Ideas about interesting problems that can be used so that it appeals to
people. I mean, while fibonacci etc look good but showing those examples
tend to send the signal that it's good for those kind of problems.
4. Is talking about or referring to Lambda calculus a good idea - I mean,
showing that using its ultra simple constructs one could build up things
like if/then etc

I'm gonna do my bit to wear the limestone!!!

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


[Haskell-cafe] Need feedback on my EDSL attempt for writing test scripts

2012-04-23 Thread C K Kashyap
Dear cafe,
Recently, I decided to use Haskell to drive the testing of a C++ DLL that
we develop. After getting the FFI etc working, I thought it might be a good
idea to expose an EDSL for the testers to alter the flow of invocations of
the functions in the DLL. I've tried to demonstrate the approach I am
contemplating here - http://hpaste.org/67495

The outcome is that I'll have a set of Instructions for the testers can
arrange to create a sequence of calls.

 data Command = Void | Init | Get3Numbers Int Int Int| GetName String |
PrintName | PrintSum | Close | PrintMessage String
 deriving (Show)

 mainloop :: StateT (ScriptState Command) IO ()
 mainloop = do
 liftIO $ putStrLn Hello World
 executeCommand Init
 executeCommand Init
 executeCommand $ PrintMessage Enter name
 executeCommand $ GetName abcd
 return ()


I'd like to ensure that some level of validation done. For example, if Init
is called twice, the tester should get to know about it. Similarly, GeName
should not be called unless PrintMessage has been called.

 executeCommand :: Command - StateT (ScriptState Command) IO ()
 executeCommand Init = do
(ScriptState c) - get
case c of
 Void - liftIO $ putStrLn (show c)
 _- liftIO $ putStrLn Init already called
put (ScriptState Init)
return ()
 executeCommand (GetName x) = do
(ScriptState c) - get
case c of
 PrintMessage _ - do { str - liftIO $ getLine; put
(ScriptState (GetName str)); return ()}
 _  - liftIO $ putStrLn PrintMessage not
called
 executeCommand (PrintMessage m) = do
liftIO $ putStrLn m
put (ScriptState (PrintMessage m))


I'd appreciate it very much if you could give me some feedback on my
approach. I get this feeling that I am wrapping up the whole program inside
a State monad - does this mean that I am giving up the functional goodies.

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


Re: [Haskell-cafe] An idea to document inter department dependencies in Haskell

2012-03-14 Thread C K Kashyap
Thanks a lot Alberto,

Actual code generation is not really my immediate goal ... What my
immediate requirement is to validate the consistency of design changes. So
essentially, this EDSL would not generate any target code - it's successful
compilation would be the desired result and perhaps more friendly
compilation error messages that can guide the non Haskell user to make
corrections.

Regards,
Kashyap


On Wed, Mar 14, 2012 at 5:31 AM, Alberto G. Corona agocor...@gmail.comwrote:

 Hi,

 Just thinking aloud :

 A way  to start is to define concrete workflows for concrete events. What
 It is necessary to do if. This may make things more explicit and to
 clarify the problems. .Later, .maybe. these concrete workflows can be
 abstracted away from procedural/imperative to declarative and from concrete
 events to categories of events and tasks..

 The declarative abstract description  then could create concrete
 workflows. The best way to express the abstract description, and the way to
 transform the description in a concrete set of instructions depend on what
 is needed  (The workflows produced can be just informative, in the form of
 a textual description of activities).

 Thus, the power users should  handle the abstract descriptions, and the
 ordinary users could run the engine, perhaps they should answer some
 questions to obtain the concrete workflows for their intended tasks

 Not very informative, but better than nothing ;)

 Alberto

 2012/3/13 C K Kashyap ckkash...@gmail.com

 My dear Haskell folks,

 I work in a software company where I develop components that go into a
 really complex system that's built of several components developed by
 different teams that are geographically distributed. The components
 themselves run in a distributed manner across client and several servers.
 All our design documents are in wiki's (fashionably so). As a result of the
 above situation and the fact that our code base is not in Haskell, we are
 almost always dealing with Oh I did not know this would effect that and
 Oh I have no clue what all this change will impact.

 I've been wondering if it would be a good idea to try and create a spec
 for the system in Haskell, such that would could get a better handle on the
 dependencies. Perhaps an EDSL, that would allow Product Managers to
 introduce new requirements - compilation failures would indicate the areas
 that would need to be touched. How is it different from having a spec in a
 diagram - well, in that case, we are requiring humans to look at the
 diagram to detect dependencies instead of the compiler telling me about the
 dependencies. I am about to start off with some implementation to capture
 my idea - I can articulate it better then. However, I just wanted to throw
 it out there to check if anyone's had some thought in this direction or if
 there is some prior art here.

 Regards,
 Kashyap


 ___
 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] An idea to document inter department dependencies in Haskell

2012-03-13 Thread C K Kashyap
My dear Haskell folks,

I work in a software company where I develop components that go into a
really complex system that's built of several components developed by
different teams that are geographically distributed. The components
themselves run in a distributed manner across client and several servers.
All our design documents are in wiki's (fashionably so). As a result of the
above situation and the fact that our code base is not in Haskell, we are
almost always dealing with Oh I did not know this would effect that and
Oh I have no clue what all this change will impact.

I've been wondering if it would be a good idea to try and create a spec for
the system in Haskell, such that would could get a better handle on the
dependencies. Perhaps an EDSL, that would allow Product Managers to
introduce new requirements - compilation failures would indicate the areas
that would need to be touched. How is it different from having a spec in a
diagram - well, in that case, we are requiring humans to look at the
diagram to detect dependencies instead of the compiler telling me about the
dependencies. I am about to start off with some implementation to capture
my idea - I can articulate it better then. However, I just wanted to throw
it out there to check if anyone's had some thought in this direction or if
there is some prior art here.

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


Re: [Haskell-cafe] [haskell-cafe] Question about 64bit target on Windows platform

2012-03-05 Thread C K Kashyap
Thank you Jason.

On Mon, Mar 5, 2012 at 1:05 PM, Jason Dagit dag...@gmail.com wrote:

 I don't know if timeline has been established, but my understanding is
 that there is a need for this and that the right people are aware of
 it and looking into it.

 The GHC trac has a ticket for this:
 http://hackage.haskell.org/trac/ghc/ticket/1884

 On Sun, Mar 4, 2012 at 9:59 PM, C K Kashyap ckkash...@gmail.com wrote:
  Hi All,
  Can someone please let me know if there is a 64bit target on Windows on
 the
  horizon for GHC?
  I am trying to push for changing the current implementation in my
  organization in C++ to Haskell - Our primary targets are Windows and Mac.
  Not being able to generate 64bit DLL's on Windows would be a big
 bottleneck.
  Regards,
  Kashyap
 
  ___
  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] [haskell-cafe] Question about 64bit target on Windows platform

2012-03-05 Thread C K Kashyap
On Mon, Mar 5, 2012 at 2:54 PM, Simon Marlow marlo...@gmail.com wrote:

 There is a possibility that the IHG might fund this during the next cycle,
 which would mean that it would be in 7.6.1.

 Cheers,
Simon


That is very good to hear!!!

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


[Haskell-cafe] [haskell-cafe] Question about 64bit target on Windows platform

2012-03-04 Thread C K Kashyap
Hi All,
Can someone please let me know if there is a 64bit target on Windows on the
horizon for GHC?
I am trying to push for changing the current implementation in my
organization in C++ to Haskell - Our primary targets are Windows and Mac.
Not being able to generate 64bit DLL's on Windows would be a big bottleneck.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need advice: Haskell in Web Client

2012-01-17 Thread C K Kashyap
On Tue, Jan 17, 2012 at 4:19 PM, dokondr doko...@gmail.com wrote:

 Hi all,
 I hope to use Haskell for graphics (charts) programming in Web client.

 My current implementation in brief:
 Server side, Haskell modules:
 1) collecting various statistics from Twitter
 2) generating text data for Gnuplot (http://www.gnuplot.info/)
 3) Gnuplot creates png files with charts

 Web client:
 GWT (Google Web Toolkit) web UI that allows user to enter queries and see
 resulting charts  in Web browser. Charts are png files generated by Gnuplot
 on the server side.

 Ideally, on the server side  instead of using Gnuplot I would like Haskell
 to generate Javascript to be downloaded to Web client and draw charts in
 the browser. Something, very approximately, similar to what GWT does :)
 This code will be specific of course to plotting Javascript framework, no
 problem.
 Looking at Haskell in web browser - HaskellWiki:

 http://www.haskell.org/haskellwiki/Haskell_in_web_browser#Haskell_web_toolkit
 I feel a little confused about current state of the available Haskell
 tools for this task.
 Any ideas?

 Hi Dimitri,
Perhaps HTML5's canvas element would meet your requirement. There a few JS
chart implementation for HTML5 floating on the internet.
Regards,
Kashap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] DB vs read/show for persisting large data

2011-12-16 Thread C K Kashyap
Thank you so much .. I am going to try out acid-state. I've been shying
away from template-haskell ... but from the looks of it,
acid-state/safecopy can do what I am looking for.
Regards,
Kashyap

On Thu, Dec 15, 2011 at 12:13 AM, Bas van Dijk v.dijk@gmail.com wrote:

 On 14 December 2011 15:22, Claude Heiland-Allen cla...@goto10.org wrote:
  I ran into this very nightmare in one project, and was recommend safecopy
  [0] by someone on the #haskell IRC channel.  I've not (yet) used it but
 it
  looks very nice!
 
  [0] http://hackage.haskell.org/package/safecopy

 Or better yet, use acid-state which is build on top of safecopy:

 http://acid-state.seize.it/

 Bas

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


[Haskell-cafe] DB vs read/show for persisting large data

2011-12-14 Thread C K Kashyap
Hi,

It has been on my todo list for some time now. I'd like to write a GTD tool
that has dependency tracking support. Haskell seems like a good choice for
this. I was wondering if there has been any past attempts with this?

One thing that has been bothering me has been this - the persistence of
data. Should I use sqlite(or someother DB) or should I use Haskell's
read/show functions to read from and write to a file? I am slightly not
inclined towards NOT using DB because I want to implement all the business
logic in Haskell. I want to avoid having to generate SQL.

It'll be great if I could get some feedback on the read/show approach -
is this even a viable option?

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


[Haskell-cafe] why the name lambda calculus?

2011-08-21 Thread C K Kashyap
Hi,
Can someone please tell me what is the root of the name lambda calculus? Is
it just because of the symbol lambda that is used?
Why not alpha or beta calculus?
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Embedding Perl RegEx in Haskell

2011-08-20 Thread C K Kashyap


 Why not just go with anchorHead and anchorTail or similar?  And a capture
 could simply be


Thanks for your inputs Brandon. I've updated the code with anchors. Still
trying to get a hold of captures.

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


[Haskell-cafe] Building ? using kleene closure {not haskell specific}

2011-08-12 Thread C K Kashyap
Hello gentle Haskell folks,

I happened to read Beautiful code's chapter 1 today and found Brian
Kerninghan's regex implementation. In it he only shows the * meta character.
I can easily understand how + can be built but am having trouble with
building ? (zero or one). I'd really appreciate it if some one could help me
understand it.

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


Re: [Haskell-cafe] Building ? using kleene closure {not haskell specific}

2011-08-12 Thread C K Kashyap
On Fri, Aug 12, 2011 at 4:34 PM, Sebastian Fischer fisc...@nii.ac.jpwrote:

  I can easily understand how + can be built but am having trouble with
  building ? (zero or one).

 If there is a regular expression e for the empty word, one can define ? as

a? = e | a

 If there is a regular expression o that never matches one can define e as

e = o*

 If there are character classes one can define o as

o = []

 Apart from that, I have no idea..

 Sebastian


Thanks Sebastian ... this is what I was asking for. I'll try and digest it.

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


Re: [Haskell-cafe] Generating simple histograms in png format?

2011-06-12 Thread C K Kashyap
You might find this useful - http://www.haskell.org/haskellwiki/Library/PNG
Btw, I too am looking for such a library.
Regards,
Kashyap

On Sat, Jun 11, 2011 at 3:32 AM, Dmitri O.Kondratiev doko...@gmail.comwrote:

 I am looking for platform-independent library to generate simple histograms
 in png format.
 Does such thing exist?

 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] Modeling the performance of a non-trivial software app

2011-05-10 Thread C K Kashyap
Hi,
I was wondering if it would be a good idea to model a software app's
performance using Haskell. The idea is a little abstract in my mind right
now. I'll try and illustrate it with an example - Let's say, I want to model
a web app - to, model it, I could think of the following entities -

1. One or more clients and as many connections (essentially bandwidth of
each connection)
2. A Load balancer ( and bandwidths to the webservers)
3. Bunch of webservers (and bandwidths to the database server)
4. A database server

Using the model, I could generate performance characteristics and figure out
if database is the bottleneck or not ... if so, what level of  sharding
would be useful etc

Is there already a wheel I am trying to re-invent? Has anyone attempted
this?

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


Re: [Haskell-cafe] Modeling the performance of a non-trivial software app

2011-05-10 Thread C K Kashyap

 Sometimes it is possible to write the corresponded model. Then the model
 can be simulated to receive the performance characteristics. Much depends on
 that how precise the model is. The keywords are Discrete Event Simulation
 (DES) and Theory of Queue. It may require some maths.

 I wrote a small library called Aivika[1]. Perhaps it might be helpful.

 David

 [1]http://hackage.haskell.org/package/aivika

  Thanks David,
I'll check out DES and Aivika.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Another good video tutorial on monads

2011-05-04 Thread C K Kashyap
http://vimeo.com/20717301
I really liked how he starts off with the let statement.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Looking for feedback on my attempt at a tree construction edsl

2011-03-23 Thread C K Kashyap

 A shallow embedding would typically use just functions - a famous
 example is Paul Hudak's region server. A deep embedding would build
 syntax - represented with data types - and interpret the syntax or
 compile the syntax for another use (so called off-shoring e.g. Conal
 Elliott's Pan).


I am not able to ascertain  if what you are saying is consistent with
http://www.haskell.org/haskellwiki/Embedded_domain_specific_language

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


[Haskell-cafe] Looking for feedback on my attempt at a tree construction edsl

2011-03-22 Thread C K Kashyap
Hi,
With my edsl, one can describe a tree like this -

import TreeEdsl
import Data.Tree

createTree :: TreeContext String ()
createTree = do
insertSubTree Fruits $ do
insertLeaf Apple
insertLeaf Mango
insertSubTree Arbitrary $ do
insertSubTree Numbers $ do
insertLeaf 1
insertLeaf 2
insertLeaf 3
insertSubTree Letters $ do
insertLeaf A
insertLeaf B
insertLeaf C
return ()
main = do
tree - process root createTree
putStrLn (drawTree (fmap show tree))
return ()


and get a tree like this -

root
|
+- Arbitrary
|  |
|  +- Letters
|  |  |
|  |  +- C
|  |  |
|  |  +- B
|  |  |
|  |  `- A
|  |
|  `- Numbers
| |
| +- 3
| |
| +- 2
| |
| `- 1
|
`- Fruits
   |
   +- Mango
   |
   `- Apple


My code is here
https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeEdsl.hs

I'd appreciate your feedback on this. Does this qualify to be a edsl?

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


Re: [Haskell-cafe] Looking for feedback on my attempt at a tree construction edsl

2011-03-22 Thread C K Kashyap
Hi,
I've tried a non-monadic version based on the suggestions here -
https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeWithoutMonad.hs
This implementation seems to lack the indentation based approach that the
do syntax allows.

Would I be right if I said that the non-monadic version is shallow
embedding and the monadic approach is deep embedding? Can we do deep
embedding without using monads?

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


Re: [Haskell-cafe] Data.Time.Calendar.Day does not seem to have an instance for Read

2011-03-17 Thread C K Kashyap

 On Thu, Mar 17, 2011 at 12:30 AM, C K Kashyap ckkash...@gmail.com wrote:
  Hi,
  I was wondering if this is a defect -
  Prelude import Data.Time.Calendar
  Prelude Data.Time.Calendar read 2011-10-10 :: Day
  interactive:1:1:
  No instance for (Read Day)
arising from a use of `read'
  Possible fix: add an instance declaration for (Read Day)
  In the expression: read 2011-10-10 :: Day
  In an equation for `it': it = read 2011-10-10 :: Day
  Prelude Data.Time.Calendar
 

 I see the same problem with GHC 7.0.2, time-1.2.0.3.

 Does it work if you use it in a Haskell source file, instead of GHCi?

 Thanks,
 Antoine


Nope, even compiling with ghc causes the error.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Time.Calendar.Day does not seem to have an instance for Read

2011-03-17 Thread C K Kashyap


 So then it's not a bug. The instance is defined in
 Data.Time.Format.Parse, and Data.Time.Calendar doesn't import that
 module.

 This, however is a bug, I think:

 Prelude import Data.Time
 Prelude Data.Time read 2011-10-10 :: Day

 ... no instance for (Read Day) ...

 Prelude :m +Data.Time
 Prelude Data.Time read 2011-10-10 :: Day
 2011-10-10


 Erik


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


[Haskell-cafe] Data.Time.Calendar.Day does not seem to have an instance for Read

2011-03-16 Thread C K Kashyap
Hi,
I was wondering if this is a defect -

Prelude import Data.Time.Calendar
Prelude Data.Time.Calendar read 2011-10-10 :: Day

interactive:1:1:
No instance for (Read Day)
  arising from a use of `read'
Possible fix: add an instance declaration for (Read Day)
In the expression: read 2011-10-10 :: Day
In an equation for `it': it = read 2011-10-10 :: Day
Prelude Data.Time.Calendar


The documentation says that  Day has an instance for Read.

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


Re: [Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-03-16 Thread C K Kashyap
I had started exploring the internal - PS constructor route looking at the
base64 encoding implementation by Bryan (which is really fast -
http://www.serpentine.com/blog/2010/09/02/fast-base64-encoding-and-decoding-in-haskell/)-
I was wondering if we don't use the PS constructor can we implement
base64 encoding that's comparable? I mean, can we create an asymptotically
similar implementation?

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


Re: [Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-03-13 Thread C K Kashyap
Thanks Brandon,

data Endian = Big | Little
data Size = Eight | Sixteen | ThirtyTwo | SixtyFour
type EncTuple = (Int,Size,Endian)

My requirement is to write encode :: [EncTuple] - ByteString
I'd like to use it with just the libraries that are part of the platform -
and I am not a fan of using the internal stuff :)
I'd appreciate it very much if you could give me a sample.

And thank you very much for
http://research.microsoft.com/en-us/um/people/simonpj/papers/unboxed-values.ps.Z

Regards,
Kashyap





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


Re: [Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-03-13 Thread C K Kashyap

 Looks like a job for Data.Binary.

  I'd like to use it with just the libraries that are part of the platform


I forgot to mention, Data.Binary does not seem to be in the platform.

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


Re: [Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-03-11 Thread C K Kashyap
Hi Don,
What would be a good way to figure out the usage of ByteString -
particularly the PS constructor.
Regards,
Kashyap

On Fri, Feb 11, 2011 at 10:01 AM, C K Kashyap ckkash...@gmail.com wrote:


 Yep, the 'Internal' module is where the type is defined, and then
 re-exported through the regular module.

 Thanks Don ... good to know.
 Regards,
 Kashyap

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


[Haskell-cafe] Getting started with http-enumerator

2011-03-04 Thread C K Kashyap
Hi,
I'd like to use http-enumerator for things that I've been using perl/Lwp
for. I tried looking but was not able to find good documentation for it.
Could someone please point me to simple examples?
Like posting a form, dealing with cookies etc.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Performance difference between ghc and ghci

2011-02-22 Thread C K Kashyap



 GHCi doesn't perform any optimizations, so whenever you're running
 interpreted bytecode there's a significant performance hit. However, if you
 compile the code, you can run the compiled/optimized version from GHCi as
 well.

 --


I missed out the optimization bit  yes, that would make a difference.
However beyond that is it not just about graph reduction which should be the
same?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Performance difference between ghc and ghci

2011-02-21 Thread C K Kashyap
Hi,
Is there a runtime performance difference between a haskell program running
under GHCI vs in its compiled form?
Especially for a long running program - as in, ignoring the initial setup
time.
If I understand right, in both case tree reduction is what is happening and
performance should be similar.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unable to get parallelism using `par`

2011-02-18 Thread C K Kashyap


 Hmm, using parSumFibEuler instead of sumFibEuler, I get  100% CPU usage
 (close to 200% if I adjust parameters so both computations take
 approximately the same time).
 Works for me, then.


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


[Haskell-cafe] Unable to get parallelism using `par`

2011-02-17 Thread C K Kashyap
Hi,
I tried the first example from A tutorial on Parallel and Concurrent
programming in Haskell but I cant seem to get sparks to get converted to OS
threads.

Below is the program I am using.
I did ghc --make -threaded program.hs
then
./program +RTS -N2
I don't see any speed gain compared to N1.
Am I missing something?


import System.Time
import Control.Parallel

fib :: Int - Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)


mkList :: Int - [Int]
mkList n = [1..n-1]

relPrime :: Int - Int - Bool
relPrime x y = gcd x y == 1

euler :: Int - Int
euler n = length (filter (relPrime n) (mkList n))

sumEuler :: Int - Int
sumEuler = sum . (map euler) . mkList

sumFibEuler :: Int - Int - Int
sumFibEuler a b = fib a + sumEuler b


parSumFibEuler :: Int - Int - Int
parSumFibEuler a b
= f `par`  (e `pseq` (e + f))
where
f = fib a
e = sumEuler b

secDiff :: ClockTime - ClockTime - Float
secDiff (TOD secs1 psecs1) (TOD secs2 psecs2)
 = fromInteger (psecs2 - psecs1) / 1e12 + fromInteger (secs2 - secs1)

r1 :: Int
r1 = sumFibEuler 38 5300

main :: IO ()
main = do
t0 - getClockTime
pseq r1 (return())
t1 - getClockTime
putStrLn (Sum:  ++ show r1)
putStrLn (time:  ++ show (secDiff t0 t1) ++  seconds)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Review request for platform independent interactive graphics with VNC

2011-02-16 Thread C K Kashyap
Hi,
I've refined this further ... earlier, each framebuffer update involved
sending the whole screen back, now, only the incremental changes are sent.
Drawing on very large images are quick now!!

Real fun will be when I can do rendering of graphics by typing things at the
ghci prompt!!!


https://github.com/ckkashyap/Chitra

Feedback welcome!!!

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


Re: [Haskell-cafe] Proving correctness

2011-02-12 Thread C K Kashyap

 many of the subtleties encountered in the process.  I am often 100%
 sure of the correctness of my refactors.


While I have an intuitive understanding of what you mean about the
correctness of refactoring ... I personally feel much more comfortable
refactoring Haskell code ... as in - as long as I apease the compiler,
things work correctly!!!
This is certainly not true in case of imperative languages ... In all my
work experience, I've always found folks and myself very very uncomfortable
making changes to existing code ... which in my opinion contributes to
software bloat!

Anyway, how can one go about explaining to an imperative programmer with no
FP exposure - what aspect of Haskell makes it easy to refactor?

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


[Haskell-cafe] Proving correctness

2011-02-11 Thread C K Kashyap
Hi Folks,

I've come across this a few times - In Haskell, once can prove the
correctness of the code - Is this true?

I know that static typing and strong typing of Haskell eliminate a whole
class of problems - is that related to the proving correctness?
Is it about Quickcheck - if so, how is it different from having test sutites
in projects using mainstream languages?


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


[Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-02-10 Thread C K Kashyap
Hi,
I noticed that even though I declare the type of a function in my code as
Data.ByteString.Lazy.ByteString ... when I check it out in ghci using :t, it
shows this - Data.ByteString.Lazy.Internal.ByteString
Is this expected?
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString

2011-02-10 Thread C K Kashyap


 Yep, the 'Internal' module is where the type is defined, and then
 re-exported through the regular module.

 Thanks Don ... good to know.
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap
Hi,
I need to convert IOArray to bytestring as shown below -

import Data.Array.IO
import Data.Binary.Put
import qualified Data.ByteString.Lazy as BS
import Data.Word

main = do
arr - newArray (0,9) 0 :: IO (IOArray Int Int)
let bs=toByteString arr
return ()

How can I implement the 'toByteString' function?

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


Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap
On Tue, Feb 8, 2011 at 2:26 PM, Michael Snoyman mich...@snoyman.com wrote:

 Your array contains machine-sized Ints, which in practice are likely
 either 32-bit or 64-bit, while a ByteString is the equivalent of an
 array or 8-bit values. So you'll need to somehow convert the Ints to
 Word8s. Do you know if you need big or little endian?

 A basic approach would be:

 * Use freeze to convert your IOArray into an IArray
 * Use putIArrayOf and put (from cereal) to generate a Putter value
 * Use runPut to generate a ByteString from that


Thanks Michael,
Actually, I need an array of 8-bit words - Is that available?

Also, would be hard to do it without cereal?

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


Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap


 1) Just use Data.Word.Word8 instead of the second Int in your type sig
 for IOArray
 2) Use getElems to get a [Word8]
 3) Data.ByteString.pack converts a [Word8] into a ByteString

 Michael


I am currently using a list of tuples - [(Int,Int,Int)] to represent an
image buffer. You can see it in the getImageByteString
function at https://github.com/ckkashyap/Chitra/blob/master/RFB/Encoding.hs
Looks like this is pretty slow, and hence I am exploring Arrays.

I wonder if working with [Word8] will also suffer from performance hit?

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


Re: [Haskell-cafe] forkIO on GHCI does not seem to spawn the thread in the background on some OSs

2011-02-08 Thread C K Kashyap


 I can't reproduce this. What are you using as the action?

 I've tried bottoms, and tight loops whose Core contains no allocations, and
 not
 managed to lock up the prompt, or seen ghci using more threads than I have
 cores.

 One thing that may give the appearance of locking up the prompt is if
 the thread starts reading from the terminal and your commands no longer
 make it
 to the interpreter.

  It is  not always a thread.  ForkIO creates a spark and then the
  scheduler  decides when sparks should be scheduled to threads.  Thus
  you get a  guarantee of concurrent but not parallel execution.

 That is not correct - it is par that creates sparks may be discarded.

 forkIO always creates new threads, though it is of course up to the
 scheduler
 when the threads are executed, and how many cores are used.

  Are you running with  threads enabled?

 That is, was your ghci compiled with -threaded? This mostly
 depends on the version. what version of ghc are you running, and how did
 you
 install it?




 Sorry ... extremely sorry ... my bad ... for some reason, I was omitting
the call to forkIO :( when I was trying on other platforms.

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


[Haskell-cafe] Split function

2011-02-08 Thread C K Kashyap
Hi,

Is this a good implementation of split function? ... I was wondering about
the lines function, it basically a special case of split right?

split c xs = foldr f [[]] xs
where
f x list@(l:ls)= if x == c then []:list else (x:l):ls


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


Re: [Haskell-cafe] Extending GHCi

2011-02-07 Thread C K Kashyap


 $ ghci
 GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 Loading package ffi-1.0 ... linking ... done.
 Prelude :m +Data.IORef Control.Concurrent Control.Monad
 Prelude Data.IORef Control.Concurrent Control.Monad msg - newIORef
 Hello
 Prelude Data.IORef Control.Concurrent Control.Monad let echo =
 forever $ readIORef msg = putStrLn  threadDelay 300
 Prelude Data.IORef Control.Concurrent Control.Monad t - forkIO echo
 Hello
 Prelude Data.IORef Control.Concurrent Control.Monad Hello
 Hello
 writeIORefHello msg World
 Prelude Data.IORef Control.Concurrent Control.Monad World
 World


On my mac, this works..but on Linux, the moment I do t - forkIO ... , it
starts off a thread in the foreground and does not return to the prompt.

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


[Haskell-cafe] forkIO on GHCI does not seem to spawn the thread in the background on some OSs

2011-02-07 Thread C K Kashyap
Hi,
I found that on windows and my ubuntu box, when I did this

ghci t - forkIO someAction

someAction started executing in the foreground - as in, the ghci prompt
did not come back (until I pressed Ctrl-C)

On my mac however, when I ran the same thing, the action started executing
in the background and ghci prompt returned instantaneously.
How can I get the thread backgrounded explicitly?

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


Re: [Haskell-cafe] Extending GHCi

2011-02-06 Thread C K Kashyap


 $ ghci
 GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 Loading package ffi-1.0 ... linking ... done.
 Prelude :m +Data.IORef Control.Concurrent Control.Monad
 Prelude Data.IORef Control.Concurrent Control.Monad msg - newIORef
 Hello
 Prelude Data.IORef Control.Concurrent Control.Monad let echo =
 forever $ readIORef msg = putStrLn  threadDelay 300
 Prelude Data.IORef Control.Concurrent Control.Monad t - forkIO echo
 Hello
 Prelude Data.IORef Control.Concurrent Control.Monad Hello
 Hello
 writeIORefHello msg World
 Prelude Data.IORef Control.Concurrent Control.Monad World
 World


Thanks ... this is the possibility I was looking for. Btw, I am thinking I'd
need to use STM to synchronize right?
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Extending GHCi

2011-02-06 Thread C K Kashyap



 What part of that doesn't already work? You can forkIO threads in GHCi,
 you can listen on the network. If you have written the server so it can be
 controlled from another thread, you can run those controlling functions
 at the prompt while the server is working.


 Thanks Brandon  .. I was looking for a confirmation.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Review request for platform independent interactive graphics with VNC

2011-02-06 Thread C K Kashyap

 After pulling in your changes and recompilation, your application runs
 as expected. Thanks a lot!


I look forward to some feedback on this.

Also, I am thinking in the lines of changing the image representation in a
list  to a mutable array - would that be the right approach?

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


  1   2   3   >