Re: [Haskell-cafe] CFG specification and analysis directly in Haskell

2011-09-30 Thread Heinrich Apfelmus

Anton Tayanovskyy wrote:

John Meacham's frisby library [1] did something similar, though the
technique is not as well-known as it should be.


Looks like an excellent library, thank you!


Note that you don't need to give explicit names to your rules anymore, the
monad can do that for you.


I was using the names for a Show instance. I am assuming there is no
syntax sugar to recover the name of the variable used in a binder as a
String.


Ah, good point. There is no referentially transparent way to recover the 
name of a variable.



Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


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


Re: [Haskell-cafe] haskell i18n best practices

2011-09-30 Thread Ertugrul Soeylemez
Paulo Pocinho poci...@gmail.com wrote:

 I don't know if this is a bad habit, but I had already separated the
 dialogue text in the code with variables holding the respective
 strings. At this time, I thought there could be some other way than
 gettext. Then I figured how to import localisation data, that the
 program loads, from external files. The data type is basically a tuple
 with variable-names associated with strings. This is bit like the
 file-embed package [3].

 Still uncomfortable with i18n, I learned about the article I18N in
 Haskell in yesod blog [4]. I'd like to hear more about it.

 What is considered the best practice for localisation?

I can't help you with best practice for Haskell, and I don't think there
is any.  Gettext is probably the easiest approach, because it integrates
nicely with the rest of the environment.  It automatically uses the
usual LANG and LC_* variables, which are used in Unix-like systems.

An even simpler (but not necessarily easier) approach is to hard-code
the languages in a Map and just look up the string you need.  In this
case you have to code the integration yourself.  It somewhat sounds like
you are targetting the Windows platform anyway.  Personally I'd likely
prefer Gettext for its integration and all the existing translation
tools.

In either case, the best practice is not to work with variables, but
with a default language.  You write your text strings in your default
language (usually English), but wrap them in a certain function call.
The function will try to look up a translated message for the current
language.  This makes both programming and translating easier.  This is
how I imagine it works (or should work):

main :: IO ()
main = do
tr - getTranslator
putStrLn (tr This is a test.)

The 'tr' function is called just '_' in other languages, but you can't
use the underscore in Haskell.  A translater (person) would use a
program to search your entire source code for those translatable
strings, then they would use a translation program, which shows an
English string and asks them to enter the translated string over and
over, until all strings are translated.


Greets,
Ertugrul


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



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


[Haskell-cafe] Indentation problem using Happy

2011-09-30 Thread Amy de Buitléir
I'm trying to use Happy for the first time, and I'm having trouble with this
very simple example:

= BEGIN: PolyParser.y =
{
module Main where

import Char ( isAlpha, isDigit, isSpace )
}
%name calc
%tokentype { Token }
%error { parseError }
%token 
  id  { TokenId $$ }
  ',' { TokenCOMMA }
  wombat  { TokenWombat $$ }
%%
Poly: id ',' wombat
{
parseError :: [Token] - a
parseError _ = error Parse error

data Poly = Poly Int String deriving Show

data Token
  = TokenId Int
  | TokenCOMMA
  | TokenWombat String deriving Show

lexer :: String - [Token]
lexer [] = []
lexer (c:cs) 
  | isSpace c = lexer cs
  | isAlpha c = lexVar (c:cs)
  | isDigit c = lexNum (c:cs)
lexer (',':cs) = TokenCOMMA : lexer cs

lexNum cs = TokenInt (read num) : lexer rest
  where (num,rest) = span isDigit cs

lexVar cs =
   case span isAlpha cs of
  (wombat,rest) - TokenWombat wombat : lexer rest
  (id,rest)   - TokenId id : lexer rest
  
main = getContents = print . calc . lexer
}
= END: PolyParser.y =

The resulting PolyParser.hs has an indentation problem (second-to-last line,
below), so it won't compile.

