[Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Jacek Generowicz

[ TLDR: How do you do Lisp symbols in Haskell? ]


What is the Haskell approach to efficient comparison and lookup of  
objects by their identity?


Maybe a toy example would help to explain what I mean.

Imagine that I want to use Haskell to maximize happiness in a  
situation where a bunch of people have to be assigned to certain  
groups according to their preferences, and some constraints on the  
group sizes. Conceptually my input data might be structured as follows:


data Group = Group GroupName MaxGroupSize
data Person = Person Name Group Group Group

The program should partition the people into groups, attempting to get  
everyone into their most favoured groups.


Whatever algorithm I choose to use for the optimization, will have to  
do lots of comparisons of Groups and Persons where their *identity* is  
all that matters: you don't need to look inside the objects. On the  
other hand, sometimes we will have to look inside the objects, for  
example in order to answer queries such as Which group did Johnny get  
and how far down his list of choices did that group feature?.


I should be able to run the program on data that becomes available at  
run time.


The lisper in me is crying out for (lisp-like-)symbols which I can  
create from the input data at run time and on which some extra  
information can be hung. How would I organize something like this in  
Haskell?



Thanks.


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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Brandon Allbery
On Thu, May 26, 2011 at 04:45, Jacek Generowicz jacek.generow...@cern.chwrote:

 What is the Haskell approach to efficient comparison and lookup of objects
 by their identity?


ghc uses Data.Unique to generate unique internal identifiers to associate
with things.  (Think gensym.  Hm, except last time I did anything serious
with Lisp, it was Maclisp... does gensym even still exist, or did CL do
something inscrutable with it?)  Beyond that, the existence of functions
such as reallyUnsafePointerEquality# makes me think it's a Hard Problem.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Christopher Done
On 26 May 2011 10:45, Jacek Generowicz jacek.generow...@cern.ch wrote:
 What is the Haskell approach to efficient comparison and lookup of objects
 by their identity?

Often you just provide your own and implement Eq.

 I should be able to run the program on data that becomes available at run
 time.

Typically you define an id generator and zip anything coming from the
input stream up with that generator. So:

persons - fmap (zipWith addId [1..] . map parsePerson)
(hGetContents handle)
 where addId id person = person { personId = id }

 Whatever algorithm I choose to use for the optimization, will have to do
 lots of comparisons of Groups and Persons where their *identity* is all that
 matters: you don't need to look inside the objects.

To achieve this abstraction the usual way is just implementing Eq:

instance Eq Person where
   Person{personId=id1} == Person{personId=id2} = id1 == id2

You can also implement ordering if required:

instance Ord Person where
   Person{personId=id1} `compare` Person{personId=id2} = id1 `compare` id2

Then you can write person1 == person2 and person1  person2, etc.
without looking inside the object, and all the library functions you
have available like the list functions that work on Eq instances and
Ord instances will work for your data type automatically.

There're also some packages on Hackage for generating unique ids.

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Jacek Generowicz


On 2011 May 26, at 11:12, Brandon Allbery wrote:

On Thu, May 26, 2011 at 04:45, Jacek Generowicz jacek.generow...@cern.ch 
 wrote:
What is the Haskell approach to efficient comparison and lookup of  
objects by their identity?


ghc uses Data.Unique to generate unique internal identifiers to  
associate with things.


At first blush it sounds like the sort of thing I'm after. Thanks.

(Think gensym.  Hm, except last time I did anything serious with  
Lisp, it was Maclisp... does gensym even still exist, or did CL do  
something inscrutable with it?)


CL has gensym.

But gensym does seem to be overkill in the case I presented.

I *could*, for example, say

data Person = Fred | Johnny | Sally | Belinda | Kate | Roger | Eric  
[... and so on for a few squillion ...]
data Group = Amazing | Brilliant | Cool | Great | Funky  [ ... and so  
on for a few dozen ...]


preferences :: Map Person (Group, Group, Group)

In this setup (Fred == Johnny) will be very cheap, and (lookup Fred  
preferences) will be less cheap but possible.


I'd use gensym if I need a new symbol right about which I know nothing  
other than I want it to be new and unique (nobody has created it  
before, and nobody will in the future). In the example scenario, I  
know what I want the symbol is to be called, and am prepared to accept  
the responsibility for avoiding duplicates, but I still want to be  
able create it at run time. In the Haskell snippet above, the compiler  
protects me against duplication, but forces me to know the data at  
compile time.


In Lisp terms, I'm looking for make-symbol and intern.

Beyond that, the existence of functions such as  
reallyUnsafePointerEquality# makes me think it's a Hard Problem.


:-)


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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Jacek Generowicz


On 2011 May 26, at 11:16, Christopher Done wrote:

On 26 May 2011 10:45, Jacek Generowicz jacek.generow...@cern.ch  
wrote:
What is the Haskell approach to efficient comparison and lookup of  
objects

by their identity?


Often you just provide your own and implement Eq.

I should be able to run the program on data that becomes available  
at run

time.


Typically you define an id generator and zip anything coming from the
input stream up with that generator.


Makes sense.

Whatever algorithm I choose to use for the optimization, will have  
to do
lots of comparisons of Groups and Persons where their *identity* is  
all that

matters: you don't need to look inside the objects.


To achieve this abstraction the usual way is just implementing Eq:

instance Eq Person where
  Person{personId=id1} == Person{personId=id2} = id1 == id2


Any comments on the relative efficiency of the above as compared to

A == B in the context of

data Foo = A | B | C | D | ... lots more ...

?

(I imagine that a Sufficiently Smart Compiler could reduce (==) ::  
Person Person to just integer comparison.)


Thank you.


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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Brandon Allbery
On Thu, May 26, 2011 at 05:41, Jacek Generowicz jacek.generow...@cern.chwrote:

 On 2011 May 26, at 11:12, Brandon Allbery wrote:

 (Think gensym.  Hm, except last time I did anything serious with Lisp, it
 was Maclisp... does gensym even still exist, or did CL do something
 inscrutable with it?)


 But gensym does seem to be overkill in the case I presented.
 (...)

In Lisp terms, I'm looking for make-symbol and intern.


I think I just landed on inscrutable; (gensym) used to do pretty much
that, it rolled symbols starting from 'a for the first one generated in
a given interpreter.  (It has occurred to me that I was not entirely clear;
the Mac in Maclisp was MACSYMA.  Ancient stuff.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Strange Type Error

2011-05-26 Thread jean-christophe mincke
Hello,

Could anyone help me understand what is wrong with the definition of f2 in
the code below?


class C a b where
convert :: a - b

convertToInt :: (C a Int) = a - Int
convertToInt x = convert x

f1 x =  convertToInt x

f2 = \x - convertToInt x

f3 :: (C a Int) = a - Int
f3 = \x - convertToInt x

Thank you

Regards

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


Re: [Haskell-cafe] Status of Haskell + Mac + GUIs graphics

2011-05-26 Thread John Lato
fltk definitely has some good points, but I've always found it hideously
ugly.  Of course the default gtk on osx is ugly too, but some of the
available themes are nice.

However, getting gtk with OpenGL on osx was fairly easy.  Everything worked
out of the box except gtkglext (Haskell package).  I've submitted some
patches for that which hopefully will be applied to the repo soon.

This is what I used:

git
darcs
ghc-7.0.3 (self-compiled)
cabal-install
macports gtk2 +no_x11 +quartz
macports gtkglext +no_x11 +quartz
gtk2hs from source
gtkglext (Haskell) from source


I use a self-compiled ghc, but this should work with any ghc.  Mixing ghc
and macports can cause problems with libiconv, but the solutions are pretty
well-known.  Since I compile ghc, I configure it to use macports's libiconv
so there aren't any conflicts.


 sudo port install gtkglext +no_x11 +quartz
(wait a while...)
 darcs get --lazy http://code.haskell.org/gtk2hs
 cd gtk
 cabal install gtk2hs-buildtools
 chmod +x bootstrap.sh
 ./bootstrap.sh -fhave-quartz-gtk
(wait a while...)
 cd ..
 darcs get --lazy http://code.haskell.org/gtkglext
 cd gtkglext
 darcs apply gtkglext.dpatch
 cabal install


Until the source tree gets patched, you'll have to manually apply the patch
bundle.

If you want to avoid macports, it should be possible to use gtk-osx and
gtkglext from source instead.  However, I've found gtk-osx to be unstable
and quite difficult to build in the past, so I'd strongly recommend
macports, at least for now.  The source install of gtkglext works just fine
and can be used with macports gtk2 (I tested this).  Since this path already
uses macports there's not much benefit though.

Cheers,
John L

On Wed, May 25, 2011 at 9:07 PM, Evan Laforge qdun...@gmail.com wrote:

 fltk supports OpenGL on windows, X11, and OS X, though I've never used
 it.  The thing it doesn't have is a haskell binding, but as I
 mentioned I just bind whatever I need when I need it and since I don't
 need much it's easy.  Dunno if this applies in your case though.

 Maybe it's my NIH, but I like to start with something too simple and
 add what I need rather than start with something that has more than I
 need and try to get it working.

 On Wed, May 25, 2011 at 11:58 AM, Conal Elliott co...@conal.net wrote:
  Thanks, John. Encouraging bit of news. Please do let us know what you
 learn
  when you try.   - Conal
 
  On Tue, May 24, 2011 at 1:28 AM, John Lato jwl...@gmail.com wrote:
 
  You can use gtkglext to get OpenGL support.  With the official release
 of
  gtkglext-1.2.0 there's a bit of hacking involved (that was probably me
  you're referring to), but it looks like the repo head has native Quartz.
  With any luck, you just need to build gtkglext from the repo, then the
  gtkglext package.
 
  I might have some time to try this later today; I'll report back if I
 get
  results.
 
  John Lato
 
  On Tue, May 24, 2011 at 6:01 AM, Conal Elliott co...@conal.net wrote:
 
  Last I tried, there wasn't native support for OpenGL with gtk, and I
 need
  OpenGL. Then more recently, I heard of some progress in that area, but
  requiring lots of hacking to get it all compiling. Any recent news?  -
 Conal
 
  On Mon, May 23, 2011 at 2:33 AM, John Lato jwl...@gmail.com wrote:
 
  Message: 17
  Date: Fri, 20 May 2011 15:59:51 -0700
  From: Evan Laforge qdun...@gmail.com
  Subject: Re: [Haskell-cafe] Status of Haskell + Mac + GUIs  graphics
  To: Erik Hesselink hessel...@gmail.com
  Cc: haskell-cafe@haskell.org
  Message-ID: BANLkTi=74mm6ortu2e192jtoot9g49f...@mail.gmail.com
  Content-Type: text/plain; charset=ISO-8859-1
 
   Note that it is supposed to be possible to build gtk2hs with
 gtk+osx,
   which will not use X11 but use the native OS X GUI. I've not been
   able
   to get this to work, but it's been a while since I tried. The
 Haskell
   wiki mentions it doesn't support Glade, but does support Cairo. If
   this were to work, gtk2hs would be a serious option as well.
 
  I've tried this 3 or 4 times, and failed every time.  It's crazy
  complicated.
 
  I used to use this combination regularly.  IME the difficulties are
  primarily with getting a working gtk+osx build.  Once that was
 accomplished,
  gtk2hs was a straightforward install, provided you build from the src
 repo
  with the -quartz flag.
  Recently I've switched to using macports gtk2 with the quartz, no-x11
  variant, which also uses native cocoa.  This is much more reliable
 than
  gtk+osx.  I don't know if it supports Glade though.
  My biggest problem with wx is that there's no support for building
  64-bit wx applications on OS X.  If that were fixed I might prefer it.
  John Lato
  ___
  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] Strange Type Error

2011-05-26 Thread Christopher Done
The problem is the monomorphism restriction:

http://www.haskell.org/haskellwiki/Monomorphism_restriction
http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/monomorphism.html
http://stackoverflow.com/questions/tagged/monomorphism-restriction
http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/pitfalls.html

This kicks everyone in the butt at least once. It would be good if GHC
could point it out, as mine (6.12.3) just complains about no instance.
Maybe GHC7 does point it out. It's a waste of people's time otherwise.

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


Re: [Haskell-cafe] Strange Type Error

2011-05-26 Thread Brandon Allbery
On Thu, May 26, 2011 at 06:01, jean-christophe mincke
jeanchristophe.min...@gmail.com wrote:
 f1 x =  convertToInt x
 f2 = \x - convertToInt x

Absent useful things like error messages, I'll assume that you tripped
over the monomorphism restriction.  That is, when you have a name that
doesn't take a direct parameter, there are additional constraints on
that name's type.  (The inner lambda is not considered for this
purpose, so while in theory f1 and f2 should be identical, in practice
they are not unless you use {-# LANGUAGE NoMonomorphismRestriction
#-}.

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


Re: [Haskell-cafe] Strange Type Error

2011-05-26 Thread Brandon Allbery
On Thu, May 26, 2011 at 06:10, Christopher Done
chrisd...@googlemail.com wrote:
 This kicks everyone in the butt at least once. It would be good if GHC
 could point it out, as mine (6.12.3) just complains about no instance.
 Maybe GHC7 does point it out. It's a waste of people's time otherwise.

I think the Haskell standards committee is moving in the direction of
eliminating it as being the wrong solution to the problem.

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Jacek Generowicz


On 2011 May 26, at 11:59, Brandon Allbery wrote:

On Thu, May 26, 2011 at 05:41, Jacek Generowicz jacek.generow...@cern.ch 
 wrote:

On 2011 May 26, at 11:12, Brandon Allbery wrote:
(Think gensym.  Hm, except last time I did anything serious with  
Lisp, it was Maclisp... does gensym even still exist, or did CL do  
something inscrutable with it?)


But gensym does seem to be overkill in the case I presented.
(...) In Lisp terms, I'm looking for make-symbol and intern.


I think I just landed on inscrutable;


Nah, it's probably just me confusing you.

(gensym) used to do pretty much that, it rolled symbols starting  
from 'a for the first one generated in a given interpreter.


It still does essentially that. (Just don't be fooled by the name  
a: you can't access that symbol through that name. Aaaah, maybe in  
Maclisp it really did intern them under that name, but that would  
surprise me).


'(gensym)' in CL is a bit like 'object()' in Python or 'new  
MyEmptyClass' in C++: the key point being that if you don't bind the  
thing being created right now, you'll never be able to get your hands  
on it again.


Coming back on topic: Yes, I could use gensym for my purposes (though  
CL provides a variety of similar yet subtly different tools, which is  
why gensym feels a bit weird in this context).



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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Jacek Generowicz


On 2011 May 26, at 11:59, Jacek Generowicz wrote:

(I imagine that a Sufficiently Smart Compiler could reduce (==) ::  
Person Person to just integer comparison.)


Sorry, I meant

(==) :: Person - Person - Bool

in the above.


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


[Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread michael rice
How do I compile and run this parallel program?
Michael
===
import Control.Parallel
nfib :: Int - Intnfib n | n = 1 = 1       | otherwise = par n1 (seq n2 (n1 + 
n2 + 1))                     where n1 = nfib (n-1)                           n2 
= nfib (n-2)
{-nfib :: Int - Intnfib n | n = 1 = 1       | otherwise = nfib (n-1) + nfib 
(n-2)-}

main = do putStrLn $ show $ nfib 39
===
[michael@hostname ~]$ ghc --make -threaded nfib.hs[michael@hostname ~]$ ./nfib 
+RTS -N3nfib: the flag -N3 requires the program to be built with 
-threadednfib: nfib: Usage: prog args [+RTS rtsopts | -RTS args] ... 
--RTS argsnfib: nfib:    +RTS    Indicates run time system options 
follownfib:    -RTS    Indicates program arguments follownfib:   --RTS    
Indicates that ALL subsequent arguments will be given to thenfib:            
program (including any of these RTS flags)nfib: nfib: The following run time 
system options are available:nfib: nfib:   -?       Prints this message and 
exits; the program is not executednfib:   --info   Print information about the 
RTS used by this programnfib: nfib:   -Ksize Sets the maximum stack size 
(default 8M)  Egs: -K32k   -K512knfib:   -ksize Sets the initial thread stack 
size (default 1k)  Egs: -k4k   -k2mnfib: nfib:   -Asize Sets the minimum 
allocation area size (default
 512k) Egs: -A1m -A10knfib:   -Msize Sets the maximum heap size (default 
unlimited)  Egs: -M256k -M1Gnfib:   -Hsize Sets the minimum heap size 
(default 0M)   Egs: -H24m  -H1Gnfib:   -mn    Minimum % of heap which must be 
available (default 3%)nfib:   -Gn    Number of generations (default: 2)nfib:  
 -Tn    Number of steps in younger generations (default: 2)nfib:   -cn    
Use in-place compaction instead of copying in the oldest generationnfib:        
    when live data is at least n% of the maximum heap size set withnfib:      
      -M (default: 30%)nfib:   -c       Use in-place compaction for all oldest 
generation collectionsnfib:            (the default is to use copying)nfib:   
-w       Use mark-region for the oldest generation (experimental)nfib: nfib:   
-t[file] One-line GC statistics (if file omitted, uses stderr)nfib:   
-s[file] Summary  GC statistics (if file omitted, uses
 stderr)nfib:   -S[file] Detailed GC statistics (if file omitted, uses 
stderr)nfib: nfib: nfib:   -Z       Don't squeeze out update frames on stack 
overflownfib:   -B       Sound the bell at the start of each garbage 
collectionnfib: nfib:   -hT      Heap residency profile (output file 
program.hp)nfib:   -isec  Time between heap samples (seconds, default: 
0.1)nfib: nfib:   -Csecs  Context-switch interval in seconds.nfib:            
 0 or no argument means switch as often as possible.nfib:             Default: 
0.02 sec; resolution is set by -V below.nfib:   -Vsecs  Master tick interval 
in seconds (0 == disable timer).nfib:             This sets the resolution for 
-C and the profile timer -i.nfib:             Default: 0.02 sec.nfib: nfib:   
--install-signal-handlers=yes|nonfib:             Install signal handlers 
(default: yes)nfib: nfib: RTS options may also be specified using the GHCRTS
 environment variable.nfib: nfib: Other RTS options may be available for 
programs compiled a different way.nfib: The GHC User's Guide has full 
details.nfib: [michael@hostname ~]$ 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread Daniel Fischer
On Thursday 26 May 2011 13:24:09, michael rice wrote:
 How do I compile and run this parallel program?
 Michael
 ===
 import Control.Parallel
 nfib :: Int - Int
 nfib n | n = 1 = 1   
| otherwise = par n1 (seq n2 (n1 + n2 + 1))

The 'seq' here should be a 'pseq' to ensure that n2 is (started to be) 
calculated before (n1 + n2 +1) is evaluated (iirc, currently, both work 
with ghc, but it's not guaranteed for seq).
 
  where 
n1 = nfib (n-1)   
n2 = nfib (n-2)
  {-nfib :: Int - Intnfib n | n = 1 = 1
   | otherwise = nfib (n-1) + nfib (n-2)-}
 
 main = do putStrLn $ show $ nfib 39
 ===
 [michael@hostname ~]$ ghc --make -threaded nfib.hs
 [michael@hostname ~]$ ./nfib +RTS -N3

In principle, that is the correct way to compile and run it (note that with 
ghc-7, you don't need the --make).

 nfib: the flag -N3 requires the program to be built with
 -threaded

Have you previously compiled the programme without -threaded?
Unless you snipped the compilation messages, their absence strongly 
indicates so.

If that is the case, you fell victim to ghc's recompilation-avoidance which 
doesn't keep track of the flags a programme/module was compiled with, so it 
saw that nothing [as far as it knows] changed, hence didn't recompile.

Then removing .o and .hi or passing -fforce-recomp will make it recompile 
and link with the threaded runtime.

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


Re: [Haskell-cafe] Function application layout

2011-05-26 Thread Neil Brown

On 25/05/11 10:00, Jonas Almström Duregård wrote:

As an equivalent to:

f (x a) (y b) (z c)

Of course my intention is that the new keyword should initiate layout 
syntax so we can write this:


f applied to
  x a
  y b
  z c



Here's a (tongue-in-cheek) trick that allows for layout close to what 
you wanted (spoiler: but not close enough!).  We start by switching to 
parameterised monads (which allow you to change the type of the monad as 
you go down the do-block; look carefully at the second and third 
parameters in the monad class):


{-# LANGUAGE RebindableSyntax #-}

 import Control.Applicative
 import Prelude ((++), (.), Num(..), Eq(..), ($), id, Int, Char, 
String, Float, ?, const, Show(..), Fractional(..))


 class Monad m where
   (=) :: m a b y - (y - m b c z) - m a c z
   return :: b - m a a b

 () :: Monad m = m a b y - m b c z - m a c z
 () m n = m = const n

Then we define a type for wrapping pure functions in this monad:

 data Fun a b c = Fun (a - b) c

 instance Monad Fun where
   (=) (Fun f x) m = let Fun g y = m x in Fun (g . f) y
   return x = Fun id x

Then we add a helper for unwrapping it:

 ($$) :: a - Fun a b c - b
 ($$) f (Fun g _) = g f

And a function for supplying an argument:

 r :: a - Fun (a - b) b a
 r x = Fun ($ x) x

And so what does let us do?  Well, here's how it's used:

 foo :: Int - Char - String - Float - String
 foo a b c d = show (a, b, c, d)

 eg :: String
 eg = foo $$ do
   r$ 2 + 1
   r$ 'c'
   r$ hello ++ goodbye
   r$ 3.0

foo is the function we want to apply, and eg shows how to apply it in 
do-notation with an argument on each line.  I couldn't manage to remove 
the r$ at the beginning of each line, which rather ruins the whole 
scheme :-(  On the plus side, there's no brackets, it's only two extra 
characters per line, and you can have whatever you like after the r$.


For those who are interested, you can also use the same trick for 
writing Applicatives in a do notation.  Continuing the same module, we 
can add an analogue for each of the types and functions for Applicative:


 data App f a b c = App (f a - f b) c

 instance Applicative f = Monad (App f) where
   (=) (App f x) m = let App g y = m x in App (g . f) y
   return x = App id x

 ($$) :: Applicative f = f a - App f a b c - f b
 ($$) f (App g _) = g f

 s :: Applicative f = f a - App f (a - b) b (f a)
 s x = App (* x) x

Then we can use this on things which are Applicative but not Monad, e.g.

 egA :: [String]
 egA = getZipList $ pure foo $$ do
   s$ ZipList [3, 6, 7]
   s$ ZipList hello
   s$ ZipList [more, strings]
   s$ ZipList [1.0, 1.5, 2.0]

And that's enough silly playing around :-)

Thanks,

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


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread michael rice
Thank, Daniel
Multiple threads are in evidence in my system monitor, but I wonder why I'm 
getting two different answers, one twice the other. The first is the parallel 
solution and the second is the non.
Michael
===
{-import Control.Parallel
nfib :: Int - Intnfib n | n = 1 = 1       | otherwise = par n1 (pseq n2 (n1 + 
n2 + 1))                     where n1 = nfib (n-1)                           n2 
= nfib (n-2)-}
nfib :: Int - Intnfib n | n = 1 = 1       | otherwise = nfib (n-1) + nfib 
(n-2)
main = do putStrLn $ show $ nfib 39
=
[michael@hostname ~]$ ghc --make -threaded nfib.hs[1 of 1] Compiling Main       
      ( nfib.hs, nfib.o )Linking nfib ...[michael@hostname ~]$ ./nfib +RTS 
-N3204668309[michael@hostname ~]$ ghc --make nfib.hs[1 of 1] Compiling Main     
        ( nfib.hs, nfib.o )Linking nfib ...[michael@hostname ~]$ 
./nfib102334155[michael@hostname ~]$ 

--- On Thu, 5/26/11, Daniel Fischer daniel.is.fisc...@googlemail.com wrote:

From: Daniel Fischer daniel.is.fisc...@googlemail.com
Subject: Re: [Haskell-cafe] Parallel compilation and execution?
To: haskell-cafe@haskell.org
Cc: michael rice nowg...@yahoo.com
Date: Thursday, May 26, 2011, 8:16 AM

On Thursday 26 May 2011 13:24:09, michael rice wrote:
 How do I compile and run this parallel program?
 Michael
 ===
 import Control.Parallel
 nfib :: Int - Int
 nfib n | n = 1 = 1       
        | otherwise = par n1 (seq n2 (n1 + n2 + 1))

The 'seq' here should be a 'pseq' to ensure that n2 is (started to be) 
calculated before (n1 + n2 +1) is evaluated (iirc, currently, both work 
with ghc, but it's not guaranteed for seq).
 
          where 
            n1 = nfib (n-1)               
            n2 = nfib (n-2)
  {-nfib :: Int - Intnfib n | n = 1 = 1
           | otherwise = nfib (n-1) + nfib (n-2)-}
 
 main = do putStrLn $ show $ nfib 39
 ===
 [michael@hostname ~]$ ghc --make -threaded nfib.hs
 [michael@hostname ~]$ ./nfib +RTS -N3

In principle, that is the correct way to compile and run it (note that with 
ghc-7, you don't need the --make).

 nfib: the flag -N3 requires the program to be built with
 -threaded

Have you previously compiled the programme without -threaded?
Unless you snipped the compilation messages, their absence strongly 
indicates so.

If that is the case, you fell victim to ghc's recompilation-avoidance which 
doesn't keep track of the flags a programme/module was compiled with, so it 
saw that nothing [as far as it knows] changed, hence didn't recompile.

Then removing .o and .hi or passing -fforce-recomp will make it recompile 
and link with the threaded runtime.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function application layout

2011-05-26 Thread Daniel Fischer
On Thursday 26 May 2011 14:35:41, Neil Brown wrote:
 foo is the function we want to apply, and eg shows how to apply it in 
 do-notation with an argument on each line.  I couldn't manage to remove 
 the r$ at the beginning of each line, which rather ruins the whole 
 scheme :-(  On the plus side, there's no brackets, it's only two extra 
 characters per line, and you can have whatever you like after the r$.

Wouldn't that be also achievable with

infixl 0 ?

(?) :: (a - b) - a - b
f ? x = f x

eg = foo
  ? 2 + 1
  ? 'c'
  ? hello ++ goodbye
  ? 3.0

?

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


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread David Virebayre
2011/5/26 michael rice nowg...@yahoo.com

 Thank, Daniel

 Multiple threads are in evidence in my system monitor, but I wonder why I'm
 getting two different answers, one twice the other. The first is the
 parallel solution and the second is the non.


Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the
non-parallel one ?



 Michael

 ===

 {-
 import Control.Parallel

 nfib :: Int - Int
 nfib n | n = 1 = 1
| otherwise = par n1 (pseq n2 (n1 + n2 + 1))
  where n1 = nfib (n-1)
n2 = nfib (n-2)
 -}

 nfib :: Int - Int
 nfib n | n = 1 = 1
| otherwise = nfib (n-1) + nfib (n-2)

 main = do putStrLn $ show $ nfib 39

 =

 [michael@hostname ~]$ ghc --make -threaded nfib.hs
 [1 of 1] Compiling Main ( nfib.hs, nfib.o )
 Linking nfib ...
 [michael@hostname ~]$ ./nfib +RTS -N3
 204668309
 [michael@hostname ~]$ ghc --make nfib.hs
 [1 of 1] Compiling Main ( nfib.hs, nfib.o )
 Linking nfib ...
 [michael@hostname ~]$ ./nfib
 102334155
 [michael@hostname ~]$


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


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread Brandon Moore
From: michael rice, Thursday, May 26, 2011
Subject: Re: [Haskell-cafe] Parallel compilation and execution?

Thank, Daniel

Multiple threads are in evidence in my system monitor, but I wonder why I'm 
getting two different answers, one twice the other. The first is the parallel 
solution and the second is the non.


Not exactly twice - (2n-1). What you get from counting all nodes in a binary 
tree (of function calls),
compared to counting just the leaves.

A program using only pure code, par, and pseq should be deterministic, so if it 
gets different
value by building with and without threaded, changing the number of threads, or 
just running
again, that's a bug in GHC (If it runs out of memory sometimes and not other 
times, that's
not technically a bug, but still interesting).


Replacing par with the second argument should also give an equivalent program. 
pseq isn't
really parallel at all, but if you'd like to remove it, then replacing it with 
seq or just the second
argument might change strictness and evaluation order, but shouldn't change the 
result.
Brandon.


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


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread michael rice
Fair question. I copied the parallel version from:

http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html
but pulled the non-parallel version from a text.
Michael

--- On Thu, 5/26/11, David Virebayre dav.vire+hask...@gmail.com wrote:

From: David Virebayre dav.vire+hask...@gmail.com
Subject: Re: [Haskell-cafe] Parallel compilation and execution?
To: michael rice nowg...@yahoo.com
Cc: haskell-cafe@haskell.org, Daniel Fischer 
daniel.is.fisc...@googlemail.com
Date: Thursday, May 26, 2011, 8:56 AM



2011/5/26 michael rice nowg...@yahoo.com

Thank, Daniel

Multiple threads are in evidence in my system monitor, but I wonder why I'm 
getting two different answers, one twice the other. The first is the parallel 
solution and the second is the non.

Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the 
non-parallel one ? 

Michael

===
{-import
 Control.Parallel
nfib :: Int - Intnfib n | n = 1 = 1
       | otherwise = par n1 (pseq n2 (n1 + n2 + 1))                     where 
n1 = nfib (n-1)
                           n2 = nfib
 (n-2)-}
nfib :: Int - Int
nfib n | n = 1 = 1       | otherwise = nfib (n-1) + nfib (n-2)

main = do putStrLn $ show $ nfib 39

=
[michael@hostname ~]$ ghc --make -threaded nfib.hs
[1 of 1] Compiling Main             ( nfib.hs, nfib.o )Linking nfib ...
[michael@hostname ~]$ ./nfib +RTS -N3204668309[michael@hostname ~]$ ghc --make 
nfib.hs
[1 of 1] Compiling Main             ( nfib.hs, nfib.o )Linking nfib
 ...[michael@hostname ~]$ ./nfib102334155[michael@hostname ~]$ 



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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Gregory Collins
Based on the description it looks like you could be looking for:

http://hackage.haskell.org/package/simple-atom

G

On Thu, May 26, 2011 at 10:45 AM, Jacek Generowicz
jacek.generow...@cern.ch wrote:
 [ TLDR: How do you do Lisp symbols in Haskell? ]


 What is the Haskell approach to efficient comparison and lookup of objects
 by their identity?

 Maybe a toy example would help to explain what I mean.

 Imagine that I want to use Haskell to maximize happiness in a situation
 where a bunch of people have to be assigned to certain groups according to
 their preferences, and some constraints on the group sizes. Conceptually my
 input data might be structured as follows:

 data Group = Group GroupName MaxGroupSize
 data Person = Person Name Group Group Group

 The program should partition the people into groups, attempting to get
 everyone into their most favoured groups.

 Whatever algorithm I choose to use for the optimization, will have to do
 lots of comparisons of Groups and Persons where their *identity* is all that
 matters: you don't need to look inside the objects. On the other hand,
 sometimes we will have to look inside the objects, for example in order to
 answer queries such as Which group did Johnny get and how far down his list
 of choices did that group feature?.

 I should be able to run the program on data that becomes available at run
 time.

 The lisper in me is crying out for (lisp-like-)symbols which I can create
 from the input data at run time and on which some extra information can be
 hung. How would I organize something like this in Haskell?


 Thanks.


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




-- 
Gregory Collins g...@gregorycollins.net

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Simon Meier
2011/5/26 Jacek Generowicz jacek.generow...@cern.ch:

 On 2011 May 26, at 11:16, Christopher Done wrote:

 On 26 May 2011 10:45, Jacek Generowicz jacek.generow...@cern.ch wrote:

 What is the Haskell approach to efficient comparison and lookup of
 objects
 by their identity?

 Often you just provide your own and implement Eq.

 I should be able to run the program on data that becomes available at run
 time.

 Typically you define an id generator and zip anything coming from the
 input stream up with that generator.

 Makes sense.

 Whatever algorithm I choose to use for the optimization, will have to do
 lots of comparisons of Groups and Persons where their *identity* is all
 that
 matters: you don't need to look inside the objects.

 To achieve this abstraction the usual way is just implementing Eq:

 instance Eq Person where
  Person{personId=id1} == Person{personId=id2} = id1 == id2

 Any comments on the relative efficiency of the above as compared to

 A == B in the context of

 data Foo = A | B | C | D | ... lots more ...

 ?

 (I imagine that a Sufficiently Smart Compiler could reduce (==) :: Person
 Person to just integer comparison.)

I'm pretty sure GHC will do that for you.

An approach similar to the one by Chris Done is to use a
bi-directional map between Persons and Ints along the lines of

data IdMap a = IdMap (IntMap a) (Map a Int)

You can then associate a unique Int with each of your Persons and use
this during your comparison. For associating Ints to the Persons, a
simple fold or a State monad computation suffice. For the lookups on
the further properties of Persons, an additional argument or the
Reader monad will do. If you use a State monad and a single operation
that associates an Int to a Person, then you additionally get the
guarantee (inside a monadic computation) that no two Persons will be
associated with the same Int.

Efficiency-wise, you'll have O(log(n)) association,  O(min(n,W))
access time, and O(1) comparison time with a very low constant factor.
See the IntMap documentation for the O(min(n,W)) explanation.
Additionally, the code is pure with all the nice properties that come
with it.

By the way this problem is very similar to the one of observable
sharing. See this thread:
http://www.haskell.org/pipermail/haskell-cafe/2008-February/039639.html

best regards,
Simon

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


Re: [Haskell-cafe] Function application layout

2011-05-26 Thread Jonas Almström Duregård
That's a useful operator! Unfortunately it does not play nice with $. Of
less importance: some syntactic constructs can not appear in the arguments
without parenthesis, let bindings for instance (although lambda abstraction
works parenthesis-free).

Also I'm not sure this can be used for defining trees or nested function
application since a nesting of the operator inevitably require parenthesis.

/J

On 26 May 2011 14:52, Daniel Fischer daniel.is.fisc...@googlemail.comwrote:

 On Thursday 26 May 2011 14:35:41, Neil Brown wrote:
  foo is the function we want to apply, and eg shows how to apply it in
  do-notation with an argument on each line.  I couldn't manage to remove
  the r$ at the beginning of each line, which rather ruins the whole
  scheme :-(  On the plus side, there's no brackets, it's only two extra
  characters per line, and you can have whatever you like after the r$.

 Wouldn't that be also achievable with

 infixl 0 ?

 (?) :: (a - b) - a - b
 f ? x = f x

 eg = foo
  ? 2 + 1
  ? 'c'
  ? hello ++ goodbye
  ? 3.0

 ?

 ___
 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] Function application layout

2011-05-26 Thread Daniel Fischer
On Thursday 26 May 2011 17:22:10, Jonas Almström Duregård wrote:
 Unfortunately it does not play nice with $.

Yes.

 Also I'm not sure this can be used for defining trees or nested function
 application since a nesting of the operator inevitably require
 parenthesis.

It can't be nested, like ($) can't be nested. You could however add

infixl 1 ??
infixl 2 ???
...

to achieve the possibility of nesting (but you have to be careful with low-
precedence operators if you actually want to use that).

As far as I'm concerned, a left-associative version of ($) would sometimes 
be nice (on the other hand, right-associativity of ($) is sometimes also 
nice), but usually, I don't find parentheses too obnoxious.

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


[Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Srinivasan Balram
folks:

I was advised to post this request here. This is about needs of daily-grind 
enterprise development.

Enterprise developers need 3 categories of books in Haskell urgently:

 (i) Haskell (CookBooks / Recipes)
 (ii) Haskell Enterprise Development i.e. how to connect commercial
 RDBMS and use Haskell along with SQL effectively
 (iii) Haskell Web/Network Development

Books by Don Stewart  Miran Lipovaca are excellent for 
beginner/intermediaries. Erik Meijer's tutorial videos were very useful as 
well. But they are not enough.

This may sound boring, but such books are badly needed today. It's hard to 
convince clients/devs to start projects without such resources.

I am trying to push for Enterprise Haskell projects. Would appreciate pointers 
to resources for doing large scale Haskell development

Thank you

-ram


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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Jason Dagit
On Thu, May 26, 2011 at 9:45 AM, Srinivasan Balram
srinivasan_bal...@marlabs.com wrote:
 folks:
 I was advised to post this request here. This is about needs of daily-grind
 enterprise development.
 Enterprise developers need 3 categories of books in Haskell urgently:
  (i) Haskell (CookBooks / Recipes)

The HaskellWiki has a bit of this CookBook sort of stuff already.  I
haven't read it so I don't know about the quality, but it should be a
good starting point:
http://haskell.org/haskellwiki/Cookbook

And the wikibooks project has some excellent articles about Haskell as well:
http://en.wikibooks.org/wiki/Haskell

  (ii) Haskell Enterprise Development i.e. how to connect commercial
  RDBMS and use Haskell along with SQL effectively

Database connectivity is a weakspot still.  Haskell developers don't
seem to use databases nearly as often as Java developers.  We have
several libraries for this, takusen and hdbc come to mind.  Real-World
Haskell documents using hdbc.

  (iii) Haskell Web/Network Development

This is very broad.  Checkout yesod and snap if you want to generate
content from a Haskell based http server.

I hope that helps,
Jason

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Clint Moore
  While it's not a solution (yet) for a book, would a section or special
section in the wiki be appropriate at least in the beginning?  Our small
company has been collecting cookbook-like recipies and best practices
for a while now but definitely not anything close to as polished or
collated as a book.


On Thu, May 26, 2011 at 04:45:15PM +, Srinivasan Balram wrote:
 folks:
 
 I was advised to post this request here. This is about needs of daily-grind 
 enterprise development.
 
 Enterprise developers need 3 categories of books in Haskell urgently:
 
  (i) Haskell (CookBooks / Recipes)
  (ii) Haskell Enterprise Development i.e. how to connect commercial
  RDBMS and use Haskell along with SQL effectively
  (iii) Haskell Web/Network Development
 
 Books by Don Stewart  Miran Lipovaca are excellent for 
 beginner/intermediaries. Erik Meijer's tutorial videos were very useful as 
 well. But they are not enough.
 
 This may sound boring, but such books are badly needed today. It's hard to 
 convince clients/devs to start projects without such resources.
 
 I am trying to push for Enterprise Haskell projects. Would appreciate 
 pointers to resources for doing large scale Haskell development
 

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Jason Dagit
On Thu, May 26, 2011 at 11:17 AM, Clint Moore cl...@ivy.io wrote:
  While it's not a solution (yet) for a book, would a section or special
 section in the wiki be appropriate at least in the beginning?  Our small
 company has been collecting cookbook-like recipies and best practices
 for a while now but definitely not anything close to as polished or
 collated as a book.

That's exactly what the cookbook part of the wiki is for, put your
stuff there: http://haskell.org/haskellwiki/Cookbook

Jason

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Clint Moore
On Thu, May 26, 2011 at 10:57:42AM -0700, Jason Dagit wrote:
 Database connectivity is a weakspot still.  Haskell developers don't
 seem to use databases nearly as often as Java developers.  We have
 several libraries for this, takusen and hdbc come to mind.  Real-World
 Haskell documents using hdbc.

  For what it's worth, we've had very good luck with Persistent.  Even
though it's not very enterprisey to base a product on an unseasoned
library, it solved so many problems that we just couldn't ignore it.

  Perhaps we should write something in the wiki that goes beyond the
tutorial in the Yesod book.


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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Michael Snoyman
On Thu, May 26, 2011 at 7:45 PM, Srinivasan Balram
srinivasan_bal...@marlabs.com wrote:
 folks:
 I was advised to post this request here. This is about needs of daily-grind
 enterprise development.
 Enterprise developers need 3 categories of books in Haskell urgently:
  (i) Haskell (CookBooks / Recipes)
  (ii) Haskell Enterprise Development i.e. how to connect commercial
  RDBMS and use Haskell along with SQL effectively
  (iii) Haskell Web/Network Development
 Books by Don Stewart  Miran Lipovaca are excellent for
 beginner/intermediaries. Erik Meijer's tutorial videos were very useful as
 well. But they are not enough.
 This may sound boring, but such books are badly needed today. It's hard to
 convince clients/devs to start projects without such resources.
 I am trying to push for Enterprise Haskell projects. Would appreciate
 pointers to resources for doing large scale Haskell development
 Thank you
 -ram

The Yesod book[1] is being actively worked on, and covers web
development with the Yesod web framework. Though many of the chapters
there should be applicable to other systems, such as the enumerators
chapter.

Michael

[1] http://www.yesodweb.com/book

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Andrew Coppin

On 26/05/2011 10:59 AM, Jacek Generowicz wrote:


Any comments on the relative efficiency of the above as compared to

A == B in the context of

data Foo = A | B | C | D | ... lots more ...

?

(I imagine that a Sufficiently Smart Compiler could reduce (==) ::
Person Person to just integer comparison.)


My understanding is that if you have a constructor with no fields, it 
gets allocated as a compile-time constant. In other words, C is just a 
pointer to a static data structure somewhere in the program binary, and 
(==) effectively becomes pointer equity.


OTOH, I am not a GHC developer...

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


Re: [Haskell-cafe] Function application layout

2011-05-26 Thread Casey McCann
2011/5/26 Daniel Fischer daniel.is.fisc...@googlemail.com
 As far as I'm concerned, a left-associative version of ($) would sometimes
 be nice (on the other hand, right-associativity of ($) is sometimes also
 nice), but usually, I don't find parentheses too obnoxious.

I have a whole set of function application/composition/lifting
operators that I'm rather fond of, but it involves replacing some
standard operators, and in particular changes the fixity of ($)
drastically, so it's something I only use in small bits of personal
code that I'll never publish anywhere. The main idea is that there are
two groups of operators, each of which are internally pretty
consistent and vaguely generalized from standard operators.

Very low precedence, function application associates toward argument:
f | x = x | f = f x, () and () for composition, and (=),
(=), (=), and (=) behaving as expected. (|) takes the place of
standard ($), and (|) allows a pipe forward style similar to using
(=).

Mid-to-high precedence, function application associates away from
argument: ($) has the same fixity as ($) and (*), as do the
binding operators (=$) and (=*), the latter being a function I
haven't seen before that does about what you'd expect from the name.
Composition is usually just (.) in most cases because of the style in
which I use these.

What it amounts to is that the first group is used mostly as
pseudo-syntax delimiting expressions that would otherwise be
parenthesized, while the second group is used for writing expressions
that would conceptually be simple one-liners if not for involving
lifting into some sort of Functor. The choice of symbols makes it easy
to remember which is which, even if it's not perfectly consistent.

Mostly, though, this is probably just another reason why my personal
coding style would be bafflingly opaque to most people, so oh well.

- C.

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Brandon Allbery
On Thu, May 26, 2011 at 14:56, Andrew Coppin
andrewcop...@btinternet.com wrote:
 My understanding is that if you have a constructor with no fields, it gets
 allocated as a compile-time constant. In other words, C is just a pointer
 to a static data structure somewhere in the program binary, and (==)
 effectively becomes pointer equity.

When used as a general function, at least; my understanding is that
it's usually reduced to an integer tag (and that this is relied on to
do fast conversions internally)

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


Re: [Haskell-cafe] Efficient object identity (aka symbols as data)

2011-05-26 Thread Andrew Coppin

On 26/05/2011 07:56 PM, Andrew Coppin wrote:

On 26/05/2011 10:59 AM, Jacek Generowicz wrote:


Any comments on the relative efficiency of the above as compared to

A == B in the context of

data Foo = A | B | C | D | ... lots more ...

?

(I imagine that a Sufficiently Smart Compiler could reduce (==) ::
Person Person to just integer comparison.)


My understanding is that if you have a constructor with no fields, it
gets allocated as a compile-time constant. In other words, C is just a
pointer to a static data structure somewhere in the program binary, and
(==) effectively becomes pointer equity.

OTOH, I am not a GHC developer...


...and what I *should* of course have written is go benchmark it. ;-)

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Stephen Tetley
Without support for at least extensible records and better GUI
integration, you'd have a hard time convincing me to use Haskell for
enterprise applications (and I use Haskell every day).

It's not that Haskell isn't a fine language, it's just that doesn't
have sufficient advantage on the state-of-practice that would counter
balance its position as a marginal language. There are good reasons
why enterprise development is conservative, state-of-the-art languages
like Haskell or Erlang excel in domains where they can be disruptive.

Best wishes

Stephen

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Jason Dagit
On Thu, May 26, 2011 at 1:09 PM, Gaius Hammond ga...@gaius.org.uk wrote:

 On 26 May 2011, at 19:22, Clint Moore wrote:

 On Thu, May 26, 2011 at 10:57:42AM -0700, Jason Dagit wrote:

 Database connectivity is a weakspot still.  Haskell developers don't
 seem to use databases nearly as often as Java developers.  We have
 several libraries for this, takusen and hdbc come to mind.  Real-World
 Haskell documents using hdbc.

  For what it's worth, we've had very good luck with Persistent.  Even
 though it's not very enterprisey to base a product on an unseasoned
 library, it solved so many problems that we just couldn't ignore it.

  Perhaps we should write something in the wiki that goes beyond the
 tutorial in the Yesod book.



 Over in OCaml-land, I have taken it upon myself to address this:
 http://gaiustech.github.com/ociml/

Takusen already supports Oracle (and other rdbms) in a resource
precise and good performance way, if that's what you're talking about
implementing:
http://projects.haskell.org/takusen/

Jason

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Gaius Hammond


On 26 May 2011, at 21:34, Jason Dagit wrote:

On Thu, May 26, 2011 at 1:09 PM, Gaius Hammond ga...@gaius.org.uk  
wrote:



Over in OCaml-land, I have taken it upon myself to address this:
http://gaiustech.github.com/ociml/


Takusen already supports Oracle (and other rdbms) in a resource
precise and good performance way, if that's what you're talking about
implementing:
http://projects.haskell.org/takusen/




Ah, interesting - I was only aware of HDBC and HSQL. Which in turn  
begs the question, why isn't this better known among (us) Enterprise  
dev types?




Cheers,



G




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


Re: [Haskell-cafe] Policy for taking over a package on Hackage

2011-05-26 Thread Jason Dagit
On Wed, May 25, 2011 at 4:02 PM, Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 26 May 2011 08:49, wren ng thornton w...@freegeek.org wrote:
 On 5/25/11 1:03 PM, Bryan O'Sullivan wrote:

 On Wed, May 25, 2011 at 5:59 AM, Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com  wrote:

 Well, using the Char8 version.

 Just because you *could* do that, it doesn't mean that you *should*. It's
 a
 bad idea to use bytestrings for manipulating text, yet the only plausible
 reason to have wl-pprint handle bytestrings is so that they can be used as
 text.

 It's worth highlighting that even with the Char8 version of ByteStrings you
 still run into encoding issues. Remember the days before Unicode came about?
 True, 8-bit encodings are often ASCII-compatible and therefore the
 representation of digits and whitespace are consistent regardless of
 (ASCII-compatible) encoding, but that's still just begging for issues. What
 are the semantics of the byte 0xA0 with respect to pretty-printing issues
 like linewraps? Are they consistent among all extant 8-bit encodings? What
 about bytes in 0x80..0x9F? What about 0x7F for that matter?

 I won't say that ByteStrings should never be used for text (there are plenty
 of programs whose use of text involves only whitespace splitting and moving
 around the resultant opaque blobs of memory). But at a bare minimum, the use
 of ByteStrings for encoding text needs to be done via newtype wrapper(s)
 which keep track of the encoding. Especially for typeclass instances.

 *shrug* this discussion on #haskell came about because lispy wanted to
 generate textual ByteStrings (using just ASCII) and would prefer not
 to have the overhead of Text.

Actually, I am okay with Text.  My application is translating GHC Core
to other languages.  I may have misrepresented my position on IRC.
Oops.  In the case of GHC Core, all the unicode bytes are z encoded
[1] away so that I'm certain to just have ascii bytes, and I don't
think performance will be an issue.

Being able to choose between String and Text in the same library is
nice.  Once you add support for letting the user specify their choice
of String or Text, does it really cost that much to add ByteString?

I think there are some cases where ByteString might make sense.  Take
darcs patches.  Darcs does it's best to be encoding agnostic about
patch hunk data, yet the syntax surrounding the hunk data is just
ascii compatible bytes.  Last time I checked, ByteString was still
used to store the patch hunks as just a blob of bytes.  You end up
passing that to some pretty printer code when serializing it, even
though you're doing your best not to dictate the encoding.

I know darcs has had a lot of important utf-8 changes since I looked
at the hunk representation code so what I said above may no longer be
the case.

Admittedly it's a rare case.

Jason

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

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


Re: [Haskell-cafe] Enterprise Haskell -- help

2011-05-26 Thread Jason Dagit
On Thu, May 26, 2011 at 1:43 PM, Gaius Hammond ga...@gaius.org.uk wrote:

 On 26 May 2011, at 21:34, Jason Dagit wrote:

 On Thu, May 26, 2011 at 1:09 PM, Gaius Hammond ga...@gaius.org.uk wrote:


 Over in OCaml-land, I have taken it upon myself to address this:
 http://gaiustech.github.com/ociml/

 Takusen already supports Oracle (and other rdbms) in a resource
 precise and good performance way, if that's what you're talking about
 implementing:
 http://projects.haskell.org/takusen/



 Ah, interesting - I was only aware of HDBC and HSQL. Which in turn begs the
 question, why isn't this better known among (us) Enterprise dev types?

I'm not certain, but I think the biggest problems getting in the way
of Takusen's greater adoption are:
  * It requires a deeper understanding of Haskell than HDBC due to use
of functional dependencies, rank-2 types, and left-fold enumerators.
  * Less documentation than its competitors
  * The name is good (it's the japanese word for oracle), but doesn't
evoke that's clearly a db library in most english speakers.

As the current maintainer (and I've been a really lazy maintainer,
still hoping to find a proper long term maintainer), I'm interested in
any feedback about Takusen.  Things I would like to eventually
implement:
  * HDBC compatibility layer to make it easier to transition from HDBC
to Takusen
  * Replace the left-fold enumerator code with a proper iteratee
library (Takusen is by Oleg but predates his work that generalized the
approach).

Jason

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


[Haskell-cafe] (no subject)

2011-05-26 Thread Gregory Propf
As you my friend I invite you to visit my own site first!. 
http://prospero.ch/friends_links.php?uGIS=45ru4

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


Re: [Haskell-cafe] Parallel compilation and execution?

2011-05-26 Thread michael rice
Are the tools of Control.Parallel comparable to OpenMP?
Michael

--- On Thu, 5/26/11, michael rice nowg...@yahoo.com wrote:

From: michael rice nowg...@yahoo.com
Subject: Re: [Haskell-cafe] Parallel compilation and execution?
To: David Virebayre dav.vire+hask...@gmail.com
Cc: Daniel Fischer daniel.is.fisc...@googlemail.com, 
haskell-cafe@haskell.org
Date: Thursday, May 26, 2011, 9:32 AM

Fair question. I copied the parallel version from:

http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html
but pulled the non-parallel version from a text.
Michael

--- On Thu, 5/26/11, David Virebayre dav.vire+hask...@gmail.com wrote:

From: David Virebayre dav.vire+hask...@gmail.com
Subject: Re:
 [Haskell-cafe] Parallel compilation and execution?
To: michael rice nowg...@yahoo.com
Cc: haskell-cafe@haskell.org, Daniel Fischer 
daniel.is.fisc...@googlemail.com
Date: Thursday, May 26, 2011, 8:56 AM



2011/5/26 michael rice nowg...@yahoo.com

Thank, Daniel

Multiple threads are in evidence in my system monitor, but I wonder why I'm 
getting two different answers, one twice the other. The first is the parallel 
solution and the second is the non.

Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the 
non-parallel one ? 

Michael

===
{-import
 Control.Parallel
nfib :: Int - Intnfib n | n = 1 = 1
       | otherwise = par n1 (pseq n2 (n1 + n2 + 1))                     where 
n1 = nfib (n-1)
                           n2 = nfib
 (n-2)-}
nfib :: Int - Int
nfib n | n = 1 = 1       | otherwise = nfib (n-1) + nfib (n-2)

main = do putStrLn $ show $ nfib 39

=
[michael@hostname ~]$ ghc --make -threaded nfib.hs
[1 of 1] Compiling Main             ( nfib.hs, nfib.o )Linking nfib ...
[michael@hostname ~]$ ./nfib +RTS -N3204668309[michael@hostname ~]$ ghc --make 
nfib.hs
[1 of 1] Compiling Main             ( nfib.hs, nfib.o )Linking nfib
 ...[michael@hostname ~]$ ./nfib102334155[michael@hostname ~]$ 




-Inline Attachment Follows-

___
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] Email spam from my account on May 26, 2011

2011-05-26 Thread Gregory Propf
I just discovered that some evil spammer has somehow gotten my contacts list 
and 
used it to send out a bunch of spam.  This is just to notify you that if you 
get 
an email from me on May 26, 2011 (other than this one or one like it - the 
problem was more extensive than I first thought) it wasn't from me.  Please 
don't add me to your spam filters.  I've changed my password and hopefully 
that's the end of it.  At this point I don't know how they did it though. - Greg___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Escaping of string literals

2011-05-26 Thread Michael Snoyman
Hi all,

I'm working on a program right now that will involve embedding some
static files inside my Haskell program as bytestrings. I've done this
in the past with file-embed[1]. In this case, I have a strange
requirement: I need to be able to modify the embedded data after the
compiler has run. In general, I've gotten the code to work (and will
soon be following up with a blog post explaining). But in this
process, I ran into something I found interesting. If I run this
program:

{-# LANGUAGE TemplateHaskell #-}
import Data.ByteString.Unsafe (unsafePackAddressLen)
import Language.Haskell.TH.Syntax
import qualified Data.ByteString as S

main = do
fromAddr - unsafePackAddressLen 7 $(return $ LitE $
StringPrimL 123\0\456)
print fromAddr
let fromStr = S.pack $ map (toEnum . fromEnum) $(return $ LitE
$ StringL 123\0\456)
print fromStr

I get the result:

123\192\128\45
123\NUL456

My understanding is that GHC is automatically escaping the non-ASCII
characters in the strings. When I use StringL, GHC also automatically
unescapes the bytes, so everything works as expected. In the case of
StringPrimL, there is no point at which the unescaping occurs.

I haven't been able to find the rules on how this escaping functions.
Can anyone point it out to me? Also, for my case, it would be very
useful to be able to bypass the escaping. I can easily do so with a
post-process on the executable to embed raw bytes, but I'm wondering
if there's some way to convince StringPrimL not to do any escaping.

Thanks,
Michael

[1] http://hackage.haskell.org/package/file-embed

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