Re: [Haskell-cafe] reasons why Template Haskell does not propose something similar to Python exec() or eval()

2013-08-24 Thread Tobias Dammers
IIRC you can use haskell-src-exts to parse a string into TH AST structures.
There might even be a quasi-quoter for that; I don't have a real computer
at hand right more, so you'll need to do some research of your own.
On Aug 24, 2013 11:37 AM, TP paratribulati...@free.fr wrote:

 Hi everybody,

 I continue to learn and test Template Haskell (one more time thanks to John
 Lato for his post at:

 http://www.mail-archive.com/haskell-cafe@haskell.org/msg106696.html

 that made me understand a lot of things).

 I have a question about the way Template Haskell is working. Why Template
 Haskell does not propose something similar to Python (or bash) exec() or
 eval(), i.e. does not offer the possibility to take a (quoted) string in
 input, to make abstract syntax in output (to be executed later in a splice
 $()).
 For example, in Python, to make an affectation 'a=a' programatically, I
 can simply do (at runtime; even if I am here only concerned with what
 Template Haskell could do, i.e. at compile time):
  def f(s): return '%s = \'%s\'' % (s,s)
  exec(f(a))
  a
 'a'

 With Template Haskell, I am compelled to make a function returning the
 abstract syntax corresponding to variable declaration:

 ValD (VarP $ mkName s) (NormalB $ LitE $ StringL s)

 (see complete example in Post Scriptum).
 This works fine, but it is less direct. I am sure that the Template Haskell
 approach has many advantages, but I am unable to list them. I think it is
 important to have the reasons in mind. Could you help me?

 Thanks in advance,

 TP


 PS: the complete Haskell example:

 ---
 module MakeVard where
 import Language.Haskell.TH

 makeVard :: Monad m = String - m [Dec]
 -- Equivalent to %s = \%s\
 makeVard s = return [ ValD (VarP $ mkName s) (NormalB $ LitE $ StringL s)
 []
 ]
 ---

 tested by

 ---
 {-# LANGUAGE TemplateHaskell #-}
 import MakeVard

 $(makeVard a)

 main = do

 print a
 ---

 resulting in
 $ runghc -ddump-splices test.hs
 test_makeVar.hs:1:1: Splicing declarations
 makeVard a
   ==
 test_makeVar.hs:4:3-14
 a = a
 a


 ___
 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] Errors in non-monadic code

2013-08-19 Thread Tobias Dammers
Except that people generally don't seem to agree what constitutes
'exceptional', even when disregarding the python world...
On Aug 19, 2013 9:24 PM, Brandon Allbery allber...@gmail.com wrote:

 On Mon, Aug 19, 2013 at 2:59 PM, jabolo...@google.com wrote:

 I'd say that if you were in the context of the IO monad, maybe you'd
 prefer to use exceptions instead of 'Either' or 'Maybe'.


 Even in IO, exceptions should be reserved for truly exceptional conditions
 (of the program cannot safely continue variety), not merely for error
 checking when this can be described as a normal flow of evaluation.
 Exceptions are not simply alternative flow of control, even in procedural
 languages; they are *disruptions* of flow of control.

 --
 brandon s allbery kf8nh   sine nomine
 associates
 allber...@gmail.com
 ballb...@sinenomine.net
 unix, openafs, kerberos, infrastructure, xmonad
 http://sinenomine.net

 ___
 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] inv f g = f . g . f

2013-08-17 Thread Tobias Dammers
Note that at least for the dropWhile example, there is a specialized
function, dropWhileEnd, which is most likely more efficient than reversing
the list twice.
On Aug 17, 2013 3:35 PM, Tom Ellis 
tom-lists-haskell-cafe-2...@jaguarpaw.co.uk wrote:

 On Sat, Aug 17, 2013 at 11:11:07AM +0200, Christopher Done wrote:
  Anyone ever needed this? Me and John Wiegley were discussing a decent
  name for it, John suggested inv as in involution. E.g.
 
  inv reverse (take 10)
  inv reverse (dropWhile isDigit)
  trim = inv reverse (dropWhile isSpace) . dropWhile isSpace

 This sounds like a job for a lens, or similar.

 Tom


 ___
 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] Alternative name for return

