Re: [Haskell-cafe] World's First Commercial Haskell IDE and Deployment Platform, FP Haskell Center Launches Today

2013-09-03 Thread Mathijs Kwik
You can always try the attached docx! :)

On Tue, Sep 3, 2013 at 9:25 PM, Tommy Thorn tt1...@yahoo.com wrote:
 This is interesting and I wish them luck, but it seems surprising
 that the below link doesn't have as much as a screenshot (for an IDE,
 you kind of expect to see what it looks like).

 After much browsing around on their website I finally found the Video Demo:
 https://www.fpcomplete.com/business/haskell-center/video-walk-through/
 but the there's no video for me on Firefox (Mac OS X). In Safari shows, but
 when I try to play it, it reports An error occurred, please try again later.

 Tommy




 On Sep 3, 2013, at 11:16 , Natalia Muska nata...@fpcomplete.com wrote:

 FP Complete Has Officially Launched the World's First Commercial Haskell IDE!

 http://www.i-newswire.com/fp-complete-launches-fp-haskell/237230

 We greatly appreciate the support we've received from the Haskell community.


 Natalia Muska
 Marketing Manager
 FP Complete, Inc.
 nata...@fpcomplete.com
 865-506-6513
 skype: natalia.s.muska




 --
 Natalia Muska
 Marketing Manager
 FP Complete, Inc.
 nata...@fpcomplete.com
 865-506-6513
 skype: natalia.s.muska
 Official Launch PR.docx___
 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] Applicative is like an Arrow

2013-08-17 Thread Mathijs Kwik
 policy, and by adding
(even implicitly) the lift-lift-lift behavior of monad transformers, it
even more feels like some strange virtual machine that you are
commanding, while you should be describing.

I remember my journey for answers about these same subjects (control
flow, program layout) and how hard it is to get a good understanding and
come up with analogies that work. That's the reason I'm writing these
huge responses, because I hope I can shorten this journey for others.
In short I would say: Idioms are beautiful, and small. If they suffice
for (part of) a problem: use them.
Arrows: I think there is a lot more to these we still need to find out,
but for some reason I find them not very elegant (syntax is probably a
reason) and a lot of people/libraries seem to focus more on monads, so
you always feel left out when you use arrows. Still, interesting to use
every now and then and for some problem domains (like FRP) they feel
more suitable.
Monads (+ transformers): use them when you need to get something done
that you would know how to do in an imperative language. Deadline? use
monads, they feel natural when you come from other languages. Just take
some time afterwards to explore alternatives because in the end you can
do without this crazy virtual-machine factory.

So what do I recommend as alternatives? That, I cannot say.
There is no single silver-bullet, the main point is to keep exploring,
I learned a lot from trying to grasp the basics of category theory
(which I still don't understand at all, but it gave me insights after
all), found that algebras (especially f-algebras), catamorphisms
(generic folds) can be tools to get the same behaviors that transformers
provide. This is strange at first, because they seem subjects that are
related to data structures, but you will quickly develop insights that
teach you that with functional programming there is no distinction
between data structures and control flow and you should embrace this. Of
course you already see this a bit when using the List monad, it's far
more about trying multiple solutions than about lists. Maybe is not
about adding failure to a type, but about a terminate-early control
flow. Well, you can take this a step further when you realize your
entire program/problem is just some DSL in your head that you can
express as a syntax tree (AST). Hey, that's data you can walk over :)
Many times when you think you need state, you actually have a future
function with a hole in it. Try a continuation passing style sometime.
All these things, combined with haskell's laziness let you express
things that are almost magic, but are a far more clear specification of
what you actually want to describe. In other words: the journey only
starts when you look past step-by-step monadic code.

2 nice links that can help develop feeling with those subjects:
- 
http://www.cs.uu.nl/wiki/pub/Center/CompilerConstructionInHaskell/C11-AG-icfp2012.pdf
  first chapter about attribute grammars talks about a different way to
  compose all kinds of aspects of a program and shows how some monads
  (reader/writer/state) are actually embedded into these lazy-folds.
- http://matthew.brecknell.net/post/btree-gadt/
  nice video tutorial showing how some new type system extensions help
  produce better code, while writing less checks and caring less about
  edge cases. The reason I mention it here is because it uses
  continuation-passing-style in a few key places, where my natural
  feeling would have come up with some ugly state-like solution.
  Don't feel bad if you have to pause the video a lot =)

Regards,
Mathijs







 Thanks and regards,
 -Damodar Kulkarni


 On Sat, Aug 17, 2013 at 1:07 AM, Mathijs Kwik math...@bluescreen303.nlwrote:

 Thiago Negri evoh...@gmail.com writes:

  I just stumbled upon the Applicative term.
  Arrows are quite difficult for me to understand at the moment.
  I guess it needs time to digest.
 
  But, as I understand so far, Applicative and Arrows looks like the same
  thing.
 
  Please, enlight me.

 I would like to point out this paper:
 http://homepages.inf.ed.ac.uk/slindley/papers/idioms-arrows-monads.pdf

 In short: arrows are a bit more powerful than idioms (applicative) but a
 bit less than monads. However, power sometimes comes at a price.
 All 3 have to do with combining / sequencing effects, but they differ in
 subtle but important ways. Every idiom is an arrow and every arrow is a
 monad, but not the other way around.

 I will first give an overview of the differences, then try to explain
 what I mean... (my terminology might be a bit awkward/wrong)

 Idiom:
 Basic combining strategy: i (a - b) - i a - i b
 Sequencing: effects are applied in sequence
 values (stuff inside) are isolated
 Shape depends on values: no

 Arrow:
 Basic combining strategy: a b c - a c d - a b d
 Sequencing: effects are applied in sequence
 values are sequenced too
 values can see upstream results
 Shape depends on values

Re: [Haskell-cafe] Applicative is like an Arrow

2013-08-16 Thread Mathijs Kwik
Thiago Negri evoh...@gmail.com writes:

 I just stumbled upon the Applicative term.
 Arrows are quite difficult for me to understand at the moment.
 I guess it needs time to digest.

 But, as I understand so far, Applicative and Arrows looks like the same
 thing.

 Please, enlight me.

I would like to point out this paper:
http://homepages.inf.ed.ac.uk/slindley/papers/idioms-arrows-monads.pdf

In short: arrows are a bit more powerful than idioms (applicative) but a
bit less than monads. However, power sometimes comes at a price.
All 3 have to do with combining / sequencing effects, but they differ in
subtle but important ways. Every idiom is an arrow and every arrow is a
monad, but not the other way around.

I will first give an overview of the differences, then try to explain
what I mean... (my terminology might be a bit awkward/wrong)

Idiom:
Basic combining strategy: i (a - b) - i a - i b
Sequencing: effects are applied in sequence
values (stuff inside) are isolated
Shape depends on values: no

Arrow:
Basic combining strategy: a b c - a c d - a b d
Sequencing: effects are applied in sequence
values are sequenced too
values can see upstream results
Shape depends on values: static choices only