happyReduce_1 = happySpecReduce_3  4 happyReduction_1
happyReduction_1 _
_
_
 =  HappyAbsSyn4
 (parseError :: [Token] - a
parseError _ = error Parse error

Thank you in advance to anyone who can tell me where I've gone wrong.


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


Re: [Haskell-cafe] haskell i18n best practices

2011-09-30 Thread Felipe Almeida Lessa
On Thu, Sep 29, 2011 at 7:54 PM, Paulo Pocinho poci...@gmail.com wrote:
 Still uncomfortable with i18n, I learned about the article I18N in
 Haskell in yesod blog [4]. I'd like to hear more about it.

Yesod's approach is pretty nice [1].  The idea is to have a data type
with all your messages, like

  data Message =
Hello |
WhatsYourName |
MyNameIs String |
Ihave_apples Int
GoodBye

For each of your supported languages, you provide a rendering function
(they may be in separate source files)

  render_en_US :: Message - String
  render_en_US Hello = Hello!
  render_en_US WhatsYourName = What's your name?
  render_en_US (MyNameIs name) = My name is  ++ name ++ .
  render_en_US (Ihave_apples 0) = I don't have any apples.
  render_en_US (Ihave_apples 1) = I have one apple.
  render_en_US (Ihave_apples n) = I have  ++ n ++  apples.
  render_en_US GoodBye = Good bye!

  render_pt_BR :: Message - String
  render_pt_BR Hello = Olá!
  render_pt_BR WhatsYourName = Como você se chama?
  render_pt_BR (MyNameIs name) = Eu me chamo  ++ name ++ .
  render_pt_BR (Ihave_apples 0) = Não tenho nenhuma maçã.
  render_pt_BR (Ihave_apples 1) = Tenho uma maçã.
  render_pt_BR (Ihave_apples 2) = Tenho uma maçã.
  render_pt_BR (Ihave_apples n) = Tenho  ++ show n ++  maçãs.
  render_pt_BR GoodBye = Tchau!

Given those functions, you can construct something like

  type Lang = String

  render :: [Lang] - Message - String
  render (pt   :_) = render_pt_BR
  render (pt_BR:_) = render_pt_BR
  render (en   :_) = render_en_US
  render (en_US:_) = render_en_US
  render (_:xs) = render xs
  render _ = render_en_US

So 'r = render [fr, pt]' will do the right thing.  You just need
to pass this 'r' around in your code.  Using is easy and clear:

  putStrLn $ r Hello
  putStrLn $ r WhatsYourName
  name - getLine
  putStrLn $ r MyNameIs Alice
  putStrLn $ r (Ihave_apples $ length name `mod` 4)
  putStrLn $ r GoodBye

This approach is nice for several reasons:

 - Builtin support for complicated messages.  Making something like
Ihave_apples in gettext would be hard.  Each language has its own
rules, and you need to encode all of them in your code.  On this
example, my render_pt_BR recognizes and treats differently the 2
apples case.  If you didn't think about it when you wrote your code
(using gettext), you'd need to change your code for pt_BR.

 - Fast processing.  render as I've coded above looks at the
language list just once.  After that, it's just GHC's pattern
matching.

 - Fast startup.  No need to look for strings on the hard drive.

 - Flexible.  You may try several extensions, depending on your needs

(a) Using a type class (like Yesod) if you don't want one big data type.

(b) Using Text instead of String.  Or even Builder.

The biggest drawback is lack of tool support and lack of translators'
expertise.  gettext has a lot of inertia and is used everywhere on a
FLOSS system.  But as Ertugrul Soeylemez said, if you're targeting
Windows, _not_ using gettext should be an advantage (less pain while
create installers).

HTH,

[1] 
http://hackage.haskell.org/packages/archive/yesod-core/0.9.2/doc/html/Yesod-Message.html

-- 
Felipe.

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


[Haskell-cafe] Type family instances in Haddock?

2011-09-30 Thread Sean Leather
Would it be useful/worthwhile to have type/data family instances show up in
Haddock just as type class instances do?

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


[Haskell-cafe] CAL or Frege as a Haskell replacement on JVM?

2011-09-30 Thread Karel Gardas


Hello,

since there is no Haskell compiler/interpreter for JVM yet (considering 
LambdaVM outdated), then the question for kind of Haskell replacement on 
this platform is either CAL[1] or Frege[2]. I'd like to ask here those 
who have used either of those languages for your experience with 
it/them, what's more similar to Haskell (at least from your point of 
view) and what you like more as a Haskell replacement on JVM.


Thanks!
Karel

[1]: http://openquark.org/Welcome.html
[2]: http://code.google.com/p/frege/

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


Re: [Haskell-cafe] Programming with arrows, exercises