2013-08-06 Thread Tobias Dammers
It is a pure value in the context of the outer monad (the one you wrap it
in). I'd say pure is still appropriate.
On Aug 6, 2013 10:14 AM, Tom Ellis 
tom-lists-haskell-cafe-2...@jaguarpaw.co.uk wrote:

 On Tue, Aug 06, 2013 at 10:03:04AM +0200, J. Stutterheim wrote:
  `putStrLn Hi` is not a pure value...

 Why not?

 ___
 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] Open Source project suitable for 2-3 persons this fall?

2013-07-05 Thread Tobias Dammers
There's one of my hobby projects that could use some manpower to
bootstrap it into a production-quality tool. It's an HTML templating
system; right now it reads input templates in one of two languages (one
very declarative, very similar to Python's jinja2, the other being a
locally-pure functional language with a curly-bracket syntax), and it
can output PHP and JavaScript as well as execute templates directly in
Haskell code. There's also a rather experimental JSON-based intermediate
format, designed for high-security scenarios (JSON can be parsed
quickly, but because it cannot contain arbitrary code, a compromised
compiler can be mitigated by whitelisting what the runtime can do; this
way, only the runtime has to be audited, not the compiler).

There is an incomplete implementation of a PHP library that can
interpret this intermediate JSON format, but it hasn't been used in any
production-quality project yet.

The core part is the compiler, consisting of a
Parsec-based parser, an AST, an optimizer, and a few backends.

The unique selling points:

* Pre-compile your templates - now you can have the cake (expressive
  clean template language) and eat it too (great performance, because
  it's pre-compiled to your web app's native language).
* Use the same template for PHP, Haskell and JavaScript (and maybe
  others, too).
* Bye bye XSS: HTML-encoding is the default.
* Extensible: Hook up your own native functions - it's as simple as
  adding a function to your template input data, then calling it inside
  the template.

It could use some work in a lot of areas; projects could include, for
example:

- Getting the JavaScript backend to support 100% of the language
  features (right now, only the direct-execution and PHP backends pass
  all tests)
- Implement some glue to allow easy embedding in Haskell web
  applications (yesod / happstack / snap)
- Add more features to the input language (some of which would also
  require some changes to the backends), e.g.:
  - range literals
  - list comprehensions
  - indexed for-each, or some way of getting the current iteration's
index; very useful for things like zebra-stripe data grids and
such
- Add other backends (Python and Ruby would be the most obvious
  candidates, but I'm really open to anything)
- Add more library functions
- A better optimizer
- Some tooling and integration support, e.g. some kind of mechanism to
  switch between executing on-the-fly (for development) and using
  pre-compiled templates (for production), something to implement
  graceful degrading on the client side (use client-side templates when
  possible, fall back to postbacks and server-side templates as needed),
  syntax highlighters for popular editors, etc.

Anyway, here's the source:

https://bitbucket.org/tdammers/hpaco

The PHP lib/script that can produce and run a subset of the JSON
intermediate format is here:

https://bitbucket.org/tdammers/phpaco

(Any contributions, feedback, etc., very welcome)

On Thu, Jul 04, 2013 at 05:26:59PM +0200, Anders Bech Mellson wrote:
 Is there any project that needs working this fall which could be used as a
 university project?
 
 I am in the university (M.Sc. in software development),
 so I am mainly looking for project ideas (preferably concrete ones).
 
 We are 2-3 students that have ~10 hours pr week for 3 months to work on a
 project.
 
 Is there a listing somewhere with project ideas for contributing to the
 Haskell community?
 
 Thanks in advance,
 Anders

 ___
 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] tangential request...

