Re: [Haskell-cafe] Anyone recommend a VPS?

2010-02-01 Thread Pasqualino Titto Assini
In Europe, http://www.ovh.com has quite good prices.

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


[Haskell-cafe] Re: OT: Literature on translation of lambda calculus to combinators

2010-02-01 Thread Torsten Grust
Dear all,

Dušan Kolář kolar at fit.vutbr.cz writes:
 [...] 
  Could anyone provide a link to some paper/book (electronic version of 
 both preferred, even if not free) that describes an algorithm of 
 translation of untyped lambda calculus expression to a set of 
 combinators? Preferably SKI or BCKW. I'm either feeding google with 
 wrong question or there is no link available now...

13 years ago (ugh...) I've posted a tutorial-style treatment of the 
compilation of Dave Turner's SASL to SKI.  Also addresses reduction 
and simple optimizations of the resulting SKI programs.

http://www-db.informatik.uni-tuebingen.de/files/publications/sasl.ps.gz

Cheers,
   —Torsten






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


Re: [Haskell-cafe] Trapping getChar before echo

2010-02-01 Thread Mark Spezzano
I've tried this example and it just lets me type in anything in CAPITALS, which 
is nice, but Delete key doesn't delete and the arrow keys unfortunately let me 
manoeuvre the cursor all over the screen. Also the biggest problem is that 
Enter doesn't terminate the input session.

Isn't there a simple way to do something like this?

Surely Haskell must have a standard getLine function that support CAPITALS and 
backspacing and no arrow keys. Arrows keys with history would be nice.

Mark


On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:

 Michael Hartl wrote:
 import System.IO
 import Data.Char
 
 main = do
  hSetEcho stdin False
  hSetBuffering stdin NoBuffering
  hSetBuffering stdout NoBuffering
  scanLine
  where scanLine = do   c - hGetChar stdin
  putChar . toUpper $ c
  scanLine
  
 
 Last time I tried something like this [on Windows], it didn't seem to work. I 
 wanted to trap arrow keys and so forth, but they seem to be being used for 
 input history. (I.e., pressing the up-arrow produces previously-entered lines 
 of text, and none of this appears to be reaching the Haskell program itself.) 
 Has this changed since I tried it last year?
 
 ___
 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] Anyone recommend a VPS?

2010-02-01 Thread Peter Robinson
I use http://www.bytemark.co.uk/ and I'm quite satisfied. They offer
Ubuntu, Debian and CentOS.

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


Re: [Haskell-cafe] Trapping getChar before echo

2010-02-01 Thread Lyndon Maydwell
It might be worth looking at something like a curses library.

On Mon, Feb 1, 2010 at 4:45 PM, Mark Spezzano
mark.spezz...@chariot.net.au wrote:
 I've tried this example and it just lets me type in anything in CAPITALS, 
 which is nice, but Delete key doesn't delete and the arrow keys unfortunately 
 let me manoeuvre the cursor all over the screen. Also the biggest problem is 
 that Enter doesn't terminate the input session.

 Isn't there a simple way to do something like this?

 Surely Haskell must have a standard getLine function that support CAPITALS 
 and backspacing and no arrow keys. Arrows keys with history would be nice.

 Mark


 On 31/01/2010, at 11:27 PM, Andrew Coppin wrote:

 Michael Hartl wrote:
 import System.IO
 import Data.Char

 main = do
  hSetEcho stdin False
  hSetBuffering stdin NoBuffering
  hSetBuffering stdout NoBuffering
  scanLine
      where scanLine = do               c - hGetChar stdin
              putChar . toUpper $ c
              scanLine


 Last time I tried something like this [on Windows], it didn't seem to work. 
 I wanted to trap arrow keys and so forth, but they seem to be being used for 
 input history. (I.e., pressing the up-arrow produces previously-entered 
 lines of text, and none of this appears to be reaching the Haskell program 
 itself.) Has this changed since I tried it last year?

 ___
 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] OT: Literature on translation of lambda calculus to combinators