2011-09-30 Thread Sergey Mironov
2011/9/30 John Lask jvl...@hotmail.com:
 On 30/09/2011 7:15 AM, Sergey Mironov wrote:

 Hello. I am reading Programming with Arrows by John Hughes (very
 helpful and interesting!), the book has an exercises requiring a
 module called Circuits for checking the answer. There should be things
 like class ArrowCircuit and various functions related to digital logic
 circuits simulation.  Does anybody know where can I find one?

 Thanks,
 Sergey

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



 This was in the old arrows library I have attached a copy, it will probably
 need modification to compile.

 You should be able to use the examples with the current arrows library with
 a few mods.


Yes, looks quite old. Unfotinately, it doesn't match the book.. I
found that  module I was looking for is in Appendix! Should I be more
attentive.. Anyway, thank you!

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


[Haskell-cafe] Handy abbreviations for using SciTE with Haskell

2011-09-30 Thread Amy de Buitléir
I often use SciTE for editing Haskell code. I wanted an easy way to type symbols
such as ∀ (instead of forall), so I created a properties file that allows me
to do that. I haven't seen anything similar online (I Googled first), so I made
the code available online.

You can find the file and instructions here:
http://www.haskell.org/haskellwiki/Tips_for_using_SciTE_with_Haskell



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


[Haskell-cafe] module - package

2011-09-30 Thread Roman Beslik
Hello. How can I find which installed package a specified module belongs 
to? ghci or cabal or ghc-pkg?


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


Re: [Haskell-cafe] module - package

2011-09-30 Thread Daniel Fischer
On Friday 30 September 2011, 21:04:48, Roman Beslik wrote:
 Hello. How can I find which installed package a specified module belongs
 to? ghci or cabal or ghc-pkg?

$ ghc-pkg find-module Foo.Bar.Baz


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


Re: [Haskell-cafe] haskell i18n best practices

2011-09-30 Thread Rogan Creswick
On Thu, Sep 29, 2011 at 3:54 PM, Paulo Pocinho poci...@gmail.com wrote:
 Hello list.

 I've been trying to figure a nice method to provide localisation. An

The grammatical framework excels at translation and localization -- it
probably has the highest learning curve of the options; but it will
generate the best / most accurate text depending on the target
language:

 * http://www.grammaticalframework.org

At first brush, it may seem like extreme overkill; but it is able to
handle many, many infuriating corner cases (eg: properly forming
discontinuous constituents, updating case / tense and number to agree
with potentially variable quantities and genders, addressing the
absence of yes and no in some languages, etc...)

The language processing bits are expressed in a PMCFG grammar, which
uses a syntax similar to haskell.  The PMCFG compiles to a PGF file
that can be loaded and used by a haskell module that implements the
runtime, so it doesn't change your run-time requirements (if you
already rely on haskell, there are also runtime implementations in
javascript, java, c and python).

--Rogan

 application is deployed using a conventional installer. The end-user
 is not required to have the Haskell runtimes, compiler or platform.
 The application should bundle ready to use translation data. What I am
 after is simple; an intuitive way that an interested translator, with
 little knowledge of Haskell, can look at and create valid translation
 data.

 This is what I've been looking at lately. The first thing I noticed
 was the GNU gettext implementation for Haskell. The wiki page [1] has
 a nice explanation by Aufheben. The hgettext package is found here
 [2].

 I don't know if this is a bad habit, but I had already separated the
 dialogue text in the code with variables holding the respective
 strings. At this time, I thought there could be some other way than
 gettext. Then I figured how to import localisation data, that the
 program loads, from external files. The data type is basically a tuple
 with variable-names associated with strings. This is bit like the
 file-embed package [3].

 Still uncomfortable with i18n, I learned about the article I18N in
 Haskell in yesod blog [4]. I'd like to hear more about it.

 What is considered the best practice for localisation?

 --
 [1] 
 http://www.haskell.org/haskellwiki/Internationalization_of_Haskell_programs
 [2] http://hackage.haskell.org/packages/archive/hgettext/
 [3] http://hackage.haskell.org/package/file-embed
 [4] http://www.yesodweb.com/blog/2011/01/i18n-in-haskell

 ___
 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 i18n best practices