2013-06-24 Thread Tobias Dammers
On Sun, Jun 23, 2013 at 09:18:18PM -0700, Mark Lentczner wrote:
 Thanks all, I’ve got what I needed.
 
 Brief results; Big variety in window and text sizes, but very few font and
 color choices. More than half the terminals seem to be basically default
 settings.

Well, there's only so many monospace fonts that are beautiful,
reasonably unicode-complete, easy on the eyes, programming-friendly AND
free (-ish). Also, the default for the most popular terminal emulators
on Linux (e.g. xterm, rxvt) is actually a bitmap font.

 Finally, 15% seem to be using horrid bitmap console fonts. _How can you
 stand to look at them?!?!_ (Don't worry, you'll have Plush soon enough...)
 ​

Controversial topic there, tread carefully ;) . Lots of folks are borderline
militant when it comes to their terminal fonts, whether they're
bitmapped or not. Also, white-on-black vs. black-on-white seems to be an
emotionally-charged question.

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


Re: [Haskell-cafe] tangential request...

2013-06-24 Thread Tobias Dammers
On Mon, Jun 24, 2013 at 04:09:22PM +0100, Tom Ellis wrote:
 On Mon, Jun 24, 2013 at 08:02:17AM -0700, Mark Lentczner wrote:
  And yet, just four fonts make up over 75% of the sample - and two of those
  are essentially identical!
 
 Inconsolata and Consolas?

My bet:

- Bitstream Vera Sans Mono
- DejaVu Sans Mono
- Inconsolata
- Whatever the default terminal font is on OS X

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


Re: [Haskell-cafe] loop error message

2013-06-22 Thread Tobias Dammers
On Sat, Jun 22, 2013 at 06:09:58AM +0300, Mihai Maruseac wrote:
 On Sat, Jun 22, 2013 at 12:41 AM, Omari Norman om...@smileystation.com 
 wrote:
  I compiled some code with GHC 7.6.3 that produces a simple error at runtime
 
  myProgramName: loop
 
  At which point the program exits with code 1.
 
  Is there documentation for this error anywhere? Does it mean I have some
  infinite loop in my code somewhere? If so, does GHC catch all infinite
  loops? I have never gotten this error before. Thanks.
 
 Hi,
 
 Indeed, you have an infinite loop in your code. However, not all
 infinite loops are catcheable by the mechanism employed there, it
 would be very hard to do so.

Some are even impossible to catch at all, a.k.a. the Halting Problem.

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


Re: [Haskell-cafe] data constructor names

2013-06-22 Thread Tobias Dammers
On Sat, Jun 22, 2013 at 12:15:07PM +0100, Tom Ellis wrote:
 On Sat, Jun 22, 2013 at 04:26:14AM -0500, Brian Lewis wrote:
  Say you write
  data Callback = Error ... | ...
 [...]
  
  Then, later, you write
  data Error = ...
 [...]
  
  They're both good names, but there's a conflict.
 
 What do you mean by a conflict?  That's fine as far as the compiler is
 concerned because constructors live in a different namespace from types.
 

I think he meant something like:

data Callback = Error Error | Success

data Error = Error String

...in which case there is a clash for the identifier Error at the
value level.

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


Re: [Haskell-cafe] ANN: Nomyx 0.2 beta, the game where you can change the rules

2013-06-19 Thread Tobias Dammers
On Wed, Jun 19, 2013 at 01:18:54PM +0200, Corentin Dupont wrote:
 Thanks Brent! I'm glad you like it.
 You will win a lot of money if new players come :)
 Indeed Brent proposed a rule that allows sponsorship: if you invite a
 player in, you win 50 ECU...

Joined a game, though I don't really have time to look into it right
now. 

One thing though: It appears that the game sends multipart/alternative
e-mail messages, where the text/plain part is completely empty (0
bytes). Since I've configured my mail client to prefer text/plain over
text/html, this is kind of inconvenient.

Otherwise, good job. I'm curious where this is going.


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


Re: [Haskell-cafe] Automating Hackage accounts

2013-06-13 Thread Tobias Dammers
On Thu, Jun 13, 2013 at 09:44:03AM -0400, Andrew Pennebaker wrote:
 Could we add an HTML form for creating new Hackage accounts? Right now, our
 community is small enough that emailing r...@soi.city.ac.uk and waiting for
 a manual response isn't too bad of a problem, but as we grow, it would be
 nice for these sorts of things to be handled by a server, like with
 RubyGems and NPM.

IMHO, a more pressing issue is SSL uploads and package signing. As it
stands, anyone with a Hackage account can upload a new version of any
given package, and some wire-sniffing is enough to reveal a legit user's
password.

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


Re: [Haskell-cafe] Automating Hackage accounts

2013-06-13 Thread Tobias Dammers
On Thu, Jun 13, 2013 at 05:07:38PM +0300, Mihai Maruseac wrote:
 On Thu, Jun 13, 2013 at 5:02 PM, Tobias Dammers tdamm...@gmail.com wrote:
  On Thu, Jun 13, 2013 at 09:44:03AM -0400, Andrew Pennebaker wrote:
  Could we add an HTML form for creating new Hackage accounts? Right now, our
  community is small enough that emailing r...@soi.city.ac.uk and waiting for
  a manual response isn't too bad of a problem, but as we grow, it would be
  nice for these sorts of things to be handled by a server, like with
  RubyGems and NPM.
 
  IMHO, a more pressing issue is SSL uploads and package signing. As it
  stands, anyone with a Hackage account can upload a new version of any
  given package, and some wire-sniffing is enough to reveal a legit user's
  password.
 
 I'd try to solve the latest two things first before going into
 creating a specific form.
 
 On the other hand, maybe we can rig something up with Yesod or similar
 to solve all three points at the same time. I'm busy now with my
 masters disertation but I can attempt something in a month if it seems
 ok and no one else does it before that date.

IIRC, there have been previous attempts, or at least a discussion. I
can't remember what the result was, though.

Either way, it'll take more than just a Yesod web application built over
a weekend; signed packages would require package authors to, well, sign,
so cabal would need features for that; you'd also have to extend it to
*check* those signatures, and give the user options to refuse or allow
unsigned packages. SSL should be relatively simple though, mostly a
matter of updating cabal's configuration and installing a suitable
certificate on the hackage server.

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


Re: [Haskell-cafe] (no subject)

2013-06-10 Thread Tobias Dammers
On Mon, Jun 10, 2013 at 05:41:05PM +0530, Zed Becker wrote:
 
  Haskell, is arguably the best example of a design-by-committee language.

You do realize that design-by-committee is generally understood to
refer to the antipattern where a committee discusses a design to death
and delivers an inconsistent, mediocre spec, as opposed to a situation
where a leader figure takes the loose ends, runs with them, and turns
them into a coherent, inspiring whole?

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


Re: [Haskell-cafe] whats with cabal and libgmp.so.3

2013-05-14 Thread Tobias Dammers
On Tue, May 14, 2013 at 01:16:44PM +0530, Rustom Mody wrote:
 Today cabal suddenly started giving me errors that libgmp.so.3 is not found
 Moving away my old .cabal makes it work again
 
 Any explanations?
 
 [I am on debian testing. I think the causing factor was that debian
 switched major versions recently.
 There were a lot of updates... Nothing that looked like it was related to
 ghc]

That could very well be the cause. My guess is that jessie has a
different libgmp than wheezy. The stuff in your .cabal was linked
against the version from wheezy, but now it's gone because of the dist
upgrade (of which cabal is unaware); recompiling everything and linking
against the new version fixes it.

If you want to be sure, see if apt updated libgmp as part of the dist
upgrade.

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


Re: [Haskell-cafe] ANN: Robot - Simulate keyboard and mouse events under X11

2013-05-09 Thread Tobias Dammers
On Thu, May 09, 2013 at 01:36:52PM +1200, Chris Wong wrote:
 
 On Tue, May 7, 2013 at 5:18 AM, Jeanne-Kamikaze
 jeannekamik...@gmail.com wrote:
  Looks like an interesting library. Will it be able to read pixels from a
  window at some point?
 
 Not sure -- I have no idea how screen capturing works in X11. Calling
 gnome-screenshot should probably cover most use cases.

I just took 2 minutes looking at the source code for scrot (which is
about as simplistic a screen grabber as you'll find), and it looks
fairly simple: it uses giblib, which provides a function called
gib_imlib_create_image_from_drawable, which does exactly that. Not sure
if Haskell bindings for giblib exist already though.

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


Re: [Haskell-cafe] Hackage checking maintainership of packages

2013-05-06 Thread Tobias Dammers
On Mon, May 06, 2013 at 08:14:59PM +0800, Niklas Hambüchen wrote:
 On 06/05/13 20:06, Tillmann Rendel wrote:
  Is a human clicked the check box a good metric for a human commits
  themselves to this package?
 
 If the check box has the text Do you want this thing to be called
 'maintained' on Hackage next to it, yes.

The problem is that people tend to (truthfully) check such a box, then
stop maintaining the package for whatever reasons, and never bother
unchecking the box.

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


Re: [Haskell-cafe] Backward compatibility

2013-05-03 Thread Tobias Dammers
On Fri, May 03, 2013 at 01:23:55PM +0300, Guy wrote:
 That's what I thought of when I saw the original complaint - GHC is
 too backwards compatible! There's far too much boilerplate because
 of the Functor = Applicative = Monad mess. Float/Double being
 Enums is ridiculous. None of this gets fixed because of the fear
 that new GHC won't compile old code.

 
 PS The proposal to fix Functor = Applicative = Monad has patches
 attached for GHC and base, but the backwards compatibility bogeyman
 always seems to trump something that will break a lot of code.

This kind of breaks everything changes would require something similar
to what Python is doing with the 2 - 3 transition, and considering how
painfully slowly it is progressing there, I understand perfectly well why
people don't want to go there.

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


Re: [Haskell-cafe] Backward compatibility

2013-05-03 Thread Tobias Dammers
On Fri, May 03, 2013 at 03:35:08PM +0100, Ozgur Akgun wrote:
 Hi,
 
 On 3 May 2013 11:43, Tobias Dammers tdamm...@gmail.com wrote:
 
   PS The proposal to fix Functor = Applicative = Monad has patches
   attached for GHC and base, but the backwards compatibility bogeyman
   always seems to trump something that will break a lot of code.
 
  This kind of breaks everything changes would require something similar
  to what Python is doing with the 2 - 3 transition, and considering how
  painfully slowly it is progressing there, I understand perfectly well why
  people don't want to go there.
 
 
 There is one very big advantage in the Haskell-world though.
 Most of the struggle will be at the compile time. The biggest headache
 caused by
 the Python 2 - 3 transition is how you get a runtime error 2 weeks after
 you think
 you've fixed everything!
 
 (Yeah, I know code coverage analysis is an option when you don't have static
 type checking, but ...)

Well; this is an additional problem that comes with the pragmatic choice
for a language that doesn't believe in type checking and compile-time
guarantees, but I think it is largely orthogonal. At least
theoretically, you could have 100% test coverage, which would put the
Python project in the same situation as the Haskell one (except that the
tests themselves would also have to be converted...)

The problem I'm talking about, though, is that such a change would split
the ecosystem in two (say, Traditional Haskell and Functor-Correct
Haskell), just like the 2/3 separation is all over the Python ecosystem
and causes all sorts of headaches. Should I be using Python 2 or 3 is
not a question that has a simple answer, and that *is* a problem.

 
 Cheers,
 Ozgur

 ___
 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