Monad:
Basic combining strategy: m a - (a - m b) - m b
Sequencing: effects are applied in sequence
values are sequenced too
values can see upstream results
Shape depends on values: yes, fully dynamic


Now, what do I mean by all this?
Basically these 3 abstractions consist of 3 things: 
- effects
- values
- shape
Effects can be things like carries state around(State), can
fail(Maybe), multiple answers(List) and more. Values are the pure
stuff inside, and what I call 'shape' is the general control flow of a
computation. 
Furthermore, I visualize these abstractions by thinking of a factory
hall with boxes (values), people (effects) and an assembly line
(shape).


Idioms are fully static: values cannot see/depend on each other or on
the result of effects. Basically the computation is split into 2 phases:
- effects+gather
- apply gathered results
example:
pure (+) * Just 3 * Just 5
The first phase just works through the parts (in sequence) and collects
the (pure) contents. In this case (Maybe) this means looking for the
Just constructor to continue, or halting on Nothing. The content inside
is being treated like a black box. It is not made aware of the effects
(whether or not Nothing was found somewhere) and it is not being
examined to choose a different codepath.
Then if everything worked out (no Nothings were found), the collected
results are taken out of their black boxes and applied. In this phase
these results (the +, the 3 and the 5) don't know anything about the
effects that happened.

In factory visualization: every part of the computation (stuff between
*) is a person that will need to perform some task(effect) and deliver
some result in a box. They will only start performing their task when
they see a box passing by from the person upstream. They cannot look in
that box or make decisions based on it or take it off. At the end of the
line, some manager receives all the boxes and opens them to combine the
results.

This is fine for a whole lot of applications and has the advantage that
the shape of the entire assembly line is clear even before starting
it. This means (static) optimization can be performed and it's easy to
reason about the program/costs. Garbage collection (sending workers
home) is easier, because it's very clear what data is needed where and
when. I will talk a bit more about these optimizations a bit further
down. Of course this assembly line is not flexible enough for more
advanced cases.

Let's see an example of that(State):
pure const * get * put 8
This is a perfectly fine idiom, albeit not very useful.
When run (with initial state 4) the first worker will package up a box
with const and send it downstream. The second worker gets the seeded
state from the state cupboard and put it in a box (4). When that box
passes by worker 3, he will walk to the state cupboard and put 8 in
it. Then to signal he's ready, he packs a box with (). At the end of the
line, someone opens the boxes const 4 and (), which computes to
just 4. So we end up with the answer 4 and an updated cupboard
containing 8.

Why is this not very useful? Well we would probably want to be able to
put state in that depends on certain stuff we got out earlier, instead
of just supplying a hard coded 8 that was known before starting the
line. Unfortunately, this is not possible with idioms as workers cannot
open each other's boxes.


Now, let's skip Arrows for a minute and move straight to Monads:


get = \x - put (x + 1)  return x
As you can see, monads tackle this issue by putting everything in
sequence. Not just the effects, but values too. Like this, they can
see upstream values and upstream effects and influence the effects and
shape of things to come further downstream.

Re: [Haskell-cafe] Instead of Haskell running on the JVM is there a way for Haskell to call a JVM language ...

2012-11-19 Thread Mathijs Kwik
KC kc1...@gmail.com writes:

 Instead of Haskell running on the JVM is there a way for Haskell to
 call a JVM language (or generate bytecode) to access the Java class
 libraries when needed?

I once did a small test to get this working.
It's not that hard, but needs some work. It's fine for exposing a few
functions though.

Basically it's a 2-step process, eased by using a makefile or similar
helper.

You have to compile your haskell code into a shared object (.so on
linux, .dll on windows), which includes the haskell runtime (rts).

This library can be called from c.
A small pitfall is that you first need to do a call to initialize the
haskell runtime, and when you're done using it, close it.
This is most easily just tied to your c/java program's main
initialization functions.

Java is able to load/use these shared libraries through JNI.
Of course you lose your platform-independance, so if you want your java
application to work on multiple platforms / OSses, you need to build
shared objects for all of them.

Last but not least:
You have to export the haskell functions you want through FFI.
Also, make sure they use raw data types such as CString, as that what C
and java will give you and expect back.

So basically you go Haskell FFI - C - Java JNI

I'm sorry I cannot give you any links or code, because I'm in a bit of a
hurry. But google and the ghc docs are your friend.

Mathijs




 Or

 Is there a way for a JVM language or bytecode to call Haskell when needed?

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


[Haskell-cafe] Zipper and Comonad

2012-05-22 Thread Mathijs Kwik
Hi all,

After using zippers for a while, I wanted to dig a bit deeper into them.
I found there is some relation between Zipper and Comonad, but this
confuses me somewhat.

After reading a bit more about Comonads [1] and [2], I think I
understand them somewhat, and I see how they too are useful for
navigating a data structures and giving functions the ability to look
around.

What confuses me though, is the relation between these 2.
This source [3] mentions all zippers can be made instances of Comonad,
and demonstrates how to do this for simple, 1-dimensional (list)
zippers.
But a comment on [4] says a Zipper by itself is already an application
of Comonad.
I want to find out which is the case. Looking at the types does not
yield me a solution yet.

This is Zipper from LYAH:

data Tree a = Empty | Node a (Tree a) (Tree a)
data Crumb a = LeftCrumb a (Tree a) | RightCrumb a (Tree a)
type Breadcrumbs a = [Crumb a]
type Zipper a = (Tree a, Breadcrumbs a)

This is Comonad from the comonad package (flattened to 1 class):

class Functor w = Comonad w where
duplicate :: w a - w (w a)
extend :: (w a - b) - w a - w b
extract :: w a - a

Now, if [3] is correct, I can write instance Comonad Zipper.
If I understood all this correctly, extend becomes (Zipper a - b)
- Zipper a - Zipper b.
This gives me something like a look-around fmap which sounds useful.

If the comment on [4] is correct though, Zipper somehow has a Comonad
built-in, (probably hidden the interaction between Tree and
[Crumb]).
So in that case, a Zipper would be a (somewhat customized) instance
Comonad Tree with some extensions.
(Tree a - b) - Tree a - Tree b seems reasonable. It will build up
a new tree with the same shape as the input tree, and allows the
mapping function to examine every node _and_ its child nodes. It does
not allow looking up though.

So what do I make of this?
It's clear that every Zipper can be a Comonad, and it's probably
useful in some cases, but on the other hand, a Zipper already gives
the ability to look around and modify (a - a) things, so the
comonadic instance only allows you to do this in a somewhat
structure-preserving way.

It's still not clear to me whether there is some truth in a Zipper
itself is an application of Comonad. What I looked at above is just a
Tree instance, which obviously lost power compared to a full Zipper.
But I somehow feel there indeed is a somewhat deeper relation between
these 2 compared to just can be made instance of.

Please share your thoughts.

Thanks,
Mathijs

[1] http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html
[2] http://blog.sigfpe.com/2008/03/comonadic-arrays.html
[3] http://blog.sigfpe.com/2007/01/monads-hidden-behind-every-zipper.html
[4] http://gelisam.blogspot.com/2007/04/i-understand-comonads.html

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