2010-02-01 Thread Matthias Görgens
Dear Dušan,

You can also find an algorithm in everyone's favourite book in
combinatorial logic To Mock a Mockingbird
(http://en.wikipedia.org/wiki/To_Mock_a_Mockingbird).

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


Re: [Haskell-cafe] Determining application directory

2010-02-01 Thread Vladimir Matveev
I wrote several times that I want determine application directory under
Windows only. Unix version will store its config in predefined location, 
in /etc. Anyway, one not subscribed man wrote me about special library
to solve this problem - http://hackage.haskell.org/package/executable-path

On Fri, Jan 29, 2010 at 11:16:25AM -0800, Scott A. Waterman wrote:
 'FindBin' is also useful.
 http://hackage.haskell.org/package/FindBin
 
 While System.Directory is quite useful, it doesn't contain a
 function to obtain
 the directory in which the running program lives.   You can get the
 current
 (working) directory (e.g. unix's 'getpwd'), and you can try to find an
 executable by searching the $PATH, but you can't find the program you
 are currently running.
 
 --ts
 
 On Jan 27, 2010, at 9:06 AM, Matveev Vladimir wrote:
 
 Hi,
 I'm writing cross-platform application in Haskell which should be
 running under Windows and Linux. Under Linux configuration is stored
 in the /etc directory, and under Windows configuration is meant to
 be in
 the application directory. So, is there a way to get an application
 directory path under Windows? I remember that there is a way to do
 this
 using WinAPI, but how to do this 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] Anyone up for Google SoC 2010?

2010-02-01 Thread Edward Kmett
I would happily participate as a mentor again and I am willing to step up as
administrator if you want to get it off your plate.

-Edward Kmett

On Sun, Jan 31, 2010 at 6:04 AM, Malcolm Wallace 
malcolm.wall...@cs.york.ac.uk wrote:

 Google has announced that the Summer of Code programme will be running
 again this year.  If haskell.org people would like to take part again this
 year, then we need volunteers:

 First,
* suggestions for suitable projects
  (in the past this was organised using a reddit)
* an administrator to co-ordinate the application to Google
  (I have done it for the last three years but am very willing
   to hand on to someone else)

 Google will accept applications from organisations in the period 8th - 12th
 March 2010, approx 1900UTC.

 If haskell.org is accepted again, students can apply between 29th March -
 9th April.
 More volunteers will be required:

* to review student applications and choose which to accept
* to supervise the accepted students

 Both of these roles are called mentor in the Google system.  Putting
 together a good team of mentors before applying as an organisation is
 helpful towards us being accepted into the programme.

 Regards,
Malcolm


 ___
 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] OT: Literature on translation of lambda calculus to combinators

2010-02-01 Thread Hans Aberg

On 28 Jan 2010, at 10:54, Dušan Kolář wrote:

 Could anyone provide a link to some paper/book (electronic version  
of both preferred, even if not free) that describes an algorithm of  
translation of untyped lambda calculus expression to a set of  
combinators? Preferably SKI or BCKW. I'm either feeding google with  
wrong question or there is no link available now...


Here is a paper that uses that standard arithmetic operators that  
Church defined:

  http://www.dcs.ed.ac.uk/home/pgh/amen.ps

  Hans


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


Re: [Haskell-cafe] Anyone up for Google SoC 2010?

2010-02-01 Thread Johan Tibell
I'd be willing to mentor again. I think it's really important that we think
hard about coming up with projects which improve the core Haskell tool chain
this year.

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


[Haskell-cafe] very strange utf8 problem

2010-02-01 Thread Günther Schmidt

Hi all,

I know this sounds daft but I do have good reason to ask.

Is it possible that GHC's core itself has a problem with a particular 
Umlaut only?


HDBC-ODBC won't read in data from an SQLite database as soon as it comes 
accross a *lowercase* U-Umlaut (ü) ghci crashes. Other Umlauts (ä, 
ö and ß) pass however.