2011-09-30 Thread Felipe Almeida Lessa
On Fri, Sep 30, 2011 at 5:44 PM, Rogan Creswick cresw...@gmail.com wrote:
 The grammatical framework excels at translation and localization -- it
 probably has the highest learning curve of the options; but it will
 generate the best / most accurate text depending on the target
 language:

  * http://www.grammaticalframework.org

 At first brush, it may seem like extreme overkill; but it is able to
 handle many, many infuriating corner cases (eg: properly forming
 discontinuous constituents, updating case / tense and number to agree
 with potentially variable quantities and genders, addressing the
 absence of yes and no in some languages, etc...)

 The language processing bits are expressed in a PMCFG grammar, which
 uses a syntax similar to haskell.  The PMCFG compiles to a PGF file
 that can be loaded and used by a haskell module that implements the
 runtime, so it doesn't change your run-time requirements (if you
 already rely on haskell, there are also runtime implementations in
 javascript, java, c and python).

I've seen GF before, but I can't actually see how one would use it for
localization.  Are there any simple examples?

Cheers, =)

-- 
Felipe.

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


Re: [Haskell-cafe] [Haskell] mapM with Traversables

2011-09-30 Thread Ryan Ingram
You can use Data.Sequence.fromList to go [a] - Seq a, though.

So given

f :: Monad m = a - m b

you have

import Data.Traversable as T
import Data.Sequence as S

g :: Monad m = [a] - m (S.Seq b)
g = T.mapM f . S.fromList

  - ryan

On Wed, Sep 28, 2011 at 6:20 PM, Marc Ziegert co...@gmx.de wrote:

 Hi Thomas,
 this should be on the haskell-cafe or haskell-beginners mailing list.
 Haskell@... is mainly for announcements.


 You have:
  f :: Monad m =
   a - m b
  Data.Traversable.mapM :: (Monad m, Traversable t) =
   (a - m b) - t a - m (t b)

 So, if you define g with
  g a = do Data.Traversable.mapM f a
  or in short
  g = Data.Traversable.mapM f
 , then the type will be
  g :: (Monad m, Traversable t) =
   t a - m (t b)
 instead of
  g :: [a] - m (Seq b)
 .

 Try using ghci to find these things out. It helps to get not confused with
 the types.


 Besides the missing Monad context, g misses a generic way to convert
 between different Traversables, which does not exist. You can only convert
 from any Traversable (imagine a Tree) toList; not all Traversables have a
 fromList function.
 For conversion, you might want to use Foldable and Monoid, fold to untangle
 and mappend to recombine; but any specific fromList function will surely
  be more efficient.

 Regards
 - Marc



  Original-Nachricht 
  Datum: Wed, 28 Sep 2011 17:27:58 -0600
  Von: thomas burt thedwa...@gmail.com
  An: hask...@haskell.org
  Betreff: [Haskell] mapM with Traversables

  Hi -
 
  I have a function, f :: Monad m = a - m b, as well as a list of a's.
  I'd
  like to produce a sequence (Data.Sequence) of b's, given the a's:
 
  g :: [a] - m (Seq b)
  g a = do Data.Traversable.mapM f a   -- type error!
 
  I see that Data.Traversable.mapM f a doesn't work... is this like
 asking
  the compiler to infer the cons/append operation from the type signature
 of
  g?
 
  Do I need to write my own function that explicitly calls the append
  functions from Data.Sequence or can I do something else that would work
  for
  any g :: Traversable t, Traversable u = t a - m (u b) given f :: a
 -
  m
  b?
 
  Thanks for any comments!
  Thomas

 ___
 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 i18n best practices

2011-09-30 Thread Rogan Creswick
On Fri, Sep 30, 2011 at 2:09 PM, Felipe Almeida Lessa
felipe.le...@gmail.com wrote:
 On Fri, Sep 30, 2011 at 5:44 PM, Rogan Creswick cresw...@gmail.com wrote:
 The grammatical framework excels at translation and localization -- it
 probably has the highest learning curve of the options; but it will
 generate the best / most accurate text depending on the target
 language:

  * http://www.grammaticalframework.org

 At first brush, it may seem like extreme overkill; but it is able to
 handle many, many infuriating corner cases (eg: properly forming
 discontinuous constituents, updating case / tense and number to agree
 with potentially variable quantities and genders, addressing the
 absence of yes and no in some languages, etc...)

 The language processing bits are expressed in a PMCFG grammar, which
 uses a syntax similar to haskell.  The PMCFG compiles to a PGF file
 that can be loaded and used by a haskell module that implements the
 runtime, so it doesn't change your run-time requirements (if you
 already rely on haskell, there are also runtime implementations in
 javascript, java, c and python).

 I've seen GF before, but I can't actually see how one would use it for
 localization.  Are there any simple examples?