Re: [Haskell-cafe] Increase GHC stack size?

2012-02-05 Thread Mathijs Kwik
./myProgram +RTS -K1600

If that gives an error, you're program was probably compiled without
support for setting RTS options from the command line.
Recompile with -rtsopts.
Then the above should work



On Sun, Feb 5, 2012 at 8:16 PM, Michael Rice limitc...@gmail.com wrote:
 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 ==

 Couldn't find much on the man or info pages. Example please, say double it
 (1600) for starters.

 Michael


 ___
 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] If you'd design a Haskell-like language, what would you do different?

2011-12-19 Thread Mathijs Kwik
A mascot :)


On Mon, Dec 19, 2011 at 8:20 PM, Robert Clausecker fuz...@gmail.com wrote:
 Image you would create your own language with a paradigm similar to
 Haskell or have to chance to change Haskell without the need to keep any
 compatibility. What stuff would you add to your language, what stuff
 would you remove and what problems would you solve completely different?

 Thanks in advance for all answers, yours

        Robert Clausecker


 ___
 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] Dutch national FP day, January 6, Utrecht

2011-12-16 Thread Mathijs Kwik
Ik wil me graag inschrijven, inc dinner.

Groeten,
Mathijs

On Fri, Dec 16, 2011 at 3:31 PM, S D Swierstra doai...@swierstra.net wrote:
 On

 http://www.cs.uu.nl/wiki/bin/view/FPDag2012/WebHome


 you will find the program and registration  information about the next Dutch 
 National Functional Programming day, on January 6, Utrecht University.

 Please forward this mail to anyone interested.

 Any questions can be directed to me.

 Hoping to meet you all,
 Doaitse Swierstra




 ___
 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 vs. Dart

2011-10-11 Thread Mathijs Kwik
I disagree.

They added types and interfaces to the language, giving it at least
some type-safety (preventing me from making stupid mistakes that will
only show up at runtime). I didn't look much further, but they _are_
extending the language itself. Coffeescript on the other hand, is just
a different syntax for javascript, not really adding any features. I
love coffeescript, it's way more readable and concise, but it's just
that, a different syntax.

I do like your suggestion about a bytecode language for browsers.
Although I must say that haskell didn't get very far (as in: usable)
on the other 2 big bytecode platforms (java/.net) yet, but probably
browsers are a much more wanted target.

Mathijs

On Tue, Oct 11, 2011 at 1:10 PM, Heinrich Apfelmus
apfel...@quantentunnel.de wrote:
 Kevin Jardine wrote:

 After Google's disappointing Dart announcement yesterday, I decided to
 tweak
 them a bit and mention Haskell and functional programming languages as an
 alternative:

 https://plus.google.com/u/0/111705054912446689620/posts/UcyLBH7RLXs

 Comments on the post are welcome!

 I didn't look very carefully, but from a Haskeller's point of view, I can't
 see any significant difference between Dart and JavaScript, except perhaps
 for the name. By comparison, CoffeeScript is a way more innovative venture.

 A far more useful thing for Google to do would be a standardized bytecode
 language for the browser; something that can be JITted efficiently while
 guaranteeing safety/security. This way, the compilation chain

    Haskell - bytecode - browser

 would finally be viable.


 Best regards,
 Heinrich Apfelmus

 --
 http://apfelmus.nfshost.com


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


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


[Haskell-cafe] SplitObjs and LLVM

2011-10-07 Thread Mathijs Kwik
Hi all,

Is it a known issue that -fllvm doesn't produce split objs?
I tried ghc 7.0.3 with llvm 2.8 and ghc 7.2.1 with llvm 2.9.

Thanks,
Mathijs

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


Re: [Haskell-cafe] emacs literate haskell mode

2011-09-28 Thread Mathijs Kwik
I tried mmm-mode with a few configurations, but I get into trouble
when using other haskell-mode features. Also, the wiki page on
haskell-mode ( 
http://www.haskell.org/haskellwiki/Haskell_mode_for_Emacs#Literate_Haskell
) specifically mentions mmm-mode tricks are not needed anymore and
shouldn't be used.

Its built-in support does a great job to keep all code blocks working
the way I want, but the latex parts are just dead text.

I wouldn't mind to switch manually, as most of the time I'm either
coding (touching only small parts of latex), or writing (leaving the
code parts as-is).
However, latex mode seems to trip over certain code parts ($ sign in
haskell code for example).
So it seems it's not smart enough to just ignore code blocks.

Probably I need to look into latex mode a bit more, so it becomes
off-topic for this list.

Thanks for your help
Mathijs


On Wed, Sep 28, 2011 at 1:27 AM, Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 28 September 2011 07:42, Rogan Creswick cresw...@gmail.com wrote:
 On Tue, Sep 27, 2011 at 11:24 AM, Mathijs Kwik math...@bluescreen303.nl 
 wrote:
 Hi all,

 I'm using haskell-mode for emacs and I'm using it to open a literate
 haskell file which uses latex.
 This works fine, haskell code has syntax highlighting, and special
 symbols like lambda get used.
 However, the latex itself is dull and gree, no highlighting/coloring there.
 Does anyone know if it's possible to turn on latex highlighting in
 literate haskell mode?
 I tried switching to latex-mode, which does the trick (but it chokes
 on the haskell code inbetween), so I'm pretty sure emacs has
 everything it needs, but haskell-mode needs to enable this somehow.

 I'm not certain this /is/ easily in Emacs capabilities.  Emacs isn't
 really set up to support more than one major mode at a time -- there
 is, however, an extension that can do this.  The challenge is defining
 the start and end of the areas of each 'mode' in the buffer; I've
 never had very much success, but depending on the delimiters used in
 the literal haskell syntax you're working with, you may be able to set
 it up:

 http://www.emacswiki.org/emacs/MultipleModes

 There's a more detailed listing at configurations, etc. at:

 * 
 http://www.haskell.org/haskellwiki/Literate_programming#Multi-mode_support_in_Emacs
 * haskell-latex.el at http://www.loveshack.ukfsn.org/emacs/ (mentioned
 in the MultipleModes page on the emacs wiki)

 But in general, I agree: multiple modes suck in Emacs.  I tried all of
 the available attempts at multiple modes when trying to get Markdown +
 literate Haskell working, the best I could get was using multi-mode.el
 (and there are still a few glitches).

 In general, Emacs tends to go a bit nuts when it's time to switch modes :/

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


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


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

2011-09-17 Thread Mathijs Kwik
perfect! works like a charm.
Thanks for the quick response!

Have a nice weekend,
Mathijs

On Sat, Sep 17, 2011 at 3:58 PM, Sergey Mironov ier...@gmail.com wrote:
 2011/9/16 Mathijs Kwik math...@bluescreen303.nl:
 Do I need any special .el file to use these?
 Or commandline arguments to use etags format?

 Emacs tells me 'visit-tags-table-buffer: File
 /home/mathijs/packages/snap/tags is not a valid tags table'


 Please try haskdogs-0.3.
  haskdogs -e
 should generate TAGS file. I didn't check, but probably it is what
 emacs supports.

 Sergey


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


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

2011-09-16 Thread Mathijs Kwik
Do I need any special .el file to use these?
Or commandline arguments to use etags format?

Emacs tells me 'visit-tags-table-buffer: File
/home/mathijs/packages/snap/tags is not a valid tags table'




On Tue, Sep 13, 2011 at 10:39 PM, Sergey Mironov ier...@gmail.com wrote:
 Hi! I am pleased to announce haskdogs - project-level ctag file generator.

 haskdogs is a small shellscript-like tool which creates tag file for
 entire haskell project directory. It takes into account first-level
 dependencies by recursively scanning imports and adding matching
 packages to the final tag list. As a result, programmer can use
 his/her text editor supporting tags (vim, for example) to jump
 directly to definition of any standard or foreign function he/she
 uses. Note, that haskdogs calls some Unix shell commands like test or
 mkdir so this tool will likely fail to work on pure Windows platforms.

 To use it, do

 0) cabal install hasktags haskdogs  mkdir -p ~/.cabal/var/haskdogs
 1) cabal unpack TrickyProject-4.2  cd TrickyProject-4.2
 2) haskdogs
 3) enjoy the tagfile with references to every function

 http://hackage.haskell.org/package/haskdogs-0.1

 Sergey

 ___
 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] Experimental GHC with GHCJS built in and Cabal support for JavaScript files

2011-05-14 Thread Mathijs Kwik
Wow, this is great news.
(still compiling, so didn't even try it out yet)

Will it be possible to interface (from/to) with native javascript
functions in this release?
And are there any packages that provide the objects/functions provided
by the DOM?

Thanks for continuing ghcjs. I was beginning to fear people didn't
mind to code JS by hand :P



On Sat, May 14, 2011 at 7:44 PM, Hamish Mackenzie
hamish.k.macken...@googlemail.com wrote:
 Blackh and I have been trying out some ideas on how to make it easier use 
 GHCJS in your Cabal projects.  We took Victor's GHCJS code and added it back 
 into GHC (we could not easily accomplish what we wanted using the current GHC 
 API).  We set it up so that GHC outputs a .js file whenever it outputs an 
 object file.  We added code to Cabal to install the .js files (in the same 
 place as the .hi files).  At link time GHC copies all the .js files from the 
 packages used into a .jsexe directory (with the same name and in the same 
 location as the executable).  Finally when the executable is installed we 
 copy the .jsexe directory along with it.  Only files with differing modified 
 dates are copied to avoid slowing things down too much.

 I have updated my yesod-slides example to show how all this can be used.

 https://github.com/hamishmack/yesod-slides

 The README.mardown there has instructions for building GHC and Cabal with the 
 GHCJS stuff in it.  It is a bit painful to build, but the changes to 
 yesod-slides were quite minor...
  * Added ghcjs-rts to the build depends
  * Published the yesod-slides.jsexe folder (using Yesod's staticFiles)
  * Added script tags to head for rts-common.js and rts-plain.js
  * Added Julius script to init the rts

 Currently GHC is hard coded to use the GHCJS Trampoline calling convention 
 (in GHC's HscMain.hs).

 Hamish
 ___
 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] ArrowLoop and streamprocessors

2011-04-01 Thread Mathijs Kwik
Thank you all,

As you all pointed out, arrows are just not up to this without resorting to
tricks such as timestamping.
I'm gonna have a look at the Peakachu library now (
http://hackage.haskell.org/packages/archive/peakachu/0.3.0/doc/html/FRP-Peakachu-Program.html
)
(thanks Gergely!), it looks like a nice API and seems to match some ideas I
had in mind.

Have a nice weekend!
Mathijs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ArrowLoop and streamprocessors

2011-04-01 Thread Mathijs Kwik
On Fri, Apr 1, 2011 at 8:28 PM, Paul L nine...@gmail.com wrote:

 Forgot to CC the list, please see below.

 On Wed, Mar 30, 2011 at 2:29 PM, Mathijs Kwik bluescreen...@gmail.com wrote:

  someBox :: Either A B ~ O
  someBox = handleA ||| handleB

 Not sure about this. If you are modeling the input as Either A B, then
 you are excluding the possibility of both A and B occur at the same
 time. I suggest you change the type to:

 someBox :: (Maybe A, Maybe B) ~ O

In case they both occur, I just prioritize 1 over the other, so I
handle A, and on the next run handle B.
Your suggestion might come useful later on though, if prioritizing
won't do the trick in certain cases.


 Based on your later comments, you implied that there could be multiple
 B produced from one O. Then I'd suggest the following type:

 someBox :: (Maybe A, [B]) ~ O

This implies that otherBox buffers its results somehow to produce the
list of B's and present it as 1 result.
I think this defies the CPS style stream processors goal.
In reality, the outputs might be infinite, or just very very many,
which will cause space leaks if they need to be buffered.


  otherBox :: O ~ Either C B
 
  Also note that in this CPS style streamprocessing, there's no 1-on-1
  relation between input and output, so on 1 input (O), otherBox might
  produce 2 outputs (2 times C), or 4 outputs (3 times C and 1 time B).

 If the number of inputs do not match the number of outputs, I suggest
 you change the type to:

 otherBox :: O ~ [Either C B]

I think you are suggesting to use lists to essentially synchronize the
input/output streams so every step of every part of the program will
always produce an output for every input. In case no real output was
produced, the result is just [].
This is a very interesting thought but I think there will be issues with this.
The start (someBox) will wait before every run until it receives
the result from the end, even if this is just [].
If the loop becomes larger, includes heavy calculations, or has to
wait for IO, this might take quite some time. Essentially the loop as
a whole will be running as some kind of singleton. It will only
restart if the last run has fully completed, meaning all inbetween
steps are doing no processing in the mean time.
Also, the full loop (every step within it) will need to run for every
input. If someBox filters its inputs and only acts on 1 in a million
of its inputs, it will now have to send [] downstream for every
dropped input and wait for the end of the loop to feed-back [] to
continue.


  To wire back B's to someBox, I'm pretty sure I need to use ArrowLoop.
  But (loop :: a (b, d) (c, d) - a b c) uses tuples, which means the
  processing will only continue when both inputs are available.
  So if I turn someBox into (A, B) ~ O and otherBox into O ~ (C, B),
  the processing will instantly halt, waiting for a B to arrive after
  the A comes in.

 You can do something like this, first, split the B out of the ouput:

 split :: [Either C B] ~ ([C], [B])

 Then the loop back:

 loop (someBox  otherBox  split) :: Maybe A ~ [C]

I must say, you did solve the problem I posted and I am gonna have a
look at its implications this weekend.
It's probably not gonna work in all situations and in a way defeats
stream processing's advantages, but it might still be useful in
certain situations.

Thanks you for your advice, it at least got me thinking in directions
I didn't consider before.

Mathijs


 --
 Regards,
 Paul Liu

 ___
 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] ArrowLoop and streamprocessors

2011-03-30 Thread Mathijs Kwik
Hi all,

I'm playing around a bit with arrows (more specifically, something
like a CPS style streamprocessor as described in Generalising Monads
to Arrows by John Hughes).
A part of my program takes inputs/signals from 2 sources.
The sources don't produce output at the same rate, and this part is
able to handle inputs independently.
So I figured I need Either A B ~ O for this part.

handleA :: A ~ O
handleB :: B ~ O

someBox :: Either A B ~ O
someBox = handleA ||| handleB

So far so good.

Now, further downstream (someBox  otherBox) there is.

otherBox :: O ~ Either C B

Let's say C are normal outputs, and B are control signals that need
to get wired back to someBox.
Control signals are rare, so maybe there's 1000 C outputs and only 1 B
output in a certain timeframe.
Also note that in this CPS style streamprocessing, there's no 1-on-1
relation between input and output, so on 1 input (O), otherBox might
produce 2 outputs (2 times C), or 4 outputs (3 times C and 1 time B).

To wire back B's to someBox, I'm pretty sure I need to use ArrowLoop.
But (loop :: a (b, d) (c, d) - a b c) uses tuples, which means the
processing will only continue when both inputs are available.
So if I turn someBox into (A, B) ~ O and otherBox into O ~ (C, B),
the processing will instantly halt, waiting for a B to arrive after
the A comes in.

I know about the 'delay' trick that usually works for loops, where an
output value is just inserted before the actual outputs, but that
won't help in my case, because otherBox doesn't produce B's at the
same rate that someBox receives A's, so by inserting a dummy B,
someBox will only run once.
Also, there's no relation between the number of A inputs someBox
receives and the number of inputs for otherBox, so I also can't have
otherBox just insert noop signals after every run.

So loop really doesn't seem to help here, but I couldn't find another
way either to feed outputs back into the system.
What I need is:
Either A B ~ Either C B - A ~ C

Does such a thing exist?

Thanks,
Mathijs

PS: I remember reading about (unfortunately didn't get the examples
working) Reactive (FRP), which has the concept of Events and Behaviors
I think Yampa has something like it too. A Behavior has a value at all
times, which was updated by Events. That sounds a bit like it might
solve my problem, since I need something that contains Latest Control
Signal was X that updates when B's are produced, but that doesn't
have to be put on the wire as a stream of events (because I can't
determine how many events to put to match incoming A's. However, I
hope there is another solution because I found Reactive and Yampa
quite hard to grasp.

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


[Haskell-cafe] forcing a type constraint on data

2011-01-01 Thread Mathijs Kwik
Hi all,

I would like to make a more restrictive version of a certain datatype.
I tried wrapping it in a newtype, fundeps, type families, really got lost :)

What I'm trying to achieve is the following:
The original package
http://hackage.haskell.org/packages/archive/reaction-logic/2010.11.17/doc/html/Data-Reactor.html
has a constructor function (mkReactor) with exactly the constraints
I'm after. However, the constraint is just on this constructor
function, not on the data itself.
All functions I write are inferred as Reactor (State s) c, while the
use of that constructor ensures that s == c.
Also, I might switch State s for some StateT s m later on, so I
would really like to be able to use (MonadState c m) = Reactor m c
in my functions as well, since this is the most generic.

Trying that blows up however:
Could not deduce (m ~ StateT s Identity)
  from the context (ValidEvent event, MonadState s m)
  `m' is a rigid type variable bound by
  the type signature for `stepper2' at Eventer.hs:77:45
In the first argument of `runState', namely
  `(insertExternals reactor [Serial event])'
In the expression:
  runState (insertExternals reactor [Serial event]) state
In an equation for `stepper2':
stepper2 (Just reactor, state) event
  = runState (insertExternals reactor [Serial event]) state

Can someone please explain the cause of this problem?
Are there workarounds? Language extensions?

Thanks in advance,
Mathijs

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


Re: [Haskell-cafe] Haskell, Step by Step, Tutorial, Developing a Whole Application

2010-12-16 Thread Mathijs Kwik
I too would like such a tutorial.
There is a lot of good material explaining certain concepts, and
complete examples doing some real-world task. I've read RWH and LYAH
and browsed quite some sources from packages from hackage. I
understand what I read and I'm able to re-use that knowledge. But I
too still feel uncertain about overall application design. Most stuff
on hackage are libraries. Binaries are mostly examples or some small
wrapper around a library.
My OOP background might be causing me to keep thinking that certain
parts (model, controller, storage layer) of an application talk to
each other by sending messages (method calls). When just trying out
something, this thinking leads me to applications that have a lot of
funcionality in IO. Sure there are lots of pure functions as well and
I occasionally lift them into Monads or Applicatives. Even
transformers are becoming less scary as of late. But the parts that
tie everything together are IO, they feel very imperative, and I feel
this isn't necessary. I can think of some ways to make it better, so
sure, by trial and error I learn and indeed it's fun. But I would have
a lot more confidence if I knew that there's a certain workflow that's
generally considered the right thing to do. Some default ways to
organize code (like the MVC pattern), and for tying things together.

It's indeed hard to really explain what I feel is missing. The
examples you mention, and some examples I know of (like the blog app
in 15 minutes ruby on rails demo) are more like a top-down approach.
Most haskell tutorials and libraries are bottom-up.
While I like building stuff brick by brick to make it really steady,
I still feel that first putting up some steady scaffolds are great to
give me some boundaries while building. I know what point to build
towards, and gives me some insights into progress. In the end ofcourse
the scaffolds will be taken away, when the bottom-up brick-laying is
complete enough.

Don't get me wrong, I'm not asking for a full-blown framework. I know
there are specialized frameworks for many things (especially webapps
as of late), many of which have some tutorials. I'm asking for
something more generic. How do you start, where do you place things,
what type of things are usually around, how do you bind them together
and most importantly: why.




On Fri, Dec 17, 2010 at 12:49 AM, __kaveh__ kaveh.shahbaz...@gmail.com wrote:

 Is there a (or more; the more, the better) tutorial for Haskell,
 developing a whole application (of any kind: web, windows, console)?

 I mean something like NerdDinner or MVC Music Store for ASP.NET MVC;
 Or those whole applications in in Action books.

 Thanks

 Edit 1: Thanks to all for your replies. I just wanted to insist on
 step by step developing a whole application aspect of what I want;
 not those tutorials that teach Haskell (they are not bad - They are
 not this). I believe if one could understand Haskell well and even
 understand it's underlying mathematical foundations, that (absolutely)
 does not mean he can develop an application in Haskell. The problem
 with Haskell is not failing to understand it (I can use LINQ and even
 developed a DSL based on LINQ - a LINQ provider - and see how it makes
 composition tidy) but failing to understand the context (system
 thinking). I can use same concepts in C# because I know the context
 and it is easy to feed in new tools/concepts. In Haskell, one can
 understand every bit of it (well almost) but there is no context there
 to fit in! So (I might not be wrong - but who knows!) there is an
 absolute need for this kind of tutorial (I wish there was a better
 name for this).

 Edit 2: I believe there is a way to learn and teach Haskell in a neat
 and straight way (That does not mean I think Haskell is a pragmatic
 programming language - don't get me wrong; I appreciate it; but start-
 up barrier with Haskell it too high; It has still a long way ahead to
 be considered as a common purpose programming language and may never
 does. But Haskell is definitely father of future programming languages
 - and also not so future ones!)

 Note: I have asked this question on stackoverflow (http://goo.gl/
 bCFf7) and I will try to sync useful information as much as possible.

 ___
 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] threadWaitRead and threadWaitWrite on multiple fds

2010-12-13 Thread Mathijs Kwik
Just to reply to myself once again,

System.Event (which isn't hidden) re-exports (un)registerFd and other
functions I need for this.
So I can implement all this myself. The only thing I can't do is ask
the RTS's eventmanager to watch the fds for me, but I can just create
my own (new constructor is exposed as well) to keep all fd-watching
in 1 thread.

So it seems just enough functionality is exposed to do what I'm after.
Those GHC devs must be clever guys :)



On Mon, Dec 13, 2010 at 8:24 AM, Mathijs Kwik bluescreen...@gmail.com wrote:
 Yep, that's like the workaround I'm using right now.
 I create an empty mvar, fire up 2 threads that will wait for an fd and
 tryPutMVar afterwards.
 My original thread justs gets the MVar to wait for any of the 2
 fd-waiting-threads to complete.
 But however light threads may be, I still think this might give some
 overhead, and it's almost the same trick that System/Event/Thread is
 using internally, although in that case, the putMVar is performed by
 the event manager thread.
 As far as I can tell, the behavior isn't hard-coded in the RTS (no
 need to change that), but applications that use base will tell it to
 use the mvar-trick as callback. That's why I was hoping to be able to
 just tell it to use a different callback.

 But indeed it's a solution for now.
 I'll just post a feature-request for GHC.

 Thanks


 On Mon, Dec 13, 2010 at 3:19 AM, Mitar mmi...@gmail.com wrote:
 Hi!

 On Mon, Dec 13, 2010 at 2:14 AM, Antoine Latter aslat...@gmail.com wrote:
 Can you do it with forkIO? That is, have two light-weight threads,
 each waiting on a different fd, which perform the same action when one
 of them wakes up.

 Or you could wait for each fd in its own thread (those are really
 light-weight threads) and once some is triggered you spawn another
 thread which deals with the event, while the original thread goes back
 into the waiting. Or you can also send data over Chan to another
 thread which then processes the even (if you need to serialize
 processing).


 Mitar



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


[Haskell-cafe] threadWaitRead and threadWaitWrite on multiple fds

2010-12-12 Thread Mathijs Kwik
Hi all,

I read the paper about the new ghc7 event handling IO manager goodies.
This is all very exciting stuff. I didn't know GHC's RTS had these
smart async-IO facilities.
The paper pointed me at threadWaitRead/threadWaitWrite.
While very nice the way they are, I would also like to be able to wait
on more than 1 fd until 1 of them becomes available.

Would it be possible to create this functionality myself? Or do I need
to request it and wait for a new GHC?
It looks like the functionality I need is in System/Event/Thread.
I think I can manage to write my own version of those functions which
then loop through a list of fds, but the original file imports
System/Event/Manager (registerFd, unregisterFd_) which I can't do
because it's a hidden module.
Is there a way around this?


Thanks,
Mathijs

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


Re: [Haskell-cafe] threadWaitRead and threadWaitWrite on multiple fds

2010-12-12 Thread Mathijs Kwik
Yep, that's like the workaround I'm using right now.
I create an empty mvar, fire up 2 threads that will wait for an fd and
tryPutMVar afterwards.
My original thread justs gets the MVar to wait for any of the 2
fd-waiting-threads to complete.
But however light threads may be, I still think this might give some
overhead, and it's almost the same trick that System/Event/Thread is
using internally, although in that case, the putMVar is performed by
the event manager thread.
As far as I can tell, the behavior isn't hard-coded in the RTS (no
need to change that), but applications that use base will tell it to
use the mvar-trick as callback. That's why I was hoping to be able to
just tell it to use a different callback.

But indeed it's a solution for now.
I'll just post a feature-request for GHC.

Thanks


On Mon, Dec 13, 2010 at 3:19 AM, Mitar mmi...@gmail.com wrote:
 Hi!

 On Mon, Dec 13, 2010 at 2:14 AM, Antoine Latter aslat...@gmail.com wrote:
 Can you do it with forkIO? That is, have two light-weight threads,
 each waiting on a different fd, which perform the same action when one
 of them wakes up.

 Or you could wait for each fd in its own thread (those are really
 light-weight threads) and once some is triggered you spawn another
 thread which deals with the event, while the original thread goes back
 into the waiting. Or you can also send data over Chan to another
 thread which then processes the even (if you need to serialize
 processing).


 Mitar


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


Re: [Haskell-cafe] Haskell-friendly Linux Distribution

2010-03-28 Thread Mathijs Kwik
As a developer in 3 languages (ruby  java professionally, haskell as
hobby) I must say I really prefer just managing this manually,
separate from the package manager.

I'm running ubuntu LTS (8.04) on production servers.
I don't want to upgrade a server OS every 6 months, so I really like
the more conservative LTS approach that ubuntu took.
But this would mean that an environment for a language would also be
somewhat frozen for at least 2 years, which isn't very useful. When
10.04 gets out with ghc 6.12.1, it will still mean that's the only
thing available until 2012, or I need to upgrade the entire OS every 6
months.

Developers prefer newer versions of ubuntu on their machines, or
another distro (or use a mac).
To get stuff working the same on all machines, it's really just the
easiest just to use manual installation.

I just keep stuff in /opt
/opt/ghc-6.10.4
/opt/ghc-6.12.1
/opt/java6
/opt/jruby-1.4
/opt/ruby-1.9
/opt/ruby-enterprise-1.8.6
/opt/ruby-enterprise-1.8.7

This has a lot of advantages:
- I don't have to wait for certain updated packages (for libs or
compiler / interpreter stuff).
- I can keep multiple versions of a language around and just switch by
changing PATH (for which I have aliases/helpers).
This opens up possibilities to keep legacy code running (I mean
upgrading to ubuntu 10.04 will mean breaking any apps that aren't
fully 6.12 compatible yet), and allows somewhat more experimental
projects to use latests-and-greatest (or even beta) versions of an
environment.

- no problems mixing package-manager installed libs with manually
installed stuff
I saw this has improved a bit for ruby/haskell quite a bit, now
allowing installation of manually installed libs to a user home-dir.
But I prefer not splitting my packages over multiple locations, so
just keeping them in 1 place manually.

This means that (when building/installing stuff) I have to install
some packages like gcc/binutils and some -dev (header) packages when I
need to bind to native code (I can uninstall them afterwards).

For getting an environment uprunning I just have some bash-scripts
which install needed (package-manager) packages, download the sources
I need and install stuff to /opt, and clean up afterwards.
It's easy to keep those scripts portable between
distributions/versions/architectures.
This way, developers can run any distro they like, and I can keep
using the more conservative LTS release on production.


For production machines (that all have same OS and architecture) I
build everything on 1 machine and have others just sync the /opt stuff
if needed.

This might not be a solution for you, it really depends on your needs,
but for me, I found it's often useful to control the exact environment
an application needs and it gives developers the freedom to run
whatever OS they like, which is a huge benefit if you use contractors
or if devs want to work from home.




On Sun, Mar 28, 2010 at 5:11 AM, Chris Dornan ch...@chrisdornan.com wrote:
 Hi,



 I am choosing a Linux distribution for a production Haskell project and
 would would normally just go with Debian (pedigree, stability, and of course
 Haskell Platfom included) but CentOS is in the frame.



 Are there any particularly strong reasons for preferring or avoiding any
 particular distribution?



 Chris



 ---

 Chris Dornan

 email : ch...@chrisdornan.com

 tel   : +1 (847) 691 7945



 ___
 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] Binaries using shared libraries with cabal-install

2010-03-15 Thread Mathijs Kwik
Hi all,

I'm using cabal-install 0.8.0 on ghc 6.12.1 on linux
I switched on shared library support on cabal.

Does this enable -dynamic and -fPIC during compilation and -dynamic
-shared during linking?
Or does it work a little differently?

I noticed everything works for libraries. .so files get created, and
using ldd on them shows they depend on other haskell shared libraries.
But for binaries, it seems it still compiles them with everything included.
ldd'ing them shows no haskell-library dependencies and their size is
quite big as well.

Is it possible to tell cabal-install I want binaries to use shared libs instead?
And is there a way to specify which RTS to link binaries with? (debug,
threaded, normal)
Or a way to defer linking to an RTS so I can do this on execution
using LD_PRELOAD ?

Thanks for any help
Mathijs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] PseudoTerminals and Handles (again)

2010-03-10 Thread Mathijs Kwik
Hi All,

A few days ago, I got started with the code found on this blogpost:
http://www.serpentine.com/blog/2008/09/30/unix-hacking-in-haskell-better-pseudoterminal-support

On my system, I found that using pseudoterminals as handles did not work.
Reading output and writing input works fine, it's just that finding
the end of the stream seems to break.
This means that I can read all output up to the last character
outputted by the other process, but the string doesn't end there.
Instead it's throwing:
fdReadBuf: hardware fault (Input/output error)

Using normal pipes (no pty), this does work as expected.

My guess is that I should somehow setup the fd or the pty a little
more before starting the child process.
Set them to nonblock/block, read/write mode, setTerminalAttribute,
stuff like that. And maybe it matters when to change settings (before
forking / after forking / in the child), or to change the master or
the child...
I don't know very much about this stuff but since the rest seems to
work fine it just seems to be a problem with how the child announces
it's finished writing to the fd.

Is there anyone who got this to work somehow?
Or is there a way to somehow trick hGetContents and friends to just
treat the hardware fault as EOF?

Thanks
Mathijs


PS: I'm using ghc 6.12.1 on x86_64  (ubuntu) by the way
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] file descriptors and handles

2010-03-08 Thread Mathijs Kwik
Hi all,

Today I had a look at chapter 20 of RWH.
The extended example (stripped down HSH) in the end is great.
I think I understand it, but I have some questions left:

the master process closes the client-sided FD's.
it uses fdToHandle for the other sides of the pipe to get a handle to
stdIn and stdOut on the client process.
it writes to the stdIn handle and closes it afterwards.
- doesn't it need to close the fd as well?

the stdOut handle gets used when reading the command output (using hGetContents)
- doesn't the handle need to get closed? or will this happen
automatically if hGetContents finds EOF ?
- and also here, shouldn't the fd get closed?

More general:
what happens when closing a handle when there's still output left?
Will reading further output throw an exception or just think it's EOF?
And what happens when closing the underlying FD? will the handle
break? or will it close automatically?

Thanks for any help
Mathijs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ptys and hGetContent problem

2010-03-08 Thread Mathijs Kwik
Hi all,

I found this blogpost from Bryan O'Sullivan
http://www.serpentine.com/blog/2008/09/30/unix-hacking-in-haskell-better-pseudoterminal-support/
and I wanted to try it out.

Before moving to an interactive command (which needs pty), I just did
a small test for ls -l / to see if it worked.
I got it to compile, but when running, it throws an exception when
reaching the end of the output (in this case because I evaluate the
length to force reading all).
Main: /dev/ptmx: hGetContents: hardware fault (Input/output error)

Please have a look at the hpaste to see what I did:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=23343

What's wrong? :)
My guess is that hGetContents doesn't receive a nice EOF when the
process exits (ls doesn't stay around waiting for input), but I have
no idea on how to fix this.

And further...
If I do want to use an interactive program which needs input, how do I
send ctrl-d or ctrl-c?
tail -f needs ctrl-c (or I need to kill the process)

Thanks for any help
Mathijs

PS:
I know about libexpect, it's not useful for what I wanna do (multiple
processes, having 'answers' from 1 be used to decide what to input the
other, without ending the 'answer' process)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ptys and hGetContent problem

2010-03-08 Thread Mathijs Kwik
Ok, cool

I got a bit further now.
I'm not using handles anymore (they seem to break indeed for ptys).
Just using executePseudoTerminalFd now (from the original blogpost)
and fdRead/fdWrite.
Now I can communicate with the process and all goes well.
If I really want lazy-like behaviour, I can just forkIo and talk
through a Chan, but for now this is enough.

Also sending \^C and \^D work as expected, although I just saw the
reply mentioning I should ask stty for the current EOF character.

The only thing I'm still looking for is a way to stop echoing input.
Right now, fdRead gives me back the output of the process, mixed with
the input I supplied.
I'm pretty sure this can be turned off.

Any suggestions?


On Mon, Mar 8, 2010 at 11:11 PM, Nick Bowler nbow...@elliptictech.com wrote:
 On 20:38 Mon 08 Mar     , Mathijs Kwik wrote:
 Hi all,

 I found this blogpost from Bryan O'Sullivan
 http://www.serpentine.com/blog/2008/09/30/unix-hacking-in-haskell-better-pseudoterminal-support/
 and I wanted to try it out.

 Before moving to an interactive command (which needs pty), I just did
 a small test for ls -l / to see if it worked.
 I got it to compile, but when running, it throws an exception when
 reaching the end of the output (in this case because I evaluate the
 length to force reading all).
 Main: /dev/ptmx: hGetContents: hardware fault (Input/output error)

 You have just stumbled into the wonderful world of pseudo-terminals,
 where their behaviour is subtly different on every bloody platform.  It
 appears that on your platform, after the last user closes the slave port
 (i.e. after your child process terminates), subsequent reads from the
 master port return EIO.

 One would normally detect this condition with the poll system call, by
 looking for POLLHUP on the master port.

 On some platforms (but evidently not yours), the last close of the slave
 port causes the behaviour you seem to have expected, where a subsequent
 read returns 0.

 What's wrong? :)

 Presumably the problem is that handle-based I/O is not suitable for
 pseudo-terminal masters.  Definitely not lazy I/O.

 And further...
 If I do want to use an interactive program which needs input, how do I
 send ctrl-d or ctrl-c?
 tail -f needs ctrl-c (or I need to kill the process)

 These so-called control characters are normally configured by termios.
 If suitably configured, the appropriate action will be performed when
 the control characters are written to the master port.

 --
 Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)

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


Re: [Haskell-cafe] ptys and hGetContent problem

2010-03-08 Thread Mathijs Kwik
And to reply to myself again...

  ta - getTerminalAttributes fd
  setTerminalAttributes fd (withoutMode ta EnableEcho) Immediately
  -- and to find the right EOF character:
  let Just eofChar = controlChar ta EndOfFile

On Tue, Mar 9, 2010 at 12:23 AM, Mathijs Kwik bluescreen...@gmail.com wrote:
 Ok, cool

 I got a bit further now.
 I'm not using handles anymore (they seem to break indeed for ptys).
 Just using executePseudoTerminalFd now (from the original blogpost)
 and fdRead/fdWrite.
 Now I can communicate with the process and all goes well.
 If I really want lazy-like behaviour, I can just forkIo and talk
 through a Chan, but for now this is enough.

 Also sending \^C and \^D work as expected, although I just saw the
 reply mentioning I should ask stty for the current EOF character.

 The only thing I'm still looking for is a way to stop echoing input.
 Right now, fdRead gives me back the output of the process, mixed with
 the input I supplied.
 I'm pretty sure this can be turned off.

 Any suggestions?


 On Mon, Mar 8, 2010 at 11:11 PM, Nick Bowler nbow...@elliptictech.com wrote:
 On 20:38 Mon 08 Mar     , Mathijs Kwik wrote:
 Hi all,

 I found this blogpost from Bryan O'Sullivan
 http://www.serpentine.com/blog/2008/09/30/unix-hacking-in-haskell-better-pseudoterminal-support/
 and I wanted to try it out.

 Before moving to an interactive command (which needs pty), I just did
 a small test for ls -l / to see if it worked.
 I got it to compile, but when running, it throws an exception when
 reaching the end of the output (in this case because I evaluate the
 length to force reading all).
 Main: /dev/ptmx: hGetContents: hardware fault (Input/output error)

 You have just stumbled into the wonderful world of pseudo-terminals,
 where their behaviour is subtly different on every bloody platform.  It
 appears that on your platform, after the last user closes the slave port
 (i.e. after your child process terminates), subsequent reads from the
 master port return EIO.

 One would normally detect this condition with the poll system call, by
 looking for POLLHUP on the master port.

 On some platforms (but evidently not yours), the last close of the slave
 port causes the behaviour you seem to have expected, where a subsequent
 read returns 0.

 What's wrong? :)

 Presumably the problem is that handle-based I/O is not suitable for
 pseudo-terminal masters.  Definitely not lazy I/O.

 And further...
 If I do want to use an interactive program which needs input, how do I
 send ctrl-d or ctrl-c?
 tail -f needs ctrl-c (or I need to kill the process)

 These so-called control characters are normally configured by termios.
 If suitably configured, the appropriate action will be performed when
 the control characters are written to the master port.

 --
 Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)


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


Re: [Haskell-cafe] Is there a way to embed a Haskell interpreter/compiler in a browser. I think this would be a safer language than JavaScript.

2009-10-26 Thread Mathijs Kwik
There used to be http://www.haskell.org/haskellwiki/Yhc/Javascript, which is
a great plan, but got abandoned (I think).
I still hope something like that will return some day (and not just for
javascript, I would like to compile haskell to java bytecode or .net).

For something that's usable now, have a look at HJScript and HJavaScript.

Those are low-level libraries allowing you to generate javascript safely in
haskell.
Low level because they are the bare minimum that javascript has to offer,
but you can probably easily build more higher-level constructs on top of it
in haskell.

If you need something more stable/complete for now, I advise you to use GWT
(Google Web Toolkit). It compiles java source code into javascript, taking
care of most browser differences and language oddities, and it has a very
nice library to use (also if you don't use java on the server side. It can
create fully independent client-side code). I know, it's not haskell, but
compared to javascript, java is very safestable.

Mathijs



On Mon, Oct 26, 2009 at 4:04 AM, Casey Hawthorne cas...@istar.ca wrote:

 Is there a way to embed a Haskell interpreter/compiler in a browser.

 I think this would be a safer language than JavaScript.

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

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


[Haskell-cafe] using phantom types to validate html

2009-06-06 Thread Mathijs Kwik
Hi all,

Please have a look at
http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=2575#a2575
I wanted to use the typesystem to mandate businesslogic (in this case
w3c validation rules).
Thanks to some helpful people in #haskell I learned a bit about phantom types.
Please let me know if I implemented them correctly.

Also this little experiment raises some questions:
The code becomes very verbose if there are more elements added or more
rules to check.
Since repetitive code can be a source of error, and hellish to
maintain, I would like to know if there's some way to get this
generated, or maybe there's some meta-programming stuff I don't know
about.
Another thing I can't figure out yet is how to do more advanced
validation rules like an html element cannot have 2 head sections,
or (made up) a span element isn't allowed to be a child(any level
deep) of a p element.

I think this would ask for an exponentially growing number of strange
types and classes. Am I right?

Just to be clear: this is just some practice to use the typesystem.
I'm well aware that just using runtime validation checks will be a lot
easier and clearer in most cases.

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


[Haskell-cafe] Datastructure with some business-rules

2009-06-03 Thread Mathijs Kwik
Hi all,

I'm building a tree-like structure that somewhat resembles a package/
dependency structure as most packagemanagers/ports-systems have them.

It's tree-like (Data.Tree at the moment), but I will probably need to
make some structural changes to allow for more complex stuff like
circular dependencies and stuff like 'alternatives'.

While I'm still on the Tree (nice  simple), I want to explore some
business-rules  validation stuff.
This is a bit of a contrived example:
Let's say that nodes are (NodeType, Int) pairs, where the Nodetype is
just a simple algebraïc type.
Now certain types of nodes are only allowed to 'grow' on top of some
other nodes, but up to 10 levels deep.
So certain nodes are only allowed if one of 10 ancestors is of some
other type.
Or to make this a bit weirder (maybe too contrived): its parent should
have a 'brother' of some type.

Ofcourse I can make a 'validate' function that checks if a tree plays
by the rules, but I would like to put the typesystem to use somehow,
since there aren't that many rules.
So I would like to have an error thrown any time an invalid structure
is used/created instead of having to validate myself every time. I
would like this, because in the future I will need to 'morph' trees
into each other so inbetween steps that exist must still be valid.
First I thought about creating some auto-validate monad that just
validates the result after every step, but before going that way I
would like to make sure this is the way to go.

I understand that Data.Tree (and other functors) just take 1 type
'payload' and they don't mind what's in there, while my 'validation'
rules are about the payload _and_ the place in the tree, so I will
probably have to change a bit here.
Is this at all possible?
Is it ok to do or is a 'external' validation/validation monad clearer?
What would be the way to go?

Thanks for any help!

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