This is the error message:

 readUTF8Char: illegal UTF-8 character 252

As I said, other Umlauts do pass.

I got this very message quite often, usually when working with databases 
and not always using HDBC but also Takusen. I kept blaming it on 
HDBC-ODBC or the input data but I might have been wrong there.

Günther


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


Re: [Haskell-cafe] Anyone recommend a VPS?

2010-02-01 Thread Jason Dusek
2010/01/31 Marc Weber marco-owe...@gmx.de:
 If all you want is standard debian or such it does'nt matter.
 However I tried installing NixOS Linux and I've had lot's of
 trouble until switching to linode. NixOS was up and running
 within 30min then..

  How did you get NixOS on your Linode system? They don't seem to
  offer it, last I checked.

  I'm looking in to doing this with PRGMR, which has pretty good
  pricing though it's not nearly as featureful as Linode.

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


Re: [Haskell-cafe] very strange utf8 problem

2010-02-01 Thread David Menendez
2010/2/1 Günther Schmidt gue.schm...@web.de:
 Hi all,

 I know this sounds daft but I do have good reason to ask.

 Is it possible that GHC's core itself has a problem with a particular Umlaut
 only?

 HDBC-ODBC won't read in data from an SQLite database as soon as it comes
 accross a *lowercase* U-Umlaut (ü) ghci crashes. Other Umlauts (ä, ö
 and ß) pass however.

 This is the error message:

  readUTF8Char: illegal UTF-8 character 252

 As I said, other Umlauts do pass.

I suspect something is trying to read ISO-Latin-1 data as UTF-8. 252
is the Unicode and Latin-1 code point for ü, but in UTF-8 it's
written in two bytes as 0xC3BC.

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Anyone up for Google SoC 2010?

2010-02-01 Thread sterl

Malcolm Wallace wrote:
Google has announced that the Summer of Code programme will be running 
again this year.  If haskell.org people would like to take part again 
this year, then we need volunteers:
I'd be happy to mentor again as well. It's important to bear in mind 
that the total number of mentors plays a small role in slot allocation, 
but far more important is to maximize the amount of high-quality 
applications -- the more students we encourage to submit proposals, the 
more proposals we will be able to fund: 
http://socghop.appspot.com/document/show/program/google/gsoc2009/studentallocations


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


[Haskell-cafe] Re: Non-termination of type-checking

2010-02-01 Thread Stefan Monnier
 And I'm pretty sure that there's no way to convince Agda that F = R,
 or  something similar, because, despite the fact that Agda has
 injective type  constructors like GHC (R x = R y = x = y), it doesn't
 let you make the  inference R Unit = F Unit = R = F. Of course, in
 Agda, one could arguably say that it's true, because Agda has no type
 case, so there's (I'm pretty sure) no  way to write an F such that
 R T = F T, but R U /= F U, for some U /= T.

It's easy to construct an F that is different from R but agrees with
R for the case of Unit: F = λ _ - R Unit
So there's a good reason why Agda doesn't let F and R unify: it would
really be completely wrong.


Stefan

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


Re: [Haskell-cafe] Re: Very imperfect hash function

2010-02-01 Thread Holger Siegel
Am Donnerstag, den 28.01.2010, 19:37 + schrieb Maciej Piechotka:
 On Thu, 2010-01-28 at 14:07 -0500, Steve Schafer wrote:
  I'm looking for some algorithmic suggestions:
  
  I have a set of several hundred key/value pairs. The keys are 32-bit
  integers, and are all distinct. The values are also integers, but the
  number of values is small (only six in my current problem). So,
  obviously, several keys map to the same value.
  
  For some subsets of keys, examining only a small portion of the key's
  bits is enough to determine the associated value. For example, there may
  be 250 keys that all have the same most-significant byte, and all 250
  map to the same value. There are also keys at the other extreme, where
  two keys that differ in only one bit position map to different values.
  
  The data are currently in a large lookup table. To save space, I'd like
  to convert that into a sort of hash function:
  
   hash :: key - value
  
  My question is this: Is there any kind of generic approach that can make
  use of the knowledge about the internal redundancy of the keys to come
  up with an efficient function?
  
  Steve Schafer
  Fenestra Technologies Corp.
  http://www.fenestra.com/
 
 Maybe:
 
 data TTree a = TTree Int (TTree a) (TTree a)
  | TNode a
 --  | THashNode some hash table
 
 hash :: TTree a - Int32 - a
 hash (TNode v) _ = v
 hash (TTree b l r) k = if testBit k b then hash r k else hash l k
 -- hash (THashNode h) k = lookupHashTable h k

This looks like you have re-invented Binary Decision Diagrams (BDDs). :)

 Of course you need to code efficiently the tree.

When you fix the order in which the bits are tested, you can take
advantage of sharing. This way you reach an efficient representation
called Reduced Ordered Binary Decision Diagram (ROBDD). Unfortunately, a
bad order may lead to exponential size (in the number of bits), and
finding a good order can be NP-hard.

Regards,

Holger


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


Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?

2010-02-01 Thread Jeremy Shaw
Attached.

Thanks!
- jeremy

On Sun, Jan 31, 2010 at 1:34 AM, Bryan O'Sullivan b...@serpentine.comwrote:

 On Tue, Jan 26, 2010 at 10:08 AM, Jeremy Shaw jer...@n-heptane.comwrote:


 I think so... none of the other instances do.. but I guess that is not a
 very good excuse :)


 Send me a final darcs patch, and I'll apply it.



data-instance-for-text.dpatch
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Generating repeatable arbitrary values with QuickCheck 2

2010-02-01 Thread Sean Leather
I would like to generate an arbitrary (large) value to benchmark the
performance of constructing that value with isomorphic types. It seems like
QuickCheck might be useful in this regards. Has anyone done something
similar?

In versions 1.*, there was a generate function:

generate :: Int - StdGen - Gen a - a
 generate n rnd (Gen m) = m size rnd'
where (size, rnd') = randomR (0, n) rnd


That seems to have disappeared in versions 2.*, and I didn't find a clear
replacement. I came up with using the destructor for Gen:

unGen :: Gen a - StdGen - Int - a


The function generate seems to have a little something extra, though I'm not
sure if it's necessary. Is this true, or should I write an equivalent
generate function? As an aside, it would be nice to have a generate function
in the library, even if it is only a wrapper for unGen.

In the end, I would write something like the following:

unGen arbitrary (mkStdGen 11) 5 :: [Int]


This produces, for example, [5,1,-2,-4,2]. I also want to generate the same
value for a type isomorphic to [Int].

unGen arbitrary (mkStdGen 11) 5 :: List Int


Unfortunately, this produces Cons 4 (Cons 3 (Cons (-2) (Cons 0 (Cons (-1)
Nil: same length but different values. The Arbitrary instances are the
same. I had similar results with generate from QC 1.

Any suggestions on how to do this? With another library perhaps?

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


[Haskell-cafe] Re: Trapping getChar before echo

2010-02-01 Thread Tim Attwood
Last time I tried something like this [on Windows], it didn't seem to 
work. I wanted to trap arrow keys and so forth, but they seem to be being 
used for input history. (I.e., pressing the up-arrow produces 
previously-entered lines of text, and none of this appears to be reaching 
the Haskell program itself.) Has this changed since I tried it last year?


Doesn't work in windows, at least up till 6.10.1. There's a work-around 
though.


{-# LANGUAGE ForeignFunctionInterface #-}

import Data.Char
import Control.Monad (liftM, forever)
import Foreign.C.Types

getHiddenChar = liftM (chr.fromEnum) c_getch
foreign import ccall unsafe conio.h getch
 c_getch :: IO CInt

main = do
  forever $ do
 c - getHiddenChar
 putStrLn $ show (fromEnum c) 



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


Re: [Haskell-cafe] Very imperfect hash function

2010-02-01 Thread Richard O'Keefe


On Feb 1, 2010, at 9:04 AM, Hans Aberg wrote:
A simple hash-function for strings is to simply exclusive-or the  
bytes and then reduce modulo a prime number,


Simply exclusive-oring the bytes will give you at most 256 distinct
results.  (For an ASCII source, 128 distinct results.)  After that,
there hardly seems to be any point in reduction modulo a prime.
This approach can't tell a CAT from an ACT or a DOG from a GOD, which
is another strike against it.  (It also can't tell a TITTLE from a TILE,
or a BOTTLE from a BOLE, for obvious reasons.)


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


[Haskell-cafe] About code style ?

2010-02-01 Thread zaxis

For me i like C style instead of layout. For example, 
func1 a = do
 -- ...
 a * 2
 -- ...

I always write it as:
func1 a = do {
  -- ...;
   a * 2;
  -- ...;
}

However, i donot know how to write pure function using C style.
func1 a = {
  -- ...;
   a * 2;
  -- ...;
}

will not compile without `do`.

Sincerely!

-
fac n = foldr (*) 1 [1..n]
-- 
View this message in context: 
http://old.nabble.com/About-code-style---tp27414627p27414627.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] About code style ?

2010-02-01 Thread Ivan Lazar Miljenovic
zaxis z_a...@163.com writes:
 However, i donot know how to write pure function using C style.
 func1 a = {
   -- ...;
a * 2;
   -- ...;
 }

You mean imperatively?  Short answer: you can't and you shouldn't.

Slightly longer answer: you can possibly fudge something together using
the Identity monad from mtl, but that will involve wrapping/unwrapping
everywhere.

Learn to think about how to chain/group functions together to form more
of a pipeline rather than a sequence of statements.  Haskell =/= C.

-- 
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] About code style ?

2010-02-01 Thread Erik de Castro Lopo
zaxis wrote:

 For me i like C style instead of layout. For example, 
 func1 a = do
  -- ...
  a * 2
  -- ...
 
 I always write it as:
 func1 a = do {
   -- ...;
a * 2;
   -- ...;
 }

Honestly, don't do this.

When you're coding in Haskell you should write idiomatic Haskell and when
doing C, do idiomatic C.

Inventing your own coding style for a language will make it difficult for
other people who know and use that language to read your code and sooner
or later you will want to or need to work with others.

Erik
-- 
--
Erik de Castro Lopo
http://www.mega-nerd.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Very imperfect hash function

2010-02-01 Thread Richard O'Keefe

On Thu, 2010-01-28 at 14:07 -0500, Steve Schafer wrote:

I'm looking for some algorithmic suggestions:

I have a set of several hundred key/value pairs. The keys are 32-bit
integers, and are all distinct. The values are also integers, but  
the

number of values is small (only six in my current problem). So,
obviously, several keys map to the same value.


Instead of mapping keys to values, map keys to sets of values,
where each set of values is represented by a small bit string.
In your present case, one byte would be enough.



For some subsets of keys, examining only a small portion of the  
key's
bits is enough to determine the associated value. For example,  
there may
be 250 keys that all have the same most-significant byte, and all  
250
map to the same value. There are also keys at the other extreme,  
where
two keys that differ in only one bit position map to different  
values.


On today's machines, several hundred pairs counts as trivial.
Start by using a Data.IntMap of bytes and look for something else
only if that doesn't pay off.  This already takes advantage of the
bit-string nature of your keys, by the way.

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


Re: [Haskell-cafe] Re: could we get a Data instance for Data.Text.Text?

2010-02-01 Thread Bryan O'Sullivan
On Mon, Feb 1, 2010 at 12:08 PM, Jeremy Shaw jer...@n-heptane.com wrote:

 Attached.


Data/Text.hs:175:63:
Module `Data.Data' does not export `mkNoRepType'

Can you send a followup patch that works against GHC 6.10.4, please?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: About code style ?

2010-02-01 Thread Ertugrul Soeylemez
Hello zaxis,

as others have noted, you are trying to write C in Haskell.  Well, that
gains you nothing and rather gets you into trouble.  If you want to
write C, then use instead and not Haskell, because the idioms you're
used to in C will not work at all in Haskell.  Note for example that the
'do' keyword is misleading.  It does not introduce imperative code, but
monadic code, which may well be pure.

To answer your question:  There are no blocks in Haskell, which you
could put into braces.  Don't think in blocks of code, because that is
C, not Haskell, and it's plain wrong.  You are not going to write any
for/while loops anyway.  Thinking that way may have a negative impact on
your Haskell coding style.  The only place where braces are used is
record types and many Haskell programmers (including me) consider this
an ugly syntax.

But don't worry, you'll get used to the new syntax and eventually fall
in love with it, because it will make your life easier.  I myself came
from years of C/C++ experience and had similar difficulties in the
beginning.


Greets
Ertugrul


zaxis z_a...@163.com wrote:

 
 For me i like C style instead of layout. For example, 
 func1 a = do
  -- ...
  a * 2
  -- ...
 
 I always write it as:
 func1 a = do {
   -- ...;
a * 2;
   -- ...;
 }
 
 However, i donot know how to write pure function using C style.
 func1 a = {
   -- ...;
a * 2;
   -- ...;
 }
 
 will not compile without `do`.
 
 Sincerely!
 
 -
 fac n = foldr (*) 1 [1..n]



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


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


Re: [Haskell-cafe] About code style ?

2010-02-01 Thread Miguel Mitrofanov

However, i donot know how to write pure function using C style.
func1 a = {
 -- ...;
  a * 2;
 -- ...;
}


What do you mean by a * 2? If you don't use this value, don't  
calculate it.

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


Re: [Haskell-cafe] About code style ?

2010-02-01 Thread Gregory Crosswhite
Ditto what everyone else has said.  But to clarify what's going on:

The braces are used to introduce a list of things, such as monadic actions, 
data fields, or declarations.  For example, consider the following code:



f a =
  let {
a_times_2 = a*2;
a_times_4 = a*4;
  } in a_times_2+a_times_4

main = putStrLn $ f 3 =  ++ show (f 3)



The reason why my code compiled and yours didn't is because the compiler saw 
that the braces were being used to introduce a list of declarations, and the 
reason why it knew this was because of the let keyword.  By contrast, in your 
code it doesn't see a let, so it assumes that you must be introducing a list 
of monadic actions.  Hence it yells at you for not putting in a do.

Remember that a pure function is merely a definition of what the output is for 
a given input.  It does not say anything about *how* to do this.  Thus, you 
should never think of a pure function as being a list of actions but rather 
(approximately) a definition which may require some additional declarations 
(such as introduced by let) solely for the purpose of making it easier for 
*you* to *express* what its value is.  (I say approximately because the way you 
express it does affect the way it gets computed despite technically being pure, 
but this is not something you should be worrying about right now.)

But again, even though you could use curly brackets and semicolons as I 
illustrated above, you really should be using whitespace as it is the standard 
practice;  others reading your code may be confused by their presence and so 
have to work harder to figure out what is going on.

Cheers,
Greg


On Feb 1, 2010, at 6:22 PM, zaxis wrote:

 
 For me i like C style instead of layout. For example, 
 func1 a = do
 -- ...
 a * 2
 -- ...
 
 I always write it as:
 func1 a = do {
  -- ...;
   a * 2;
  -- ...;
 }
 
 However, i donot know how to write pure function using C style.
 func1 a = {
  -- ...;
   a * 2;
  -- ...;
 }
 
 will not compile without `do`.
 
 Sincerely!
 
 -
 fac n = foldr (*) 1 [1..n]
 -- 
 View this message in context: 
 http://old.nabble.com/About-code-style---tp27414627p27414627.html
 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.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