Here's a *very* simple example I just threw together, based on the
Foods grammar (so it's quite contrived), but hopefully it's sufficient
for the moment:

https://github.com/creswick/gfI8N

Updating it to use the Phrasebook example would make it much more
interesting... I think there are numbers in there, and iirc, it uses
the actual resource grammars, which is what you really want for a real
system.

Usage details in the README.md, and I've commented the important
function in the haskell source.  The rest of the magic is in the (also
ugly) Setup.hs.

You will also need to manually install gf, I believe, even if you use
cabal-dev, due to some annoyingly complex (but solveable) build-order
and PATH complications.

--Rogan

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


[Haskell-cafe] Static linking for machines that don't have Haskell

2011-09-30 Thread Roshan James
Hi All,

I am trying to run a Haskell program compiled on my Ubuntu box on a server
box that does not have GHC installed and where I dont have root privileges.
I run into several missing libraries, in particular libgmp, libffi and
libuuid (the later two are needed by my program). How I can statically link
my program such that I can run it on this server?

I have a tried static linking as follows:
*  ghc -static -optl-static -optl-pthread --make -o p main.hs*

This gives me several warnings of the form:
*/usr/lib/haskell-packages/ghc6/lib/network-2.2.1.7/ghc-6.12.3/libHSnetwork-2.2.1.7.a(BSD.o):
In function `sw4B_info':*
*(.text+0x584c): warning: Using 'getservbyport' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking*

And sure enough the generated executable segfaults on the server which has a
different glibc version.

Is there some way to static link all the other libraries needed except
glibc? I have looked around for an example of this but to no avail and the
output of the -v switch seemed a bit overwhelming. Or is there some other
way to go about doing this?

thanks in advance,
Roshan

ps. including these, in case they maybe of some use:

My machine:

*$ ldd p*
* linux-vdso.so.1 =  (0x7fff3000)*
* libncurses.so.5 = /lib/libncurses.so.5 (0x7fbdbbf4f000)*
* libuuid.so.1 = /lib/x86_64-linux-gnu/libuuid.so.1 (0x7fbdbbd4a000)*
* librt.so.1 = /lib/x86_64-linux-gnu/librt.so.1 (0x7fbdbbb41000)*
* libutil.so.1 = /lib/x86_64-linux-gnu/libutil.so.1 (0x7fbdbb93e000)*
* libdl.so.2 = /lib/x86_64-linux-gnu/libdl.so.2 (0x7fbdbb73a000)*
* libpthread.so.0 = /lib/x86_64-linux-gnu/libpthread.so.0
(0x7fbdbb51b000)*
* libgmp.so.3 = /usr/lib/libgmp.so.3 (0x7fbdbb2be000)*
* libffi.so.5 = /usr/lib/libffi.so.5 (0x7fbdbb0b6000)*
* libm.so.6 = /lib/x86_64-linux-gnu/libm.so.6 (0x7fbdbae3)*
* libc.so.6 = /lib/x86_64-linux-gnu/libc.so.6 (0x7fbdbaa9c000)*
* /lib64/ld-linux-x86-64.so.2 (0x7fbdbc1b5000)*

Server:

*$ ldd p*
*./p: /lib64/libuuid.so.1: no version information available (required by
./p)*
*linux-vdso.so.1 =  (0x7fffc51fd000)*
*libncurses.so.5 = /usr/lib64/libncurses.so.5 (0x0037bce0)*
*libuuid.so.1 = /lib64/libuuid.so.1 (0x0037b720)*
*librt.so.1 = /lib64/librt.so.1 (0x0037b5a0)*
*libutil.so.1 = /lib64/libutil.so.1 (0x0037bda0)*
*libdl.so.2 = /lib64/libdl.so.2 (0x0037b4a0)*
*libpthread.so.0 = /lib64/libpthread.so.0 (0x0037b520)*
*libgmp.so.3 = not found*
*libffi.so.5 = not found*
*libm.so.6 = /lib64/libm.so.6 (0x0037b4e0)*
*libc.so.6 = /lib64/libc.so.6 (0x0037b460)*
*/lib64/ld-linux-x86-64.so.2 (0x0037b420)*
*
*
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe