[Haskell-cafe] Re: Haddock: Failed to create dependency graph (when adding sections with * or a module heading)

2009-08-20 Thread Jared Updike
Simple fix (terrible error message):

Move the ( up to the line with the module name. Previous bad code:

module Data.DualMap
   -- * The @DualMap@ abstract type
   ( DualMap ()
   -- * (?) internal? -- exposed for testing purposes, for now...
   , dmFlip
   -- * converting to and from DualMap
   , toList, fromList, map
   -- * constructing a DualMap
   , empty, null, insert, union

Happy code looks like this:

module Data.DualMap (
   -- * The @DualMap@ abstract type
 DualMap ()
   -- * (?) internal? -- exposed for testing purposes, for now...
   , dmFlip
   -- * converting to and from DualMap
   , toList, fromList, map
   -- * constructing a DualMap
   , empty, null, insert, union

Simple enough. I found this out by downloading DList [1] from hacakge
and gutting it and replacing the code with my own code. When DList
worked with 'cabal haddock' and mine didn't (when I tried to add some
asterisks), I looked at the difference between the files and sure
enough my parenthesis was on the wrong line.

BTW I highly recommend DList as a starting place for a new Haskell
project instead of hnop [2].

  Jared.

[1] http://hackage.haskell.org/package/dlist-0.5
[2] http://semantic.org/hnop/


On Wed, Aug 19, 2009 at 9:45 AM, Jared Updike jupd...@gmail.com wrote:

 I compiled and installed haddock-2.4.2 from the tarball source.
 Adding a few simple comments to the code here:
   https://dl.getdropbox.com/u/143480/doc/DualMap.hs
 and running haddock
 $ haddock -h -o doc Data/DualMap.hs
 Warning: Data.DualMap: could not find link destinations for:
     Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show GHC.Base.Ord 
 GHC.Base.Bool Data.Set.Set
 yields:
   https://dl.getdropbox.com/u/143480/doc/Data-DualMap.html

 Things look good. (Note that this module only depends on libs that ship with 
 GHC and no other source modules.)
 However, when I try to add sections (a 
 la http://www.haskell.org/haddock/doc/html/ch03s04.html#id289234 ) in the 
 comments with -- * test I get:
 $ haddock -h -o doc Data/DualMap.hs
 Data/DualMap.hs:20:0: parse error on input `-- * test'
 haddock: Failed to create dependency graph
 I have no idea where to begin getting this to work since this error message 
 only tells me that Haddock.Interface.depanal returned Nothing (according to a 
 grep of the haddock sources) but not how to stop the dependency analysis from 
 failing. Perhaps I need some more command line arguments or references to 
 missing link destinations in GHC/base/containers documentation or some 
 haddock config file?
 Searching Google yielded plenty of cabal build errors of the same ilk for 
 packages on hackage but nothing about how to fix them.

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


[Haskell-cafe] Haddock: Failed to create dependency graph (when adding sections with * or a module heading)

2009-08-19 Thread Jared Updike
I compiled and installed haddock-2.4.2 from the tarball source.

Adding a few simple comments to the code here:

  https://dl.getdropbox.com/u/143480/doc/DualMap.hs

and running haddock

$ haddock -h -o doc Data/DualMap.hs
Warning: Data.DualMap: could not find link destinations for:
Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show GHC.Base.Ord
GHC.Base.Bool Data.Set.Set

yields:

  https://dl.getdropbox.com/u/143480/doc/Data-DualMap.html

Things look good. (Note that this module only depends on libs that ship with
GHC and no other source modules.)

However, when I try to add sections (a la
http://www.haskell.org/haddock/doc/html/ch03s04.html#id289234 ) in the
comments with -- * test I get:

$ haddock -h -o doc Data/DualMap.hs
Data/DualMap.hs:20:0: parse error on input `-- * test'
haddock: Failed to create dependency graph

I have no idea where to begin getting this to work since this error message
only tells me that Haddock.Interface.depanal returned Nothing (according to
a grep of the haddock sources) but not how to stop the dependency analysis
from failing. Perhaps I need some more command line arguments or references
to missing link destinations in GHC/base/containers documentation or some
haddock config file?

Searching Google yielded plenty of cabal build errors of the same ilk for
packages on hackage but nothing about how to fix them.

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


Re: [Haskell-cafe] Haskell Logo Voting has started!

2009-03-17 Thread Jared Updike
Wow, I had a nice list of all the numbers of my favorites ranked
before voting began (like a week ago), and here they are all
re-numbered, rendering all that waste of time... even more of a waste
of time...

  Jared.

On 3/17/09, Eelco Lempsink ee...@lempsink.nl wrote:
 Hi there!

  I updated a couple of logo versions and ungrouped and regrouped the
 (former) number 31.  Other than that, there was nothing standing in the way
 of the voting to begin imho, so I started up the competition.

  By now, I suppose everybody should have received their ballot.  If you
 think you should have received it but didn't, please report it, I can resend
 the invitation.  Also, for people not directly subscribed to the
 haskell-cafe mailing list, you can still send ballot requests until the end
 of the competition (March 24, 12:00 UTC).  Make sure the message contains
 'haskell logo voting ballot request' (e.g. in the subject).

  Depending on the winner of this voting round we can decide whether we need
 to continue with variations.  Jared Updike already offered to donate a bit
 of time to help create several variations.  But for now, good luck with
 sorting those options! :)

  --
  Regards,

  Eelco Lempsink


 ___
  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] Re: Logo Preferences

2009-03-10 Thread Jared Updike
I agree that we should use the first round of voting to learn what the
general consensus of the Haskell community is on a logo design idea
(and to filter out the non-viable logos).

In the spirit of bikeshedding, I would love to see---and would
volunteer to spend part of a day editing, say, the top one or two
logos, in Photoshop---generating numerous variations on fonts, colors
(text, emblem and background), and relative font/emblem sizes.
(Alternately, the original author of the favorite logo(s) could
produce said variations.) Then I think we should vote on the final
minor variations.

I can *almost* picture a few of the current logos becoming the Final
logo, but not As Is; there are many great ideas but some of them (or
combinations of a few of them) could be improved in minor ways,
bringing things (at least to me) up to professional level for a logo.
(cf. the python.org logo)

  Jared.

On 3/9/09, Ian Lynagh ig...@earth.li wrote:
 On Mon, Mar 09, 2009 at 11:13:40AM +, Sebastian Sylvan wrote:
  
   Another reason condorcet voting is nice is that there is no need to group
   similar items together.


 I think the plan is that once a logo class is chosen, we'll have
  another vote for the actual colour scheme etc to be used, if applicable.

  Yes, we could have done this in a single vote, but then people would
  need to spend time creating 30 variants of each logo, and we'd be
  ranking 3000, rather than 100, options.


  Thanks

 Ian


  ___
  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] Re: Data.Map: Enumerating ordered subset of keys

2009-02-09 Thread Jared Updike
I had a similar thought. That will probably do the trick.

  Jared.

On 2/8/09, Svein Ove Aas svein@aas.no wrote:
 On Mon, Feb 9, 2009 at 8:02 AM, Jared Updike jupd...@gmail.com wrote:
   It looks like two Map.splits will do what I need except for allowing
   more exact testing of = vs.  (since == elements are left out of both
   maps...?)
  

 If your key is an instance of Enum, you can use succ/pred to work
  around that little problem.

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


Re: [Haskell-cafe] Re: Data.Map: Enumerating ordered subset of keys

2009-02-09 Thread Jared Updike
On 2/8/09, Anish Muttreja anishmuttr...@gmail.com wrote:
 Maybe you wantData.Map.partition (\key - key = key1  key = key2) map

This will return what I want, but partition is O(n) and touches all
the keys, so if I had a million keys and only 2 of them matched the
key1..key2 range, it would still visit all of them before it
enumerated the ones that satisify the predicate. I don't believe
laziness would help here.

  HTH,
  Anish


  On Sun, 08 Feb 2009 23:02:37 -0800, Jared Updike jupd...@gmail.com wrote:


 
  It looks like two Map.splits will do what I need except for allowing
  more exact testing of = vs.  (since == elements are left out of both
  maps...?)
 
   Jared.
 
  On 2/8/09, Jared Updike jupd...@gmail.com wrote:
 
   I would like to enumerate a subset of keys in a Map satisfying \ key
= key1  key = key2 but in the expected, reasonable amount of time
(e.g.  O(log(n)) + O(m) for n total keys and m keys in the subset).
(Or key  key1 and/or key  key2 or some such combination).
  
Is there an appropriate idiom or combination of library functions to
accomplish this, short of digging into the code for Data.Map and
writing such a function for a forked version of Data.Map?
  
For example I could try something like a Set.split of a Set.split of
Map.keysSet of my original map, but will laziness magically do what I
really want? which is to walk down the tree to key1 (or the nearest
key  key1) and enumerate keys in order until key2 is reached?
  
Data.Map almost looks like what I need if I can do this.
  
  
Jared.
  
  
  ___
  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] Data.Map: Enumerating ordered subset of keys

2009-02-09 Thread Jared Updike
On 2/8/09, Evan Laforge qdun...@gmail.com wrote:
 I have a little util library with various map functions.  'within' is
  almost what you want, except it's half-open.  You can make an
  inclusive one by pulling the lowest element off the above map.

  I'm also curious if there's a better way to do this...

  -- | Like Map.split, except include a matched key in the above map.
  split_map :: (Ord k) = k - Map.Map k a - (Map.Map k a, Map.Map k a)
  split_map k fm = (pre, post')
 where
 (pre, at, post) = Map.splitLookup k fm
 post' = maybe post (\v - Map.insert k v post) at

  -- | Split the map into the maps below, within, and above the given range.
  -- @low@ to @high@ is half-open, as usual.
  split3_map :: (Ord k) = k - k - Map.Map k a
 - (Map.Map k a, Map.Map k a, Map.Map k a)
  split3_map low high fm = (below, within, way_above)
 where
 (below, above) = split_map low fm
 (within, way_above) = split_map high above

  within low high fm = let (_, m, _) = split3_map low high fm in m

This looks right to me (correct time complexity). It should do what I
need. I will test it and see what I discover.

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


[Haskell-cafe] Data.Map: Enumerating ordered subset of keys

2009-02-08 Thread Jared Updike
I would like to enumerate a subset of keys in a Map satisfying \ key
= key1  key = key2 but in the expected, reasonable amount of time
(e.g.  O(log(n)) + O(m) for n total keys and m keys in the subset).
(Or key  key1 and/or key  key2 or some such combination).

Is there an appropriate idiom or combination of library functions to
accomplish this, short of digging into the code for Data.Map and
writing such a function for a forked version of Data.Map?

For example I could try something like a Set.split of a Set.split of
Map.keysSet of my original map, but will laziness magically do what I
really want? which is to walk down the tree to key1 (or the nearest
key  key1) and enumerate keys in order until key2 is reached?

Data.Map almost looks like what I need if I can do this.

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


[Haskell-cafe] Re: Data.Map: Enumerating ordered subset of keys

2009-02-08 Thread Jared Updike
It looks like two Map.splits will do what I need except for allowing
more exact testing of = vs.  (since == elements are left out of both
maps...?)

  Jared.

On 2/8/09, Jared Updike jupd...@gmail.com wrote:
 I would like to enumerate a subset of keys in a Map satisfying \ key
  = key1  key = key2 but in the expected, reasonable amount of time
  (e.g.  O(log(n)) + O(m) for n total keys and m keys in the subset).
  (Or key  key1 and/or key  key2 or some such combination).

  Is there an appropriate idiom or combination of library functions to
  accomplish this, short of digging into the code for Data.Map and
  writing such a function for a forked version of Data.Map?

  For example I could try something like a Set.split of a Set.split of
  Map.keysSet of my original map, but will laziness magically do what I
  really want? which is to walk down the tree to key1 (or the nearest
  key  key1) and enumerate keys in order until key2 is reached?

  Data.Map almost looks like what I need if I can do this.


   Jared.

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


[Haskell-cafe] Functional MetaPost in 5 Steps

2008-10-23 Thread Jared Updike
I'm interested in using Functional MetaPost on Mac OS X (or FreeBSD).
I'm looking for a tutorial like:

  http://haskell.org/haskellwiki/Haskell_in_5_steps

but for FMP. I can't even get a simple example to show up in a PDF file:
---
import FMP
... (see full code below)
myPicture = text Hello World
main = do
   print $ emit $ metaPost 1 myPicture params
--
When run, this emits MetaPost, which, after running through my shell
script, below, won't show up in my PDF... (this same TeX file will
show an .eps figure I made with PyX, the Python equivalent of FMP,
when I change includegraphics to use that file instead of test.1)

What am I missing? If I can get this working I will gladly write the
FMP 5 Step Tutorial. I like the idea of using FMP but I can't for the
life of me understand why running a toy example is so non-trivial.
(Not to mention undocumented... the manual and tutorials are very
compelling but they don't mention how to get a viewable PDF out of any
of the otherwise enticing examples.)

  Jared.

Relevant almost working code:

Test.hs:
---

import FMP

params = Parameters {
  prolog = verbatimtex\n\
 \\\documentclass{article}\n\
 \\\begin{document}\n\
 \etex\n\n\
 \input boxes\n\
 \input FuncMP\n\n,
  epilog= \n\n\\end,

  defaultDX= 3,
  defaultDY= 3,
  textDX= 2,
  textDY= 2,

  newmp= True,

  funcmpRTS= IGNORE, --+RTS -H40m -K3M -RTS,
  funcmpBin= IGNORE, -- ~/FuncMP-1.2/FuncMP,

   mpBin= IGNORE -- MPINPUTS=:~/FuncMP-1.2 TEX=latex mpost 
}

myPicture = text blah

main = do
   print $ emit $ metaPost 1 myPicture params

--

test.tex:
---
\documentclass[12pt]{article}
\usepackage[dvipdfm]{graphicx}

\begin{document}

\section*{Heading}

\begin{figure}

\begin{center}
\includegraphics{test.1}
\end{center}

\end{figure}

\end{document}
---

shell script:
--
#!/bin/sh

ghc --make Test.hs  \
  ./Test  test.mp  \
  mpost test.mp  \
  latex test.tex  \
  latex test.tex  \
  dvipdfm test.dvi  \
  open test.pdf   # MacOS X runs my pdf in preview
---
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-06 Thread Jared Updike
  If you substitute your mpfr_set_signed_int for the one below, the noworks
 should become works.

Yes, this works perfectly. Thank you for saving my project! (Had I
known about HMPFR when I started this project, I would have just used
that instead of rolling my own, but it looks like HMPFR was uploaded
at the end of September though I started rolling my own bindings in
June or July... you know how life goes: work, moving, vacation, wife
starting grad school, etc.)

Last night I was seriously considering dropping work on my current
project and joining the effort to replace GMP in GHC as the only
solution. But now I

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


[Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-05 Thread Jared Updike
In order to create an arbitrary precision floating point / drop in
replacement for Double, I'm trying to wrap MPFR (http://www.mpfr.org/)
using the FFI but despite all my efforts the simplest bit of code
doesn't work. It compiles, it runs, but it crashes mockingly after
pretending to work for a while. A simple C version of the code happily
prints the number 1 to (640 decimal places) a total of 10,000 times.
The Haskell version, when asked to do the same, silently corrupts (?)
the data after only 289 print outs of 1.... and after 385
print outs, it causes an assertion failure and bombs. I'm at a loss
for how to proceed in debugging this since it should work.

The code can be perused at http://hpaste.org/10923 (and attached) and
downloaded at http://www.updike.org/mpfr-broken.tar.gz

I'm using GHC 6.83 on FreeBSD 6 and GHC 6.8.2 on Mac OS X. Note you
will need MPFR (tested with 2.3.2) installed with the correct paths
(change the Makefile) for libs and header files (along with those from
GMP) to successfully compile this.

Why does the C version work, but the Haskell version flake out? What
else am I missing when approaching the FFI? I tried StablePtrs and had
the exact same results.

Can someone else verify if this is a Mac/BSD only problem by compiling
and running my code? (Does the C executableworks work? Does the
Haskell executable noworks not work?) Can anyone on Linux and
Windows attempt to compile/run and see if you can get the same
results?

  Jared.

P.S. I actually have much more code, having wrapped dozens of
functions from the MPFR library and created instances using
unsafePerformIO and foreignPtrs and all that useful high level
Haskell/pure stuff--- all of which basically works perfectly except
that it doesn't work at all since it crashes mysteriously after
pretending to work at first. I had to narrow it down to something
simple and the Print 1.0... 10,000 times was the best I could
do. If I can get that working, I will then move on to something like
the factorial of 1000 (printing intermediate values), which also works
in C, but not Haskell, and after that, maybe everything will just
work and I can use/publish this library!

- works.c

#include stdio.h
#include stdlib.h
#include string.h

#include gmp.h
#include mpfr.h
#include mpfr_ffi.c

int main()
{
  int i;
  mpfr_ptr one;

  mpf_set_default_prec_decimal(640);

  one = mpf_set_signed_int(1);
  for (i = 0; i  1; i++)
{
  printf(%d\n, i);
  mpf_show(one);
}
}



 Main.hs --- Doesn't work!

module Main where

import Foreign.Ptr( Ptr, FunPtr )
import Foreign.C.Types( CInt, CLong, CULong, CDouble )
import Foreign.StablePtr  ( StablePtr )

data MPFR = MPFR

foreign import ccall mpf_set_default_prec_decimal
c_set_default_prec_decimal  :: CInt - IO ()
setPrecisionDecimal :: Integer - IO ()
setPrecisionDecimal decimal_digits = do
c_set_default_prec_decimal (fromInteger decimal_digits)

foreign import ccall mpf_show
   c_show   :: Ptr MPFR - IO ()

foreign import ccall mpf_set_signed_int
   c_set_signed_int :: CLong - IO (Ptr MPFR)

showNums k n = do
   print n
   c_show k

main = do
   setPrecisionDecimal 640
   one - c_set_signed_int (fromInteger 1)
   mapM_ (showNums one) [1..1]



-- mpfr_ffi.c

// a little bit of wrapper code... this may be where the problem is
// but since the (working) C code uses this and has no problems, I don't
// understand why the Haskell code appears to be corrupting the limbs
(the mantissa)

#include stdio.h
#include stdlib.h
#include string.h

#include gmp.h
#include mpfr.h

void mpf_show(mpfr_ptr x)
{
  mpfr_out_str(stdout, 10, 0, x, GMP_RNDN);
  printf(\n);
}


#define LOG2_10   3.3219280948873626
#define IEEE_BITS 53
void mpf_set_default_prec_decimal(int dec_digits)
{
  double bits = LOG2_10 * dec_digits;
  int ibits = (int)bits;
  double ddec;
  int dec;
  //printf(DEC_DIGITS = %d\n, dec_digits);
  //printf(IBITS  = %d\n, ibits);
  ddec = ibits / LOG2_10;
  dec = (int)ddec;
  //printf(DEC= %d\n, dec);
  while (dec  dec_digits)
  {
ibits++;
//printf(IBITS  = %d\n, ibits);
ddec = ibits / LOG2_10;
dec = (int)ddec;
//printf(DEC= %d\n, dec);
  }
  mpfr_set_default_prec(ibits);
}

mpfr_ptr mpf_new_mpfr()
{
  return (mpfr_ptr)malloc(sizeof(__mpfr_struct));
}

mpfr_ptr mpf_set_signed_int(int x)
{
  mpfr_ptr result = mpf_new_mpfr();
  if (result == NULL)
return NULL;
  mpfr_init_set_si(result, x, GMP_RNDN);
  return result;
}



--- Makefile


CC  = gcc
HC  = ghc
INCLUDE = -I/home/private/local/include -I/usr/local/include
-I/opt/local/include
LIBS= -L/opt/local/lib -L/usr/local/lib

all:works noworks

works:  mpfr_ffi.o works.o
$(CC) -o works works.o -lgmp -lmpfr $(INCLUDE) $(LIBS)

works.o:works.c
$(CC) -c works.c $(INCLUDE)


Re: [Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-05 Thread Jared Updike
Thanks for trying out my code. I'm glad it's not particular to my system.

I suspected it had to do with the GHC RTS monkeying around with the
heap (lower precisions print more iterations and maybe aren't moving
through the heap as fast?) but I think when I added a statement to
print out the hex address for each Ptr MPFR that those pointers (to
'one') in particular weren't getting moved. Likely the stuff living in
the heap, pointed at in the MPFR struct, specifically the pointer to
the limbs (the mantissa or actual digits of the number) are getting
kludged.. I don't really understand why this is the case when I don't
think I'm allocating a lot of the heap or anything, just printing the
same number over and over... Is there a space leak somewhere? (I can
also verify that mpf_new_mpfr is only getting called once per program
run by appending to a file each time it gets called). How do I tell
GHC leave this mess and anything in the C heap completely alone?

  Jared.

On 10/5/08, Alexander Dunlap [EMAIL PROTECTED] wrote:
 On Sun, Oct 5, 2008 at 5:38 PM, Chris Mears [EMAIL PROTECTED] wrote:
   Jared Updike [EMAIL PROTECTED] writes:
  
   Can someone else verify if this is a Mac/BSD only problem by compiling
   and running my code? (Does the C executableworks work? Does the
   Haskell executable noworks not work?) Can anyone on Linux and
   Windows attempt to compile/run and see if you can get the same
   results?
  
   I can't help you fix the problem, but can confirm that it behaves as you
   describe on my Linux system.  The program works produces correct
   output, but noworks gives:
  
   ==
   [...]
   290
   
 1.0
   291
   
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892325510831739618679352919703855747262870175016933079782350322237289103929997053812694251557912158924211585973481445271933347978517620
   292
   [...]
   384
   
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892325510831739618679352919703855747262870175016933079782350322237289103929997053812694251557912158924211585973481445271933347978517620
   385
   
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892281684860507747503219323326708248193093246881500522519352192987169395899758472958160241015525770811984166890239749344848735134541218
   386
   ../get_str.c:149:  assertion failed: size_s1 = m
   Aborted
   ==
  
   All the values from 291-384 are the same, but 385 is slightly different.

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

  My results (from Linux i686) are slightly different. I am getting

  [...]
  287

Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Jared Updike

Maybe I've misused the word segfault.
What happened is:
The programme consumed more and more memory (according to top),
kswapd started to have a higher CPU-percentage than my programme,
programme died, system yelling 'Speicherzugriffsfehler', top displays
'kswapddefunct'.
I believe that means my programme demanded more memory than I have available
(only 256MB RAM + 800MB swap). Is that a segfault or what is the correct
term?


I thought a segfault was when a program reads or writes to protected
memory (for example, out of bounds on an array, or dereferencing a
null pointer, etc. things mostly avoided in Haskell). Luckily there
are lots of fun ways to crash computers! I've heard your heap
overflow called exploding because of how the process rapdily
expands its memory usage, filling all available space, causing system
collapse.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] map (-2) [1..5]

2006-09-08 Thread Jared Updike

In C, it wouldn't be, since there, unary ops always bind tighter than infix
ops, and the precedences used in C are also used in C++, Java, C#,
Javascript etc, and even ISO Prolog obeys the rule that unary minus binds
tighter so making unary minus have the same precedence as infix minus just
makes Haskell syntax difficult to parse for anyone coming from one of these
other very popular languages. Imho, for better or worse, C has established a
kind of de-facto standard that unary ops always bind tighter than infix ops
in programming languages ;-)


... in **programming languages that don't have infix exponeniation**.
You missed Ruby, Python, Matlab, Mathematica (not generally a good
inspiration for syntax but it has a rather large following and almost
20 years of usage), and TI calculators. These all have ^ or ** bind
tighter than unary - to go along with math, not C. Since it didn't
happen we will never know **if C had had infix exponentiation, what
would the precedence have been relative to unary ops** or indeed if
they dropped infix exponentiation, preferring pow(x,y), for exactly
that reason, or what.

All this talk is a design choice and folks will naturally disagree and
the right balance for *everything*, especially since all their
conflicting interactions yield so many mutually exclusive possible
outcomes. I suppose I just disagree that C has said the last word
about infix/unary ops because C never spoke up on the problem of unary
negation and exponentiation. (And if it had, would I agree anyway? :-)

I still get tripped up by unary negation in Haskell, especially with
sections, parenthese, etc. But that's what hugs or ghci are for.


Also, it's a good example of why we should *not* have unary minus, since the
above could be written with no ambiguity as:
negate (4 ^ 2)
or better still:
negate (expNat 4 2)
because this would free the ^ symbol for some more widely applicable use,


True. I would much rather be forced to type negate (4 ^ 2) than have
-4^2 return 16 instead of -16 because the - got lexed into -4.
Alternately, if you want unary ops to bind the tightest, then just
eliminating ^ and replacing it with expNat, etc. would solve any
precedence problems with unary minus.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] head as a total function

2006-09-07 Thread Jared Updike

 it was the first imperative language supporting closures, after all

Uh, what about lisp?


For those who read the Foozles slides posted earlier [0], I must say
he nailed this one, on slide 2.


The (MIT) lisp 1.4 manual (ca. 1965) refers to
FUNCTION differing from QUOTE in that it handled free variables
correctly; I take this to mean that at least a primitive form of
closure was provided.


Steele's work on Scheme helped Lisp programmers take lexical scoping
seriously [1]; these ideas and a method for efficient implementation
were attributed to Algol [2]. That lexical scope was available in some
dialect of Lisp, even very early on, doesn't surprise me (and
according to [3] is the case). But I do think dynamic scoping took a
while to die out as generally accepted Lisp practice (it does still
exist in Common LISP, with a special keyword, IIRC) and that Scheme
(late 1970s) helped to effect that.


Moreover, a language that provides SET/SETQ,
RPLACA/RPLACD and the PROG feature (including labels and a goto) surely
qualifies as imperative?


Haskell has been called the best imperative programming language ever.
:-) I mean, Haskell has IORef and friends, right?

 Jared.

[0] http://hope.cs.rice.edu/twiki/pub/WG211/M3Schedule/foozles.pdf
[1] Tenth paragraph, this page: http://www.lisp.org/table/Lisp-History.html
[2] Steele's Rabbit compiler paper, p.13. See also Steele's Lambda papers
[3] Steele and Gabriel, Evolution of Lisp.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Re: data structures question

2006-08-31 Thread Jared Updike

 And stop calling me Shirley.



Could you please be a bit more explicit? Have I offended anyone?


This is a reference to a joke from the movie Airplane:

Surely, you can't be serious.
I am serious, and stop calling me Shirley.

I imagine it meant nothing personal.

 Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to force HTML (rather than XML) output from Haskell XML Toolbox?

2006-08-30 Thread Jared Updike

which is close but not exactly as wanted. The meta (and I expect
other tags like br will have the same) tag has closing slash as it
would have in XML (XHTML), but not in HTML. Also the DOCTYPE has been
lost.


I've had similar problems outputting XHTML. For example, naive output
(correct according to the definition of XML and (X)HTML) breaks in IE
because IE doesn't like link ... /  or script ... / tags, instead
it wants link .../link  and script .../ script. Pages with
correct XHTML, but with these unhappy tags in the HTML head, load
in IE as a blank page! To make pages that will load in 90% of
browsers, I've always generated my own (X)HTML with special pretty
printers that know these caveats and a few others.

 Jared.

On 8/30/06, Dimitry Golubovsky [EMAIL PROTECTED] wrote:

Hi,

I am developing a code that reads a HTML page (template), modifies it
(adds some stuff) and then writes the output file which is to be HTML,
not XML.

I use hxt-5.3 (but I may upgrade if necessary).

It is desired to preserve the original HTML template pieces maximally
close to the original.

But output appears to be closer to XML rather than HTML.

The code I use:



  let attrs = [(a_parse_html, 1),
   (a_output_xml, 0),
   (a_encoding,   utf8)]

  (res, err, rc) - getXmlDocument attrs (fromJust $ tmplPath dopt)

  putXmlDocument attrs (fromJust $ outPath dopt) res

=

for this input HTML file:

=

!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
head
  titleEmpty Page Template for Haskell Applications/title
  meta http-equiv=content-type content=text/html; charset=UTF-8
/head
body
/body
/html

=

outputs:

=

html
head
  titleEmpty Page Template for Haskell Applications/title
  meta http-equiv=content-type content=text/html; charset=UTF-8/
/head
body
/body
/html

=

which is close but not exactly as wanted. The meta (and I expect
other tags like br will have the same) tag has closing slash as it
would have in XML (XHTML), but not in HTML. Also the DOCTYPE has been
lost.

Is this something hxt is not able to provide, or just a bug fixed
since 5.3? Or should I write my own output code (because I am
guessing, hxt functionality regarding manipulation over XML trees is
sufficient for what I need)? Or should I use another package?

--
Dimitry Golubovsky

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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to force HTML (rather than XML) output from Haskell XML Toolbox?

2006-08-30 Thread Jared Updike

Just a bit of info on the br, IE treats br/ as a line break, but
br/br as 2 line breaks. Just in case you go for the obvious
solution of always expanding out a/ to a/a, br won't work.


but br / with a space works.  And this applies to most tags with
this behavior---the space helps, and it validates with W3C XHTML
Validator.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fran - Functional Reactive Animation

2006-08-23 Thread Jared Updike

I think this works:

 http://haskell.org/edsl/pansharp.html

 Jared.

On 8/23/06, HIGGINS Neil (ENERGEX) [EMAIL PROTECTED] wrote:






Fran is a Haskell library (or embedded language) for interactive
animations with 2D and 3D graphics and sound. See
http://www.conal.net/fran/ and
http://research.microsoft.com/research/downloads/download.aspx?FUID=c9eff407-ce59-4a2a-90cb-de099a9bacbd

I would like to use Fran as a rapid prototyping environment for animations,
but it appears to be broken under WinHugs.

I'm looking for someone with much better Haskell prowess than myself who
might be able resurrect Fran under WinHugs. Unfortunately I can only offer
my gratitude in return.

It's a long shot, I know.

Kind regards,
Neil Higgins
Snr Strategic Planning Engineer
ENERGEX
Em: [EMAIL PROTECTED]
Ph:  3407 4800
Fx:  3407 4832


*
 This email message (including any file attachments transmitted with it)
 is for the sole use of the intended recipient(s) and may contain
 confidential and legally privileged information. Any unauthorised
 review, use, alteration, disclosure or distribution of this email
 (including any attachments) by an unintended recipient is prohibited.
 If you have received this email in error, please notify the sender by
 return email and destroy all copies of the original message.
 Any confidential or legal professional privilege is not waived
 or lost by any mistaken delivery of the email.
 ENERGEX accepts no responsibility for the content of any email
 which is sent by an employee which is of a personal nature.
 Sender Details:
 ENERGEX
 GPO Box 1461 Brisbane QLD Australia 4001
 +61 7 3407 4000
 http://www.energex.com.au
 ENERGEX policy is to not send unsolicited electronic messages. Suspected
 breaches of this policy can be reported by replying to this message
 including the original message and the word UNSUBSCRIBE in the subject.
*

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






--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] implementing a csv reader

2006-08-22 Thread Jared Updike

Now I need to find something else for practice.  Is there anything
related to data analysis/statistics that is lacking is Haskell?


A native implementation of multiparameter data fitting (requires some
linear algebra) like:

Sec 15.4 of http://www.library.cornell.edu/nr/bookcpdf.html
or 
http://www.gnu.org/software/gsl/manual/html_node/Multi_002dparameter-fitting.html#Multi_002dparameter-fitting

would be nice, unless it exists. (There might be a GSL binding in
Haskell for this but I'd rather use a native library.)

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Memoizing longest-common-subsequence

2006-08-22 Thread Jared Updike

(Sorry for the late reply; have been on holiday.)


No problem. Your email system was kind enough to say when you'd be back :-)


I've used it to diff fairly large files (hundreds of K's, if not Megs)
where there were few differences. It seemed to perform OK, and in cases
where GNU diff (or whatever comes with MSYS) failed.


Thanks for posting the code. It works on pretty large data sets (for
example, a thousand Strings each) and I have a hunch that if I use
Data.ByteString it would even work fast enough on my quarter meg text
files (split on words, ~40,000 and ~50,000 words each) to use in place
of GNU sdiff or diff. Did you use FastPackedString or ByteString to
get performance you alluded to?

I'll return with the results of my experiments with ByteString and
Diff, although I imagine it should be pretty fast since darcs is able
to get acceptable speed on large datasets using (I think) ByeString
and a Haskell implementation of Myers diff.

Cheers,
 Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell wiki: most popular pages

2006-08-18 Thread Jared Updike

I feel that Haskell is missing some basic string manipuation functions, like
- replacing all occurances of one substring (or sublist) with another
string (or list).
- tokenize a string by an arbitrary delimeter


This came up not too long ago:
 http://www.haskell.org/pipermail/haskell-cafe/2006-July/thread.html#16559
Ironically this thread talks about how the same topic came up two
years ago and no consensus was reached. So I made a skeleton page to
discuss/maybe reach consensus on this. Please flesh it out and hack it
to pieces!

http://www.haskell.org/haskellwiki/Prelude_function_suggestions


I know many of these functions can be written in Haskell without much
effort.


Let the work begin (record opinions and any semblance of consensus).

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] map (-2) [1..5]

2006-08-17 Thread Jared Updike

I'd have thought it would have been simpler to just make the rule that -2
(no spaces between '-' and '2') would be a single lexeme


I'd have thought so too, until I implemented a parser with exponentiation.
It is easy to get confused and make a parser that is too eager to include
the minus sign as part of a numeric literal instead of as subtraction
or unary negation (all you parser-with-exponentiation-implementers out
there, pay attention!). And since many
programming languages (specifically C) don't have syntax for
exponentation as an infix operator (nothing authoritative to copy
precedence from), I had to implement this myself, get confused and see
that it was so---(I tried making the literal include the minus sign if
there was no space). I never noticed this before because in a C-like
language:

-4*2is the same whether parsed as

(-4)*2   or  -(4*2)

but

-4^2is not the same whether parsed as

(-4)^2  or  -(4^2)  (the correct version)

Basically, before someone argues this with me,

-4^2 should parse the same as

- 4^2 which should be the same thing as

0 - 4^2

(you don't want -4^2  and 0-4^2 giving different results, no matter
how much you think whitespace belongs around operators)

Math follows these same rules but it's slightly harder to get confused
because of the way exponentiation is written by superscripting. See
http://mathforum.org/library/drmath/view/55709.html and
http://mathforum.org/library/drmath/view/53240.html.

I thought this was surprising, that parsing the minus sign into
lexemes would cause such confusion, but it is born out in many places
(Python, Frink (http://futureboy.homeip.net/frinkdocs/FrinkApplet.html),
etc.)

(Note: this email isn't about Haskell specifically and I'm sure issues
with the minus sign in Haskell are more confusing than this; this is
purely about parsing a C-like langauge extended with exponentionation
and how including the minus sign in the literal is dangerous in
conjuntion with exponentiation.)

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] map (-2) [1..5]

2006-08-17 Thread Jared Updike

I'd also argue that in maths the necessary brackets are implied by the
superscripting syntax


ASCII text parsing issues aside, in math,

   2
-4   =?

(No you cannot ask if there is space between the 4 and the - symbol,
or if I meant (-4)^2   or -(4^2), or if I wrote a negative sign or a
subtract sign. I believe there is only one standard interpretation
here.)


they can only get in through the back door of evaluation
which just doesn't seem right.


Constant folding can eliminate any runtime cost, so effectively 0 - 2
== negative 2 at compile time. No problem.

 Jared

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] map (-2) [1..5]

2006-08-17 Thread Jared Updike

Yes but my point is that -4^2 is not the same as

2
-4

because the latter by convention means - (4^2).



In other words, superscripts bind tighter than prefix ops but prefix ops
bind tighter than infix.


I see. My point is that there already exists a convention[1] that the
way to type in
  2
-4
is -4^2 which means -(4^2) not (-4)^2 because - as a prefix op has the
same precedence as binary subtraction, not super tight like normal
prefix ops (i.e. normal function application) as you would like it to
be (if I understand correctly). You are welcome to break an existing
(unofficial) convention for the sake of lexical syntax[2].

Cheers,
 Jared.

[1] On my TI89 calculator (where there are even two - buttons: a
little negative unary button and a binary subtract button). It
pretty prints
  2
-4 =  -16
when I punch in -4^2  (where - is the negative unary button). The
answer is -16. Python (-4**2 = -4 ** 2 = - 4 ** 2 = -16) and Matlab
and Mathematica agree (-4^2 = -4 ^ 2 = - 4 ^ 2 = -16).

[2] http://wadler.blogspot.com/2006/01/bikeshed-coloring.html

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Int-[Char] conversion

2006-08-16 Thread Jared Updike

putStrLn (Product:  ++ convertnumbertostring(pp))


Also, there is a predefined function called 'print' where

print x = putStr (convertnumbertostring x)
i.e.
print x = putStr (show x)

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


Re: [Haskell-cafe] Can someone explain this typing restriction?

2006-08-14 Thread Jared Updike

Google Scholar is often quite handy for this sort of situation.

 http://scholar.google.com/scholar?q=typing-haskell-in-haskell+jones

 Jared.

On 8/14/06, Tim Walkenhorst [EMAIL PROTECTED] wrote:



 It can be found here: http://citeseer.ist.psu.edu/424440.html

Thanks! Actually I've seen this page before, but was too retarded to
figure that you can access the actual document there. I thought it was
just an abstract... (*embarrassed*)

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


Re: [Haskell-cafe] AJAX applications in Haskell

2006-08-10 Thread Jared Updike

http://happs.org/HAppS/README.html
http://pass.net/

 Jared.

On 8/9/06, Adam Peacock [EMAIL PROTECTED] wrote:

On 8/10/06, Jared Updike [EMAIL PROTECTED] wrote:
[..]
   http://www.ugcs.caltech.edu/~lordkaos/calc.cgi

 (source available here http://www.ugcs.caltech.edu/~lordkaos/calc.tar.gz)

I've only recently joined this mailing list, and there seems to be a
considerable amount of talk about Haskell and web applications.
Although I can't seem find any commercial sites using Haskell. I'm not
after examples like the WASH gallery, I'm after non-trivial, real or
commercial applications using Haskell and the web.

Does anyone know of any?

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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Memoizing longest-common-subsequence

2006-08-10 Thread Jared Updike

and also ended up with an STArray based implementation. I can send the
code if you're interested. I have no idea how well it performs compared
to Ian's, or the one in darcs (which uses PackedStrings).


Ian's LCS code looks like it works fine in terms of space usage, but
for large input (lengrh as == 4, length bs == 5) it seems to
be way too slow in terms of time complexity (GNU sdiff executes on
this same data in a few seconds, the Hunt-Szymanski LCS algorithm
didn't terminate, even after like 10 minutes).

If it's not too much trouble, could you send Myers STArray based code?

Thanks,
 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] AJAX applications in Haskell

2006-08-09 Thread Jared Updike

This would require to:

- Retarget one of the existing Haskell compilers to generate JavaScript
(other possible targets would be Flash or higher level UI languages such as
OpenLaszlo that in turn compiles down to either Flash or JavaScript/HTML)


As I've noticed from experience, you can just write JavaScript itself!
(You will end up doing this a lot anyway because any library is bound
to be missing some feature you need, say, input textbox history w/
up/down keys, or, say, autoscroll to bottom of iframe when content
added, etc. as here):

 http://www.ugcs.caltech.edu/~lordkaos/calc.cgi

(source available here http://www.ugcs.caltech.edu/~lordkaos/calc.tar.gz)


Is anyone working on anything similar or that might be interested in such a
project?


I'm definitely interested in this. I would love to be able to deploy a
Haskell application in the web browser w/out having to drain server
computing resources. Imagine reading a Haskell tutorial and providing
interactive applications that run in the reader's browser, etc.

Also, I really would love to see something in Haskell that can compete
with the Web Services / Web Forms stuff from Visual Studio 2005/C# in
terms of simplicity and power and feature-completeness: just write
your app and it generates all the HTML/CSS/JavaScript on the client
and the XML request stuff on the serve. Perhaps in Haskell we could
have something fugdets-like but deployable in any (relatively recent)
browser w/ no downloads.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can Your Programming Language Do This?

2006-08-02 Thread Jared Updike

So basically he rediscovered Why FP Matters
(http://www.math.chalmers.se/~rjmh/Papers/whyfp.html) ~15-20 years
after the fact, but neglected to point out the interesting fact that
one can write map in terms of reduce (i.e. foldr) (obviously he didn't
read the paper) and ignored the benefits of laziness. Also, if your
programming language has this ability and it's so great, why is this
not idiomatic? (i.e. people using for loops all over the place in
JavaScript).

(Sorry, couldn't find a place to comment on Joel's blog).
 Jared.

On 8/2/06, Stephane Bortzmeyer [EMAIL PROTECTED] wrote:

From the excellent programming blog Joel on software, a very good
text if you need to convince Java or C programmers that functional
programming is a A Good Thing.

Probably all the readers of this list will find it brings nothing new
(that's perfectly right) but it is oriented towards ordinary
programmers :-)

http://www.joelonsoftware.com/items/2006/08/01.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can Your Programming Language Do This?

2006-08-02 Thread Jared Updike

I don't think this commentary is really fair.  It's also insular and bad for
the reputation of the Haskell community.  There are enough barriers to
exploring FP and Haskell already.  The purpose of the article was to
encourage people to start taking baby steps toward FP, not to demonstrate a
deep mastery of the subject.


I feel (maybe others agree) delighted that someone so widely read
begins to extoll the virtues of functional programming. I also feel
(maybe others also agree) disappointed that this, and other such
articles, fail to take the subject far enough, really showing what
better programming languages can do. I supposed I should be happy; the
long road to FP has to start somewhere, hopefully others will start
down that road sooner rather than later.

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


Re: [Haskell-cafe] Memoizing longest-common-subsequence

2006-08-01 Thread Jared Updike

On 8/1/06, Mark T.B. Carroll [EMAIL PROTECTED] wrote:

I wanted a longest common subsequence function and a bit of Googling
failed to turn up a functional one, except for in a scary bit of darcs.


I saw a thread from back in the day about this when I was looking for
a good implementation of sdiff (or diff) in Haskell (thank Googleness
for Google):
 http://www.haskell.org/pipermail/haskell/2002-November/010731.html

all message in thread:
 http://www.haskell.org/pipermail/haskell/2002-November/thread.html#10726

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


Re: [Haskell-cafe] Future Edison directions

2006-08-01 Thread Jared Updike

This page:

 http://jaortega.wordpress.com/2006/03/17/programmers-go-bananas/

lists some references at the bottom. Perhaps they would be useful.

 Jared.

On 8/1/06, Brian Hulley [EMAIL PROTECTED] wrote:

Robert Dockins wrote:
[snip other points]
 7) Finally, I somehow feel like there should be a nice categorical
 formulation of these datastructure abstractions which would help to
 drive a refactoring of the API typeclasses in a principled way,
 rather than on an ad-hoc I-sort-of-think-these-go-together sort of
 way.  Unfortunately, my category-fu is quite weak, so all I have is
 this vague intuition that I can't substantiate.  I'm sort of familiar
 with initial algebras, but I think they may be too concrete.  I'm
 looking for some way to classify algebras that have, eg, the property
 of having folds, or of being set-like, etc.  If anybody can point me
 in the right direction wrt this, that would be great.

I'd love to find out more about these categorical abstractions also, since
Monads and Monoids (the only ones I know about) are an incredible source of
power and expressiveness in Haskell programming, so I've got the feeling
that I'm wasting tremendous amounts of time reinventing the wheel when other
abstractions that may be equally useful are just waiting to be used...

Can anyone recommend a good book or web tutorial about category theory
that's not too difficult? I'm thinking about something which would have lots
of diagrams and discussion about the relevance of the concepts to practical
computing problems but not something loaded with complicated proofs or LaTeX
symbols :-)

Thanks, Brian.

--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com

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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble compiling wxhaskell

2006-07-31 Thread Jared Updike

Hmmm I found

 http://www.haskell.org/haskellwiki/WxHaskell/Installation_tips

so there are two such pages, the other being:

 http://www.haskell.org/haskellwiki/WxHaskell/Install

so perhaps these pages can be merged? and a redirect placed from one
to the other?

Cheers,

 Jared.

On 7/31/06, Jason Dagit [EMAIL PROTECTED] wrote:

I've done this recently.  I put my notes on the wiki:
http://www.haskell.org/haskellwiki/WxHaskell/Install#Windows

Do you have a particular error message?

Jason

On 7/31/06, David F. Place [EMAIL PROTECTED] wrote:
 Hi:

 I'm having trouble compiling wxhaskell 0.9.4 under both ghc 6.4.2 and
 ghc 6.5.   Does anyone know where I should direct my queries?

 Thanks.

 
 David F. Place
 mailto:[EMAIL PROTECTED]

 ___
 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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie Q: Deriving MyOrd from Eq problem

2006-07-25 Thread Jared Updike

I am trying to derive MyOrd class from Eq (Prelude):

class Eq a = MyOrd a where
(%=), (%), (%=) :: a - a - Bool
x %= y = (x  y || x == y)
x % y =  y  x
x %= y = (y  x || x == y)

Q: What's wrong?  Why 'Ord' gets into play here?


You are using  which is a function on types that instance the class
Ord, so the compiler is telling you to add (Ord a) to the same place
you have (Eq a) or don't use  or  or any function in the class Ord.
You can the prelude and thus the Ord class and make your own  and 
functions but you can't make them refer to the real  and 
functions without Ord because that is where they live.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie Q: Deriving MyOrd from Eq problem

2006-07-25 Thread Jared Updike

Sorry, left out an important verb, *hide*:


You can the prelude and thus the Ord class and make your own  and 


You can *hide* the prelude and thus the Ord class and make your own  and 

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why Haskell?

2006-07-23 Thread Jared Updike

GSL Haskell bindings:

http://dis.um.es/~alberto/GSLHaskell/
http://dis.um.es/~alberto/GSLHaskell/doc/

Specifically for Linary Algebra:
http://dis.um.es/~alberto/GSLHaskell/doc/GSL-Base.html


 You make a good point and the decision was by no means cut and dry.  However
 I made a point of developing some test code using some the newer array data
 types and looked at maintaining the array in Haskell and then directly
 calling Blas etc.  I even had a nice polymorphic matrix class going.
 However I found the array interface just a bit too 'clunky' to use a
 technical term.  The withArray interface is not very appealing.  The layers
 of lambda notation was giving me a headache.


I think part of the problem here is not necessarily C or Haskell's
fault, but rather that what you were trying to do was write a library
(or needed the right library). Library writing is hard enough on its
own, much less when one is relatively new to Haskell! Hopefully you
will find the right tool for the job and things will go well!

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] process simulation in functional style

2006-07-17 Thread Jared Updike

Also, I found that the textbook The Haskell School of Expression by
Paul Hudak is a good introduction (particularly, if I remember
correctly, the second half of the book) to functional reactive
programming in Haskell.

 Jared.

On 7/16/06, Nicolas Frisby [EMAIL PROTECTED] wrote:

You might discover helpful techniques by searching for these
terms/projects/papers:

- functional reactive programming (e.g. Yampa project)
- resumption monad (e.g. Cheap but Functional Threads)
- concurrent Haskell extensions
- or even comonads (e.g. Essence of Dataflow)

The activation energy to be invested in each technique is likely
considerable, but that's the fun part, right?

Hope that helps,
Nick

On 7/16/06, Alexander Vodomerov [EMAIL PROTECTED] wrote:
   Hello!

 I'm writing a program that simulates multiple processes. The processes may
 send/receive messages, do some work, or sleep for some amount of time.

 I have seen that many such things can be expressed in Haskell in very
 elegant manner using it functional or lazy properties. For example,
 client/server interaction may be expressed via inifinite lists as shown
 in Gentle Introduction to Haskell. Another way of process simulation
 is describied in http://citeseer.ist.psu.edu/harcourt95extensible.html,
 where simple and concise CCS interperter is constructed.

 I've tried to apply the idea of infinite lists or CCS-style processes,
 but fail. The main reason is that:

 1) messages are asynchronous (it may be received and handled while
 process are sleeping, without waking them)
 2) in some cases received message may wake up process
 3) all activity in system is ordered by time
 4) there are 2 process and during simulations new processes may be
 created

 I've no idea how to implement 1, 2 in CCS interpeter.
 The approach of infinite lists seems to have problems with 3, 4.

 Have somebody any ideas how this can be solved in simple and concise way?

 With best regards,
 Alexander.

 PS. Currently I have some code (see below), but it is VERY UGLY. The
 main drawback is that is very imperative. It employs notion of Global
 state.  It doesn't use features of Haskell and can be rewritten in ML
 or C++ without changes. Another flaws is that it is very unextensible,
 and all processes must have the same state.

 -- example code

 latency = 0.001

 type Message = String
 type MsgM = WriterT [(Int, Message)] IO  -- process may send messages

 -- process states

 next id = (id + 1) `mod` 3

 type State = (Int, Int, Double) -- proc. number, counter, interval

 do_step :: State - MsgM (Double, State) --- do something and then sleep
 do_step (id, cnt, delay) = do
   tell [(next id, ping  ++ show id ++  cnt  ++ show cnt)]
   return (delay, (id, cnt + 1, delay))

 handle_message :: Message - State - MsgM State
 handle_message msg (id, cnt, delay) = do
 -- liftIO $ putStrLn $ show id ++  received  msg  ++ msg
 if msg !! 0 == 'p' then tell [(next id, reply  ++ show id ++  to  ++ 
msg)] else return ()
 return (id, cnt, delay)

 -- global event queue

 data Event = MsgRecv Message | Work deriving Show
 type EventQueue = [(Double, Int, Event)]

 compare_event (t1, n1, e1) (t2, n2, e2) = compare t1 t2

 type EventM = WriterT EventQueue IO

 queue_event :: Int - Event - Double - EventM ()
 queue_event dest ev time = tell [(time, dest, ev)]

 type FullState = Map.Map Int State

 handle_event :: Int - Double - Event - FullState - EventM FullState
 handle_event procnum time ev fullstate  = do
 let localstate = (fullstate Map.! procnum)
 case ev of
   MsgRecv msg - do
   (nstate, messages) - lift $ runWriterT (handle_message msg 
localstate)
   sequence_ $ map (\(dst, msg) - queue_event dst (MsgRecv msg) 
(time + latency)) messages
   return $ Map.insert procnum nstate fullstate
   Work - do
   ((pause, nstate), messages) - lift $ runWriterT (do_step 
localstate)
   sequence_ $ map (\(dst, msg) - queue_event dst (MsgRecv msg) 
(time + latency)) messages
   queue_event procnum Work (time + pause)
   return $ Map.insert procnum nstate fullstate

 run_queue :: FullState - EventQueue - IO ()
 run_queue st eventqueue =
 case eventqueue of
   [] - return ()
   (time, dest, ev) : rest - do
   putStrLn $ processing event  ++ (showFFloat (Just 3) time)  ++  
at procnum  ++ show dest ++++ show ev
   (nst, nev) - runWriterT (handle_event dest time ev st)
   let nqueue = foldl (\res - \e - insertBy 
compare_event e res) rest nev
   run_queue nst nqueue

 init_state = Map.fromList [(0, (0, 0, 0.3)), (1, (1, 0, 0.4)), (2, (2, 0, 
0.5))]

 main = run_queue init_state [(0, 0, Work), (0, 1, Work)]

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

___

Re: [Haskell-cafe] Type of a function?

2006-07-14 Thread Jared Updike

Did you try putting this in a file, say,   t.hsand running
  ghci  t.hs

then typing

  :type func

at the GHCi prompt? It should tell you the function type.

 Jared.

On 7/14/06, Jenny678 [EMAIL PROTECTED] wrote:


Hallo

Can somebody tell me the type of  the following function?

func :: ?
func f x = (z,y)
  where (z,y) = f x

Thanks
--
View this message in context: 
http://www.nabble.com/Type-of-a-function--tf1945843.html#a5335607
Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type of a function?

2006-07-14 Thread Jared Updike

(leave off the line with

func :: ???

and the compiler will figure it out for you, if possible---it works in
this case)

 Jared.

On 7/14/06, Jared Updike [EMAIL PROTECTED] wrote:

Did you try putting this in a file, say,   t.hsand running
   ghci  t.hs

then typing

   :type func

at the GHCi prompt? It should tell you the function type.

  Jared.

On 7/14/06, Jenny678 [EMAIL PROTECTED] wrote:

 Hallo

 Can somebody tell me the type of  the following function?

 func :: ?
 func f x = (z,y)
   where (z,y) = f x

 Thanks
 --
 View this message in context: 
http://www.nabble.com/Type-of-a-function--tf1945843.html#a5335607
 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

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



--
http://www.updike.org/~jared/
reverse )-:


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


Re: [Haskell-cafe] Re: Why is there no splitBy in the list module?

2006-07-12 Thread Jared Updike

 fields = csv `separateWith` ,
 csv = fields `joinWith` , -- equivalent to concatIntersperse

Hence I would much rather have the split condition be the first
parameter -- the infix notation looks good, but it will need a
flip to get the parameters in the right order.


This also goes along with join in python, i.e.

\n.join(xs)
 ==
\n `join` xs
  in Haskell (wherejoin sep = concat . intersperse sep )

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


Re: [Haskell-cafe] Re: Why is there no splitBy in the list module?

2006-07-11 Thread Jared Updike

split is... unconcatIntersperse.


How about separate?  (split or splitBy is better but it is used
all over the place in many libs)

And for strings I definitely would use split :: [a] - [a] - [[a]]  a
lot, just like Python's split function. And words works great for
breaking on multiple spaces, so I would avoid trying to fill that
need...

 Jared.


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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] closures with side effects

2006-06-26 Thread Jared Updike

 I have been trying to understand closures in haskell and how they relate
 to side effects. I have been looking around but all I find are trivial
 examples with no side effects. Please let me know if you know of any
 examples.


Bulat what you mean by 'closure'?

Perhaps you are refering to something like the Accumlator generator in Lisp:

(defun mkacc (n)
  (lambda (i) (incf n i)))

or Scheme:

(define (mkacc n)
 (lambda (i)
   (set! n (+ n i))
 n))

(the term closure explained in footnote 6 in SICP here:
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#footnote_Temp_154:
A closure is an implementation technique for representing procedures
with free variables.)
?

In Haskell you can do this, but all side effects are made explicit and
can only be used within code marked with IO (in the IO monad):

import Data.IORef

mkAcc :: (Num a) = a - IO (a - IO a)
mkAcc n = do
 r - newIORef n
 return (\i - do
   modifyIORef r (+i)
   readIORef r)

(These examples are from http://www.paulgraham.com/accgen.html, by the way.)

On 6/26/06, dkarapet [EMAIL PROTECTED] wrote:

I have been trying to understand closures in haskell and how they relate
to side effects. I have been looking around but all I find are trivial
examples with no side effects. Please let me know if you know of any
examples.



in Haskell, expression may have a side
effect only if it has IO a return type. it is then whole point of
pure lazy language - evaluation of pure (not IO) expression can be
deferred until it's value really need and language guarantee that this
don't change anything (including lack of any side effects)
 Bulatmailto:[EMAIL PROTECTED]


The reason you need IO in the type that the compiler/type system
forces you to isolate side effects from pure code so all your pure
code stays pure. There is a good explanation here, under Pure
Functions:

http://en.wikipedia.org/wiki/Functional_Programming#Pure_functions

The reason purity is **enforced** is similar to the reason goto is
considered harmful: the belief is that the programmer receives great
benefits this tradeoff. In exchange for giving up side effects in
arbitrary places, the programmer gains freedom in knowing that all
pure functions are free from side-effects related bugs and her code is
easier to reason about mathematically.

My understanding is that Haskell's execution model is a lot more
involved than, say, Scheme, because pure code is more flexibly
refactored by the compiler and because the runtime evaluation strategy
for lazy evaluation is less obviously implemented. In this sense, if I
undertsand correctly, Haskell doesn't really use closures as an
implementation strategy (as defined above), if that is what your
question is refering to, and I'm not surprised that you don't find
interesting examples in Haskell, especially any involving side
effects.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Eager Parser Combinators [was: Functional programming for processing of largeraster images]

2006-06-22 Thread Jared Updike

On 6/22/06, Greg Buchholz [EMAIL PROTECTED] wrote:

Ralf Hinze wrote:
 Also, in a non-strict language recursive definitions are not
 limited to function types. Users of parser combinators heavily rely
 on this feature. Just try to define/use parsing combinators
 ins a strict language.

Anyone care to comment on what goes wrong with parser combinators in
an eager language?  Is it mainly a space usage problem (where the lazy
version might essentially perform a depth-first-search, while the eager
version is breadth-first)?  Or is there something else I'm missing?


Slide 22 (Combinator Libraries) of
 http://research.microsoft.com/~simonpj/papers/haskell-retrospective/
shows that in an eager language, you have to make the argument
explicit, which destroys the Parser abstraction. Indeed I rolled my
own sort of monads and made my own parser combinators in C# and they
were a lot like your Perl combinators: very imperative and verbose
(~10x more code than Haskell for the same parser), instead of clean
and declarative like BNF or Haskell parser combinators.

 Jared.


As a reference, back when I was trying to understand monads, I
ported the parser combinators from the Hutton and Meijer paper to
perl...

http://sleepingsquirrel.org/monads/parser/monad_parser.txt


Thanks,

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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Functional progr., images, laziness and alltherest

2006-06-22 Thread Jared Updike

 Therefore the list of non-negative integers is longer than the list of
 positive integers. I agree they have the same cardinality but this doesn't
 mean they have the same length.

Are you saying that some of the (0,1,2,3,4,5,...), (1,2,3,4,5,...) and
(1-1,2-1,3-1,4-1,5-1,...) lists have different lengths?


Q: Which list is longer, [0..] or [1..] ?
A: MU! (see http://en.wikipedia.org/wiki/Mu_%28negative%29 ) I am
un-asking the question. They don't have length. Length only makes
sense for lists with [] in them and infinite lists do not use [].

 Jared.

P.S. If you still don't believe me, this code should put this mystery to rest:

length2 x y = f 0 0 x y where
  f a b [] []  = (a, b)
  f a b [] (y:ys)  = f a (b+1) [] ys
  f a b (x:xs) []  = f (a+1) b xs []
  f a b (x:xs) (y:ys)  = f (a+1) (b+1) xs ys

length2 [0..] [1..]

Feel free to get back to us with the results!
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Polymorphic type

2006-06-22 Thread Jared Updike

On 6/22/06, Sara Kenedy [EMAIL PROTECTED] wrote:

Hello all,

Now I am trying with the function of polymorphic type: This function
returns the Nth element of list with type a. I try it as below.

getNthElem :: Int - [a] - Maybe a
getNthElemt _ []= Nothing
getNthElem 0 _  = Nothing
getNthElem n s
| n  length s  = Nothing
| otherwise = Just ((drop (n-1) (take n s))!!0)

getNthElem 2 [a,b,c]
Just b

However, I do not satisfy with this function because I want to return
the Nth element of type a, not (Maybe a). For example, I want this
function:
getNthElem :: Int - [a] -  a

But, I do not know how to define the empty element of type a.


Not all types (especially numbers) have an empty element (what does
that even mean?). Suppose you have a list
 [0, 1, -2, -1, 2]
and you try getNthElemt 4 and your program assumes that the empty
element for integers is 0. How can you tell that 0 from the 0 at the
beginning of the list [0, 1, 2]? Think really hard about what you are
asking and you will see why Maybe a takes the type a and extends it,
in a way, with an empty element, Nothing. To convert it from Maybe a
to a, try, e.g.
 fromJust (Just 4)    4
(it will give exceptions when Nothing shows up).


getNthElemt _ []= 
getNthElem 0 _  =  


One possiblity is to make a class called empty with a single member:


class Empty a where
  empty :: a
instance Empty [a] where   -- this also makes= empty   for String
  empty = []
instance Empty Maybe a where   -- is this desirable?
  empty = Nothing
instance Integer where -- or this?
  empty = 0
...


and then add the constraint to your function:


getNthElem :: Empty a = Int - [a] - a
getNthElem :: Int - [a] - Maybe a
getNthElemt _ []= empty
getNthElem 0 _  = empty
getNthElem n s
| n  length s  = empty
| otherwise = ((drop (n-1) (take n s))!!0)



but you need overlapping instances to instantiate [a].  Or you could
use MonadPlus and mzero instead of Empty and empty, but that would
only work for List, Maybe and other monads and not for Integer, etc.

Note that in a dynamic language the same thing happens. In python
  4 + None
raises an exception. I don't think it's possible to get away from this
whole failure concept (except silently ignore it---in perl   4+null
yields 4 but is that always the right behavior in all situations? It
makes bugs really hard to find.)

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple matrix

2006-06-21 Thread Jared Updike

  fromInteger x = [[fromInteger x]]


Wouldn't you want the expression

[[1,0],[0,2]] + 10

to yield

[[11,10],[10,12]]

instead of [[11]] ? I guess you would need some complicated machinery
so this is one thing you have to ignore to keep your otherwise nifty
instance nice and simple.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:


  abs x = map (map abs) x
  (+) [ ]  y  = y
  (+)  x  [ ] = x
  (+)  x   y  = zipWith (zipWith (+)) x y
  (*)  x   y  = map (matrixXvector x) y
where
--matrixXvector :: Num a = [[a]] - [a] - [[a]]
  matrixXvector m v = foldl vectorsum [] $ zipWith vectorXnumber m v
--vectorXnumber :: Num a = [a] - a - [a]
  vectorXnumber v n = map (n*) v
--vectorsum :: [a] - [a] - [a]
  vectorsum [] y = y
  vectorsum x [] = x
  vectorsum x  y = zipWith (+) x y



___
Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. 
Registre seu aparelho agora!
http://br.mobile.yahoo.com/mailalertas/


___
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] Simple matrix

2006-06-21 Thread Jared Updike

I dont see how to fix this.


There was a thread about statically knowing lots about the shape of
matrices using the type system.

http://www.haskell.org/pipermail/haskell/2006-April/017845.html

I believe they incorporated this (variable size identity matrix, for
example) in their approach. (They don't preserve your property of
being able to do things with simple list syntax, like [[1,2],[3,4]] *
[[5,6],[7,8]] , instead you have to use Template Haskell and some
small contructor functions)


Could be better to forget about fromInteger...


Except then you wouldn't have a full instance for Num. How about
constructing an infite list of infinite lists of that number:

  fromInteger x = map repeat (repeat (fromInteger x))

when it gets zipped with smaller matrices, will it terminate?

It works with addition but multiplying caused problems:

 [[1,2],[3,4]] + 10 = [[11,12],[13,14]]

 [[1,2],[3,4]] * 10 = [[40,60],[40,60],[40,60],[40,60],[40,60], .

Hmm...
 Jared.


Atila

Jared Updike wrote:
   fromInteger x = [[fromInteger x]]

 Wouldn't you want the expression

 [[1,0],[0,2]] + 10

 to yield

 [[11,10],[10,12]]

 instead of [[11]] ? I guess you would need some complicated machinery
 so this is one thing you have to ignore to keep your otherwise nifty
 instance nice and simple.

  Jared.



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple matrix

2006-06-21 Thread Jared Updike

Instead of


   fromInteger x = map repeat (repeat (fromInteger x))


I meant


   fromInteger x = repeat (repeat (fromInteger x))


but it still doesn't work for multiplication.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie question on iterating over IO list

2006-06-20 Thread Jared Updike

o To output anything, I need to do 'do'.


If you only have one action, you can omit do, e.g.

 main = do { putStrLn Hello, World! }

is identical (after de-sguaring) to

 main = putStrLn Hello, World!

Essentially, you are correct; to output anything (i.e. to perform I/O
by side effect) your actions will be inside the I/O monad, typically
inside of a 'do' block.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ACross

2006-06-19 Thread Jared Updike

Not to be the bad guy, but perhaps it's a good idea to remind
ourselves of our homework policy.


This?

 http://www.haskell.org/hawiki/HomeworkHelp


Can I use putString ???


If you mean putStrLn and putStr, then yes. I would first make a
function that constructs the string or list of strings (maybe using
++) you need to display, and then call putStr and/or putStrLn the
appropriate number of times.

Other questions to answer:

* Can we safely ignore the case of even numbers?, i.e. cross 2, cross
4, cross 6, etc.
* Looking at the output lines, how can we break down or classify them,
in terms of numbers of plus signs and areas of spaces? Which lines are
similar? etc.

Good luck,
 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learning C after Haskell

2006-06-12 Thread Jared Updike

Thanks, Minh. So are things like recursion and memory sharing typically out
the window?


Recursion works in C, but every function call pushes stack, so
recursive depth is limited by RAM (compare to tail call optimization
in many functional programming languages where the stack frame is
reused if code is written iteratively with an accumulator). Most of
the time for performance (and to be idiomatic) in C you will just
write for and while loops and modify state in place. Welcom to C.

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Jared Updike

Funny. I have a module called Useful.hs with some of these same sorts
of functions. (coming from Python where I used .split(',') and
.replace('\r', '') and such a lot):

--
module Useful where

import List ( intersperse, tails )
import Numeric ( readHex )

hex2num :: (Num a) = String - a
hex2num s = let (result, _):_ = readHex s in result

toEnv s = map tuple (split ';' s)

tuple :: String - (String, String)
tuple line = case split '=' line of
  a:b:_ - (a,b)
  a:_   - (a,)
  _ - (,) -- not good, probably won't happen for my typical usage...

split   :: Char - String - [String]
split _   =  []
split c s   =  let (l, s') = break (== c) s
in  l : case s' of
  []  - []
  (_:s'') - split c s''

beginsWith []   [] = True
beginsWith _[] = True
beginsWith []   _  = False
beginsWith (a:aa)   (b:bb)
   | a == b   = aa `beginsWith` bb
   | otherwise= False

dropping [] [] = []
dropping [] _  = []
dropping x  [] = x
dropping s@(a:aa) (b:bb) | a == b= dropping aa bb
| otherwise = s

-- replace all occurrences of 'this' with 'that' in the string 'str'
-- like Python replace
replace __[]  = []
replace this that str
   | str `beginsWith` this = let after = (str `dropping` this)
  in  that ++ replace this that after
   | otherwise =
   let x:xs = str
 in x : replace this that xs

eat s = replace s 

-- sometimes newlines get out of hand on the end of form POST submissions,
-- so trim all the end newlines and add a single newline
fixEndingNewlines = reverse . ('\n':) . dropWhile (=='\n') . reverse .
filter (/= '\r')

endsWith a b = beginsWith (reverse a) (reverse b)

a `contains` b = any (`beginsWith` b) $ tails a
--

 Jared.

On 6/12/06, Neil Mitchell [EMAIL PROTECTED] wrote:

Hi,

I tend to use the module TextUtil (or Util.Text) from Yhc for these
kind of string manipulations:

http://www-users.cs.york.ac.uk/~malcolm/cgi-bin/darcsweb.cgi?r=yhc;a=headblob;f=/src/compiler98/Util/Text.hs

separate = splitList ,

I am currently thinking about making this module into a standalone
library with some other useful functions, if people have any opinions
on this then please let me know.

Thanks

Neil


On 6/12/06, Sara Kenedy [EMAIL PROTECTED] wrote:
 Hi all,

 I want to write a function to separate a string into a list of strings
 separated by commas.

 Example:
 separate :: String - [String]

 separate Haskell, Haskell, and Haskell = [Haskell, Haskell, and 
Haskell]

 If anyone has some ideas, please share with me. Thanks.

 S.
 ___
 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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Features of Haskell

2006-06-04 Thread Jared Updike

stumped as to how I'm going to do this. I've got about 15-20 minutes,
so I can only discuss the major features.


I was always impressed with Autrijus Tang's presentation here:
 http://www.pugscode.org/euroscon/haskell.xul (view with Firefox
or other Gecko-based browser)

I think he managed to explain very effectively what made Haskell
special, including major features/differences/paradigms, as well as
syntax, all at once. I did read the slides as one familiar with
Haskell so I can't say how it would come across to one unfamiliar with
Haskell (which was his target audience), but maybe his presentation
will help give you ideas.

Best of luck!
 Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Features of Haskell

2006-06-04 Thread Jared Updike

On Sun, Jun 04, 2006 at 05:17:02PM -0700, Jared Updike wrote:
 stumped as to how I'm going to do this. I've got about 15-20 minutes,
 so I can only discuss the major features.

 I was always impressed with Autrijus Tang's presentation here:
   Audrey
 I think he managed to explain very effectively what made Haskell
  ^^ she


Yep.. My bad.

Cheers,
 Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC wish

2006-05-23 Thread Jared Updike

Sorry, meant to reply all:
---

This tool (DrIFT) can derive these instances for you, if you care to
make rules for it, for Pretty:

  http://repetae.net/john/computer/haskell/DrIFT/

 Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] develop new Haskell shell?

2006-05-11 Thread Jared Updike

It would also be wise to look at occam and erlang and see if they have
any useful ideas. And, of course, Windows PowerShell.


And scsh (Scheme shell, pretty full featured these days):  http://www.scsh.net/

 Jared.



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




--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie Instance Of Floating Int Error

2006-04-28 Thread Jared Updike
It looks like somewhere else in your program (or a type signature
somewhere) is trying to force the result of sqrt to be an Int which
won't work since square roots are irrational (represented by the
computer as a Float or Double).

You might try (1) making sure the place where distBetween is used
isn't trying to use only Ints or Integers and (2) taking off explicit
type signatures and seeing if that works (the compiler can usually get
things working for you as long as you don't give it misinformation in
type signatures). Also, a more useful type of Point if you are taking
distances would be

type Point = (Float,Float)

instead (or you can leave that out because the function type for
distBetween will be inferred to be the right thing, i.e.
(Float,Float) is already a valid type without needing to be named).

Hope that helps,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:

On 4/27/06, Aditya Siram [EMAIL PROTECTED] wrote:
 Hi all,
 I just started working with Haskell and am having some difficulties with its
 type system.
 Here is function that is supposed to calculate the distance between two
 coordinates:
 distBetween (x1,y1) (x2,y2) = sqrt((x2-x1)^2  + (y2-y1)^2)

 I am trying to explictly give it a type signature. Here is what I have tried
 and the errors generated by Hugs:

 type Point = (Int,Int)
 distBetween :: Point - Point - Float
 ERROR - Type error in explicitly typed binding
 *** Term   : distBetween
 *** Type   : Point - Point - Int
 *** Does not match : Point - Point - Float

 distBetween :: Point - Point - Int
 Instance of Floating Int required for definition of distBetween

 Any help is appreciated...
 Deech


 ___
 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] RuntimeLoader

2006-04-14 Thread Jared Updike
I've never used that Runtime Loader package but I have gotten
hs-plugins to work:
   http://www.cse.unsw.edu.au/~dons/hs-plugins/

Hope that helps,
  Jared.

On 4/13/06, Tim Newsham [EMAIL PROTECTED] wrote:
 Hi,
 I'm about to start playing with HWS-WP (web server + plugins).  It
 relies on RuntimeLoader:

 http://www.algorithm.com.au/wiki/hacking/haskell.ghc_runtime_loading

 I grabbed the example and built it (only one minor tweak to imports
 to get it to build) but it doesnt quite work:

 $ ./src/TextFilter ./plugins/Lower.o  README
 TextFilter: ./plugins/Lower.o: unknown symbol `__stginit_Char_'
 TextFilter: user error (resolveFunctions failed?False)

 There were also some warnings during building:

 Compiling RuntimeLoader( ../runtime_loader/RuntimeLoader.hs,
 ./RuntimeLoader
 .o )
 /tmp/ghc11951.hc: In function `s2Pj_ret':
 /tmp/ghc11951.hc:170: warning: implicit declaration of function
 `unloadObj'
 /tmp/ghc11951.hc: In function `s2JU_entry':
 [...]

 I assume this is because it is mucking with some ghc internals?
 Is anyone familiar with this package?  Is there a more up-to-date
 version or alternative?

 Tim Newsham
 http://www.lava.net/~newsham/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] web servers

2006-04-08 Thread Jared Updike
I don't know if there's anything newer, but you could check out:

http://happs.org/HAppS/README.html
http://www.informatik.uni-freiburg.de/~thiemann/WASH/

Hope that helps,
  Jared.

On 4/8/06, Tim Newsham [EMAIL PROTECTED] wrote:
 Hi Everyone,
 I'm new to the list, been on irc a bit.  I'm still learning haskell.
 Wanted to say Hi before getting in to things...

 I'm interested in real-world programs in haskell, especially ones where
 security and formal methods are important.  I'm looking at web servers
 right now.  I found a copy of Simon Marlow's HWS on haskell.org's cvs
 server.  I know there's a newer plugin version, but I cant find a working
 link to the actual code.  I've been able to get the code to compile after
 a while, but it still has some warnings of deprecated features which I
 havent been able to get rid of (if anyone's interested in helping out, let
 me know).  Anyway, I configured it an ran it and it works, although I have
 noticed two security flaws in it which need fixing.  Is it possible there
 is a newer version with these flaws fixed?

 Besides HWS, what other web servers exist?  Does anyone actually use a
 haskell based web server in practice?  Which web server is considered the
 most mature?  stable?  fastest?

 I'm trying to decided if I should sink some time into HWS or if I should
 use another server.

 Tim Newsham
 http://www.lava.net/~newsham/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Justification for Ord inheriting from Eq?

2006-04-07 Thread Jared Updike
 given an Ord instance (for a type T) a corresponding Eq instance can be
 given by:

 instance Eq T where
 a == b = compare a b == EQ

where did this second -^ == come from? (I guess if if Ordering
derives Eq :-) I think you meant

 instance (Ord T) = Eq T where
 a == b = case compare a b of
 EQ - True
 _ - False

Cheers,
  Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] What's up with this Haskell runtime error message:

2006-04-06 Thread Jared Updike
 Thanks so much for your help. I should have made clear that I was aware that
 the definitions were mutually dependent.  What I was hoping was that Haskell
 could solve this for me without my having to resort to effectively finessing
 any sequencing considerations.

Haskell is a functional language. The program you are trying to solve
sounds like a logic problem if I understand it correctly. There is a
functional logic programming language called Curry [1] that has
similar syntax to Haskell, but a different evaluation approach. (Note:
I don't know anything about Curry other than what I read on the front
page of their website, and the fact that someone wrote a Sudoku solver
by writing the constraints and having the compiler generate a program
that solves the puzzle.)

  Perhaps I am really asking it to do too much.

What you want is a program that looks for a set of values that satisfy
a certain set of mathematical relations (you mentioned scientific
computing). As I understand it, this is where logic programming
shines. (If you can turn this into a system of equations, Mathematica
might be able to solve it, btw.)

  This I thought might be reasonable since one is supposed to be achieving a
 sequence-less style of programming.

I never really heard Haskell described this way. I've heard Haskell
described as a declarative programming language, where you shouldn't
worry about the order of execution of your functions, but I never
thought it meant anything about complete sequence-less-ness; it seems
very rooted in deterministic evaluation.

 But this would seem to be a counter
 example where  I will be essentially forced to implement a sequential
 processing semantic in a language environment which ostensibly would deny me
 such (for my own good I understand).

In fact, Haskell is big on sequencing. One of the key features of
Haskell is the monad [2]; you might call it sequencing done right. I'm
not sure how monads would help you (if you can express your code
imperatively you are good to go, but it sounds like you want to keep
things declarative).

  Thoughts?

Someone who knows about logic programming might point you to good
resources about this perspective, if it applies (other than Curry
[1]), which looks pretty fun.

Hope that helps,
  Jared.

[1] http://www.informatik.uni-kiel.de/~curry/
[2] http://www.nomaware.com/monads/html/

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code Review: Sudoku solver

2006-04-04 Thread Jared Updike
On 4/3/06, Donald Bruce Stewart [EMAIL PROTECTED] wrote:
 It would also be nice to see some example sudoku solvers posted
 on an `Idioms' page on haskell.org:
http://www.haskell.org/haskellwiki/Category:Idioms

 someone could just  create a new page 'Sudoku' and add the phrase
 [Category:Idioms]] to the text, and it will be indexed.

Done.  Lives at  http://www.haskell.org/haskellwiki/Sudoku

 Seeing 4 or 5 solutions would be a useful tutorial, I'd imagine.
  it seems that sudoku solver may be a good candidate for nofib suite /
  language comparison shootout

Anyone with killer solvers (Chris?) can add them to the wiki. Maybe
the fastest can be used in a new Shootout benchmark.

  Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code Review: Sudoku solver

2006-04-03 Thread Jared Updike
Chris wrote:
 You need more than 5 examples.  The truly evil puzzles are rarer than that.  
 Go
 get the set of minimal puzzles and see how far your logic takes you.

Chris elucidated some of my questions before I finished writing my email...

Claus wrote:
 (*) actually, that was a bit disappointing!-(

How much harder is the problem of generating (hard/medium/easy)
(solvable) Sudoku puzzles? Are all puzzles solvable (that don't break
the rules at any point)? I imagine a simple way is to start with a
correctly saturated grid of numbers and then start randomly shooting
holes in it and testing if it is still solvable (either unambiguously
or ambiguously) with your Sudoku solver? A rough mesaure of the
difficulty of the unsolved puzzle could be how long the solver took to
solve it (number of steps) (and the number of possible solutions)? Are
puzzles with multiple solutions usually considered harder or easier?
Are these considered proper puzzles?

Is this a more interesting problem to try to solve (generating) rather
than solving puzzles? I haven't investigated it much but I thought
about it when I was writing YASS (Yet Another Sudoku Solver) of my
own. What makes a Sudoku puzzle fiendish? Just the amount of missing
information, the amount of lookahed required?

  Jared.

P.S. Another interesting problem could be trying other number
arrangements besides 9x9, e.g. hexadecimal puzzles... I wrote my
solver to handle these but I never saw other than 9x9 puzzles to try
it on (hence the idea of generating puzzles)... Is that because most
people want puzzles to solve by hand instead of computer?

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] PPM image manipulation

2006-04-02 Thread Jared Updike
 having some trouble trying to be able to manipulate PPM images.  I want to be
 able to desaturate and also double the scale of them. im a first time user
 of haskell so am not very familiar with it. any info would be great! thanks!

Nothing wrong with asking for help, but before you do, please read:
  http://www.haskell.org/hawiki/HomeworkHelp
After you read that and follow its advice, we would love to help with
*specific* questions (code help or algorithms, for example).

I have a few questions for you: Do you understand how to do these
image manipulations, for example, in another programming language? Are
you confused about how to do this in Haskell? Or both?

If these manipulations are difficult, try something simple, like
inverting the image or keeping only the red channel (zero out blue and
green), anything to make sure you have a handle on the code.

Thanks,
  Jared.

P.S. After googling around for haskell image manipulation (in the
hopes of finding some Haskell image lib like VIPS [1] or the Python
Imaging Library [2]), I found the assignment spoken of
  http://cs.anu.edu.au/Student/comp1100/assts/asst1/
just so everyone knows. BTW, does Haskell have an imaging library that
people usually turn to? (Or should I add that to my list of cool
projects that I need to get around to ...)

[1] http://www.vips.ecs.soton.ac.uk/
[2] http://www.pythonware.com/products/pil/

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-02 Thread Jared Updike
Is there a common way (standard libs, higher order) to express the
lambda part below? It's not particulary complicated but I think it is
not higher-order enough

 unionBy (\x y - fst x == fst y) listOfPairs1 listOfPairs2

Something like distribute fst (==) where

 distribute f op x y = f x `op` f y

would leave

 unionBy (distribute fst (==)) listOfPairs1 listOfPairs2

I imagine something involving Arrows and/or zip/curry/uncurry but I just
can't see it. Is this a case of trying to make something more complicated
than it is?

  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] List of instantiated types

2006-03-30 Thread Jared Updike
My understanding is that type classes in Haskell are meant to be
open, so that any code that uses your type class will work with any
new instances of that type class. This inherent open endedness causes
a problem if you are trying to enumerate all instances because at any
time someone can create a new instance of your class in their code.

There is a ticket for Haskell' talking about Closed Classes but I'm
not sure it would be adopted anytime soon (and I'm pretty sure it's
not implemented in GHC):
  http://hackage.haskell.org/trac/haskell-prime/wiki/ClosedClasses

What you're trying to do *may* be possible but it would require some
way of having the runtime query the compiler/linker for information
about all modules being linked against.
This kind of hacking may require hs-plugins, Template Haskell, or the
GHC API (i.e. some kind of metaprogramming).

What I mean is, I'm not sure how to make it so you can gather all
information about your type class in one central place; I think for
type classes the information flows in the other direction. There might
still be a totally different way to accomplish this but you'll have to
wait for a guru to answer that...

Hope that helps,
  Jared.

On 3/30/06, Mirko Rahn [EMAIL PROTECTED] wrote:

 Hello,

 please suppose the following setting: (see [1] too)

 {-# OPTIONS_GHC -fglasgow-exts #-}
 module C where

 class C a where name :: a - String ; pre :: a - a

 data Cs = forall a . (C a) = Cs a

 instance C Cs where name (Cs a) = name a ; pre (Cs a) = Cs (pre a)

 mkCs :: C a = a - Cs
 mkCs = Cs

 instance C Int where name = show ; pre = \ _ - 0
 instance C Char where name = return ; pre = \ _ - 'A'

 all_Cs = [ mkCs (undefined :: Int), mkCs (undefined :: Char) ]

 Note that despite I served undefined values only I can type

 *C map (name . pre) all_Cs
 [0,A]

 to extract some information. But, when several instances spreads over
 some modules, writing down 'all_Cs' is an error-prone task, in
 particular when using some third party modules.

 So my question is: Is it possible to construct 'all_Cs' automatically?

 I think such a list cannot be constructed at compile-time, but at link-
 and run-time a complete list of instantiated types should be available.
 But is this list accessible somehow? Is there a possibility to write

 foreach type t that is an instance of C:
 return (mkCs (undefined :: t))

 What is the general problem?

 Thanks, MR

 [1] http://www.haskell.org/pipermail/haskell-cafe/2006-March/014947.html

 --
 -- Mirko Rahn -- Tel +49-721 608 7504 --
 --- http://liinwww.ira.uka.de/~rahn/ ---
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Positive integers

2006-03-24 Thread Jared Updike
 Fortunately there are already List functions like genericLength and
 genericTake, which can handle such a number type. Shouldn't be Peano
 numbers part of the standard libraries?

Natural numbers are being discussed as a possible part of the new
Haskell' standard.
   http://hackage.haskell.org/trac/haskell-prime/ticket/79

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


Re: [Haskell-cafe] Re: Positive integers

2006-03-23 Thread Jared Updike
 An additive torsor is?

Surprisingly, there is a page on MathWorld about Torsors but it is
empty. Google turned up the following page with a good explanation.

http://math.ucr.edu/home/baez/torsors.html

 I'd maintain that the difference between two lengths is an entirely different
 quantity from the length of a list.

(Maybe this is a good example of what the term torsor captures.)

Thanks to Aaron for expanding our vocabulary.

  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code Review: Sudoku solver

2006-03-22 Thread Jared Updike
On 3/22/06, David F. Place [EMAIL PROTECTED] wrote:
 Hi All,

 I really appreciate all the help I received when I asked you to
 critique my PrefixMap module a few weeks ago.  I think I am making
 good progress in correcting the lisp in my Haskell programming.
 I'll be very grateful to anyone who can take a glance at the attached
 short program and say if any unidiomatic usages pop out

Try

 cellIndex r c = 3*(r `div` 3) + c `div` 3

It's much much shorter and should produce the same results.

 It solves
 sudoku puzzles.  (What pleasure do people get by doing these in their
 heads?!?)


They are probably asking the same question: why take hours to write a
program to do it when with my mad sudoku solving skills I can solve it
in X seconds? My roommate is like this.

Cheers,
   Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: dynamic arrays

2006-03-17 Thread Jared Updike
(Moved to haskell-cafe)

JU General question to the list:
JU (Q)  Are there any data structures in Haskell similar to C++/STL
JU vectors or C# generic Lists (i.e. strongly typed ArrayLists, e.g.
JU Listint)? These data structures grow automatically as you add
JU elements to them (but in large chunks, not one node at a time). This
JU data structure (if it exists in Haskell) would run inside a monad (ST
JU and/or IO) and it would automaticly resize when needed, but would be
JU more or less like a mutable array except you can add new elements to
JU the end of it without reallocating an entire array of n+1 elements...

i tried to implement this today :) but there is one problem:

 if i have (l,u) - array bounds of type Ix, and i - offending index of
 the same type, how can i compute new bounds of array so that it will
 grow in large chunks? there is no such computation operations for
 Ix type and that is logical - if this array is really a matrix then
 it's hard to use the same rules of extending it as for vectors

Hmmm, that is a problem, especially as you said, for enum types that
are bounded above. I guess you can't make it grow more than the min
and max. For the most part, this dynamic array would only be useful
for arrays with indices isomorphic to the natural numbers.

 such computation as (u-l)*2+l is great for integral indexes, but not
 for general case. now i plan to use this strategy for all enum types
 and just grow to minimal and maximal indexes actually used for other
 index types

Perhaps the function to build these DynamicArrays could take a Maybe
parameter telling the maximum possible range (for bounded enums) or
Nothing if the array is allowed to grow indefinitely. Or an Either
parameter where Left (a,a) tells the max range and Right (a,a) -
(a,a) which tells how the range should grow on a resize.

Or just the range resize function :: (a,a) - (a,a) telling how to
grow on a resize, i.e. for enums function = id. Something like that.

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


Re: [Haskell-cafe] Learning from scratch

2006-03-15 Thread Jared Updike
For GHC try adding the line

import Data.Char

or

import Char

at the top of your Haskell program. Or in ghci, try Char.chr instead
of chr, etc. Or try
  ghci filename.hs
where filename.hs is a text file with the line import Char at the
top. Now 'chr' should appear in scope.

The hierarchical libraries are listed here:
   http://haskell.org/ghc/docs/latest/html/libraries/ (scroll down to
see all the modules listed)
You can search for functions here, e.g.:
http://haskell.org/hoogle/?q=chr

Good luck,
  Jared.

On 3/15/06, Xavier Elizalde [EMAIL PROTECTED] wrote:
 I'm just starting to learn Haskell from scratch and I've just hit a
 snag. The book Haskell: The Craft of Functional Programming, Second
 Edition uses some examples that call functions from Prelude.hs. But
 for some reason, two installations of Haskell that I have on my
 computer don't have the functions available. I have the OS X version
 of Hugs (http://www.haskell.org/soe/software.htm) for the book The
 Haskell School of Expression installed, as well as the latest
 version of the Glasgow Haskell Compiler. Both of them get errors with
 the functions such as ord and chr mentioned at the beginning of
 the first book mentioned. Where can I get Prelude.hs and the other
 files it needs, and what do I do with them? I'm going to move on to
 the School of Expression book after the Craft of Functional
 Programming book, which is why I have the SOE version of hugs installed.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] Trying to get a Composite design pattern to work

2006-03-13 Thread Jared Updike
(Moved to haskell-cafe)

 Actually, I'm trying to avoid library functions, so I can learn the
 language and the functional way of thinking.  How would one implement
 the concatMap function?

The Haskell 98 report gives possible implementations of standard functions:
   http://haskell.org/onlinereport/standard-prelude.html

e.g.

foldr:: (a - b - b) - b - [a] - b
foldr f z [] =  z
foldr f z (x:xs) =  f x (foldr f z xs)

map :: (a - b) - [a] - [b]
map f [] = []
map f (x:xs) = f x : map f xs

concat :: [[a]] - [a]
concat xss = foldr (++) [] xss

concatMap :: (a - [b]) - [a] - [b]
concatMap f = concat . map f

etc.

The book Haskell School of Expression (by Paul Hudak) goes over using
recursion as a control structure and then shows you how to replace
your simple recursion patterns with library functions once you start
to see these general patterns. As you start to understand the
functional style of iterating over lists, you should begin to see when
to use the library functions, and how it will save you time and be
more simple and clear than using recursion directly for every
function.

If you want a place to start, I would challenge you to expand the
concatMap definition above with the definitions of concat and map, and
then plug in the definition of foldr and see if you can make your own
concatMap function. Maybe that will help you understand things better.

Hope that helps,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] | vs. $ (was: request for code review)

2006-03-09 Thread Jared Updike
 Dude, that was a friggin' awesome email!  I'm trying to figure out how
 I can just copy it wholesale into the article ;)

Use what you need. Share and share alike.

 I've been struggling
 with Haskell for long enough that my knowledge is now snowballing
 downhill.

I think I experienced that too. I like how Haskell is about the
concepts (even things you didn't know you were already doing
implicitly) and the language is just a very transparent vehicle for
manipulating them. Haskell has really taught me a lot and helped me
think a lot clearer---but now I think in Haskell! The danger is that
since I've taken the red Haskell pill I have a hard time looking at
the imperative world the same way. I have to resist trying to cram all
these elegant approaches into a system that can't support them and
instead program like a normal person. (The good news is that many
languages are slowly soaking up features, e.g. C# delegates are
higher-order functions and anonymous delegates are lambdas, C# 3.0
will have some kind of type inference, etc. but these features are
many decades old.)

 Everything you said made sense 100%.

To add a few more comments to this: in Haskell you don't overload the
semicolon, instead you overload = (bind) and create a new
typeclass with this function (as well as a function called return,
where these two functions obey certain laws that keep things kosher,
i.e. return is the identity, = is associative, and they interact
as you would expect). It just so happens that the semicolons (or
newlines) in do blocks get converted into =s and lambdas to scope
your variables over the rest of your actions.

The reason monads are cool and magical is that now that we've made
this sequencing explicit in the type, we can swap out the machinery
(what type of implicit state we're passing around or even the =
function itself) and change a minimal amount of code, i.e. nothing...
except adding code to use the new functionality (if all goes well). We
can now get continuation passing, or true mutable variables (e.g.
IORef), or a simple sort of non-determinism (e.g. List as a monad), or
failure (Maybe) or exception handling, or any number of behaviors (or
combinations) by changing the monad.

BTW the original discussion was about composing functions and I gotta
say since C programmers don't really think in terms of f . g x = f (g
x) anyways, and since writing code in the order it executes is
natural (think Python   str.replace('\r', '').split('\n')  ), I think
the idea of explaining | as a pipe is pretty cool. There might be a
little too much overhead in explaining things if you drop the M-bomb
(monads), but if you can make and keep monads clear and simple and use
them there, you will have accomplished a great feat (and analogies
like Unix pipes are a good thing). I'm curious to see how this
evolves.

Good luck.
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] | vs. $ (was: request for code review)

2006-03-08 Thread Jared Updike
 I suspect you guys are right.  I had always thought of states as
 being isomorphic to integers (i.e. you can be in state 0, state 1,
 ... state n), not as contexts (you have this input, that output, and
 this token stack), am I wrong?

You're thinking of a state machine, I think, which is not quite what a
state monad would do here. (I have nightmares of writing a
state-machine parser in assembly like I did in an EE class once...
ouch).

  I suspect I need to spend more time
 trying to understand the state monad.  I must admit that I baulked
 the last time I tried to squeeze it into my head.  I'll just need to
 try again ;)

Here's the way I like to think about state in imperative
programs---it's hard because it's not something you can get far away
from enough to see, usually.

In imperative programs, the value of a variable 'a' at one point is
not always the value of the variable 'a' at another point later in the
code. In some sense, each statement that gets executed is passed the
entire state of the machine (the world) implicitly, and then when the
statement ends, it passes the state of the world on to the next
statement. If you want to access the value of the variable 'a', then
'a' gets looked up in the environment/state.
In C/C++/Java/C#/Python/Perl, etc. this is done for you automatically
and efficiently. It's just the way the machine works. But you don't
have the choice to change this or, as someone put it, overload the
semicolon.

In Haskell none of this variable-mutating, state-passing **can**
occur, so it gets created from scratch, and voila, we have the State
Monad. It makes it sound like a lot more work than it should be just
to do something that comes for free in most other languages, but in
these languages, you can't overload the semicolon! And if you could,
who knows what could go wrong at runtime (imagine Perl with semicolon
overloading... I bet some day they will do this just because they
can...). In Haskell, everything is watched over by the type system, so
the parts of your program that explicitly need to munge state are
isolated with the some type tag, e.g. ParseContext, while the rest of
your program is normal and pure and functional.

The problem with monads is not that they are advanced but that they
are so painfully and subtly abstract (I was going to say subtly
simple but maybe they aren't for most working non-Haskell
programmers...). (It just so happens that you **can** do amazing,
convenient, efficient, magic and otherwise advanced things with them,
especially with the libraries.) Another problem is that everyone has
different ways of explaining them or trying to define what they are (a
way of sequencing computation? or a type constructor? or a type
class?). Of course, they are all those things, which makes it even
more confusing. At a certain point, though, I think they just
subconciously click and boom, now you get it.

Anyway, if your goal is to get people to understand Haskell, then see
if you can use monads to simplify things. If your goal is to do a
straight translation of the C code, don't worry about monads.

My 2c,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Layout rule (was Re: PrefixMap: code reviewrequest)

2006-03-02 Thread Jared Updike
Layout only applies when something is less indented than previous
lines, I believe...

e.g.

 do
 c - getContents filename
 putStrLn blah

or

do
x - getContents filename
putStrLn ok

works fine but

 do
 c - blahAction
 putStrLn blah

obviously won't work

  Jared.

On 3/2/06, Brian Hulley [EMAIL PROTECTED] wrote:
 Brian Hulley wrote:
 [snip]
  So any solutions welcome :-)

 Thank to everyone who replied to my queries about this whole layout issue.

 One other thing I've been wanting to ask (not to change! :-)) for a while
 is: how is the following acceptable according to the rules in the Haskell98
 report where where is one of the lexemes, which when followed by a line
 more indented than the line the layout-starting-lexeme is on, should start
 an implicit block:

module M where
data T = .-- not indented!

 According to my understanding of the layout algorithm, the above code would
 have to be written:

module M where
   data T = 

 Can anyone shed some light on what the formal rule is that allows the first
 (and very useful) way of laying out code to be ok?

 Thanks, Brian.


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



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Layout rule (was Re: PrefixMap: code review request)

2006-02-28 Thread Jared Updike
BH  Why? Surely typing one tab is better than having to hit the
spacebar 4 (or 8)
BH  times?
PC Not when it prevents me from ever exhibiting the slightest shred of style
PC in my code. I use that control for readability purposes in my code.
 [snip]

BH I'm really puzled here. I've been using tabs to indent my C++ code for at
BH least 10 years and don't see the problem.

At least two reasons:
1. C++ doesn't care about any whitespace (except to separate tokens).
Haskell cares about leading whitespace (which it is clear you are
thinking a lot about...) but
2. as Philippa mentioned, Haskell programmers care a ton about
inter-line, inter-word layout/alignment, for example, lining up =
signs and arguments to functions in pattern matches, etc. C++ does not
invite this style of declarative programming so it is not surprising
that it wasn't an issue: aside from the indentation, I rarely type
fancy whitespace inside a giving line of C++ code to align elements
with those on a preceding line. In Haskell, this unofficial layout
style doesn't affect the machine-parsing of the code, but rather the
human-parsing of the code. (In fact, it's one of my favorite things
about Haskell.)

If you want to see what can be accomplished with variable width fonts
and complex layouts (not just beginning of lines but rather
inter-line, inter-word alignment) you should checkout lhs2TeX. They
accomplish all their magic with spaces.

BH The only problem would be if
BH someone mixed tabs with spaces. Since it has to be either tabs only or
BH spaces only I'd choose tabs only to save keystrokes.

BTW, tab doesn't type the tab character (at least in emacs and I think
vim) but instead moves the left edge of the current line by adding or
deleted spaces (or trying to ident the right amount). This usually
means you don't have to type 4 or 8 spaces. (And anyway, I would just
hold the key down if I had to type more than one spacebar, etc.)

 [snip]
 For example on Windows Trebuchet MS is a very nice font, also Verdana, both
 of which are not monospaced. But yes I agree it's not a major issue and I
 just see the option of being able to use them as a nice side-effect.

Very few programmers I know would go to variable width fonts just to
use some Microsoft font to edit code... (BTW I like Trebuchet and
Verdana too.)

To each his/her own!

Cheers,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] rounding errors with real numbers.

2006-02-26 Thread Jared Updike
 Well, if you are relying on exact results from floating point
 arithmetic you're in trouble no matter what you do.

As long as you don't do anything irrational (exp, sin, sqrt, etc.),
you should be able to get away with using Rational. Number constants
with decimals are not automatically constructors for floating point
numbers in Haskell; they are exact (fromRational) until you make them
Doubles or some other floating point value. If you have to use Doubles
for other reasons (performance/memory, interfacing with other code,
etc.) this won't help you...

Just my 2c.
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Monads (was how to write an interactive program ? gui library to use ?)

2006-02-25 Thread Jared Updike
(Note, moved to haskell-cafe.)

 Essentially, the answer is yes, the state needs to be passed around
 (neglecting hackery to simulate global variables that is better
 avoided).  However, this can be made convenient by using a monad.

BTW, Minh, If you don't know what monads are, then read this. Monads
are an indispensable part of programming in Haskell:
   http://www.nomaware.com/monads/html/
   http://haskell.org/hawiki/Monad
Monads are good. Monads are your friend.

  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Infinite loop?

2006-02-17 Thread Jared Updike
Yep. change one line to:

   entry - if isdir  name /= .  name /= ..

and it does in fact work.

  Jared.

On 2/17/06, Jon Fairbairn [EMAIL PROTECTED] wrote:
 On 2006-02-17 at 20:12GMT rgo wrote:
  Hi all,
  my program probably goes into infinite loop... But i cannot understand 
  where and why.

 getDirectoryContents will include . and .., so if you
 follow those, you're bound to loop.

 --
 Jón Fairbairn  Jon.Fairbairn at cl.cam.ac.uk


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



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problems instancing a class

2006-02-17 Thread Jared Updike
 type introduce a type synonym, and Haskell98 forbids these in
 instances, so GHC complains. GHC also lifts this restriction when
 invoked with -fglasgow-exts .
 http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#type-synonyms


Flexible Instances will probably be added to HaskellPrime:
  http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleInstances

This page:

http://cvs.haskell.org/Hugs/pages/users_guide/class-extensions.html#FLEXIBLE-INSTANCES

says that ultimately you would turn the type language pretty much into
Prolog (which would allow more expressive power---and less
inconvenience as we both would like--but make general type checking
undecidable). Instead they do a more conservative extension with a
fixed depth of constraints it will check so the compiler will
terminate.

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


Re: [Haskell-cafe] Haskell as scripting language?

2006-02-15 Thread Jared Updike
For scenario (a) you can use hs-plugins and ghc
  http://www.cse.unsw.edu.au/~dons/hs-plugins/
With hs-plugins you can get an eval command, or you can dynamically
load Haskell modules (from source or pre-compiled .o files).

GHC (= 6.5) has an API that you can access from Haskell programs:
  http://www.haskell.org/haskellwiki/GHC/As_a_library
I was wondering if the new GHC API gives you everything hs-plugins
does? If not will it ultimately do what hs-plugins does and replace
it, in the future?

  Jared.

On 2/15/06, Marc Weber [EMAIL PROTECTED] wrote:
 Is there a way to use haskell as scripting language in
 a) your own project?
 b) other projects such as vim (beeing written in C)?

 At the moment I'm interested, I don't have any real project..
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Matching constructors

2006-02-10 Thread Jared Updike
Or inline as

 findIndices (\x - case x of Tootie _ - True; _ - False) listOfPasAndTooties

There was a recent thread about wanting a more succint way to write
this (unary pattern matching):
http://thread.gmane.org/gmane.comp.lang.haskell.cafe/11109

If John got his wish, then you could write something like
 findIndices (@ Tootie _) listOfPasAndTooties

Maybe this feature will appear in a future Haskell standard? though I
don't see anything on the Haskell' wiki about this...

Cheers
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] haskell reference card ?

2006-02-07 Thread Jared Updike
On the new wiki, there is a keyword page as well (probably copied from
the old wiki):
http://haskell.org/haskellwiki/Keywords

I agree that it would be nice to have a reference card page much
like yours, Neil. So I made it on the wiki:
http://www.haskell.org/haskellwiki/Reference_card

By the way, what is the current plan for the old wiki? Should new
improvements be made to the new wiki
(http://haskell.org/haskellwiki/...) instead of the old one
(http://haskell.org/hawiki/...) ? Is the old wiki supposed to get
gradually merged into the new wiki/website? I understand it would be a
bad idea to take it down (so it will probably be there for a long
time) but is it supposed to be deprecated any time soon?

  Jared.

On 2/7/06, Neil Mitchell [EMAIL PROTECTED] wrote:
  is there somewhre Haskell reference card ?

 I attempted to start one quite a while ago:
 http://www.nmitchell.co.uk/code/haskell.htm

 But its not complete, and it was quite a while ago, so it may be wrong
 (but on the other hand, it may be useful)

 I also attempted to start a keyword list on the old haskell wiki
 http://www.haskell.org/hawiki/Keywords

 Perhaps there should be a wiki page for this? In which case, people
 are welcome to copy either of those above pages.

 Thanks

 Neil
 ___
 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] main features of functional programming paradigm

2006-02-06 Thread Jared Updike
 I would like to ask about what are tha main features
 of functional programming?

If you are new to functional programming, read this
http://haskell.org/haskellwiki/Introduction

 What kind of software can i develop with this
 methodology?

I'm not sure what you mean by your question as it is very general. (If
you are refering to the methodology in the FAD paper at
http://www.cs.kent.ac.uk/pubs/2001/1152/ , I haven't read it so I
can't help you there.) With Haskell, you can develop pretty much any
kind of software, as any other programming language. See
http://haskell.org/haskellwiki/Applications

(If you want to develop a compiler or interpreter, you are in luck as
functional programming languages are very good for developing this
kind of software.)

What kind of software are you intending to develop?

  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of leftassociative?

2006-02-04 Thread Jared Updike
 [a,b,c ; tail]  ===  a :: b :: c :: tail -- where ::

How is [a,b,c ; tail]   simpler, clearer or less typing than 
a:b:c:tail  ? I think that the commas and semicolons are easy to
confuse.

While we're talking about the aesthetics of :: and :, I like how a
line with a type annotation stands out strongly with ::, e.g.
map :: (a - b) - [a] - [b]
Compare this to
map : (a - b) - [a] - [b]
where the identifier looks more connected to the type. You will notice
this is different than ML anyway because in Haskell you can separate
the type annotation and the declaration.

If you are designing your own langauge, you will of course have your
own aesthetics and reasons for doing it your way. As for me, I started
to design (in my head) the perfect language (for me), but the more I
learned and used Haskell, the more I realized how carefully designed
it was and how it was better for me to use my efforts to learn from
Haskell (especially conceptually, since the syntax is so transparent
and the ideas are so amazing) than to try to insert clever ideas to
satisfy my own whims. Sure, there are always little things to nitpick,
but on the whole, can you think of more succinct language with more
power? (and less parentheses!) Plus, what other languages let you more
easily add (infix) operators, etc. and change things to fit your whim,
anyway (and still be strongly type!).

Cheers,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell code for this example of flow control

2006-02-01 Thread Jared Updike
I would use recrusion and the Prelude function until:

until (=1) (/2) 1000

Cheers,
  Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can I use Haskell for web programming

2006-01-22 Thread Jared Updike
For haskell-fastcgi, my configure fails with

cannot satisfy dependency cgi-any

Google does not turn up any useful results for this. Which package
will fix this dependency? I thought I just installed fastcgi from
source but I'm not sure where it gets looked for by haskell-fastcgi...

Thanks
   Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Can I use Haskell for web programming

2006-01-21 Thread Jared Updike
 Interesting. It's hosted on Haskell site. Do you think I would be
 able to do what you have done in a professional hosting service computer?

If you don't need dynamic web pages, you could develop the pages on
your own machine, generate HTML, etc. and then upload those to the
server of your choice. It may also be possible to deploy just the
compiled binaries (for the appropriate platform, i.e. BSD, Linux,
whatever the host uses) if you need CGI functionality and the hosting
service gives you the OK. I just run Ubuntu Linux (so I can put
whatever packages I need on there) on a machine connected to a DSL
modem and use dynamic DNS to keep the name pointed at my computer, but
I don't have high bandwidth needs. I'm finding Haskell to be a really
nice language for generating webpages, much better than doing things
by hand or even using Python, for example.

  Jared.

--
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] formal methods functional programming

2006-01-14 Thread Jared Updike
I can't think of any Haskell papers about ``formal methods'' in
software engineering, but many papers and books talk about proving
program correctness, which is difficult in traditional, imperative
languages (which is why it is probably not stressed as much as
//testing// is in formal software methods). Paul Hudak, in the
textbook, The Haskell School of Expression
(http://www.amazon.com/gp/product/0521644089/104-7074974-5852762?v=glancen=283155)
writes a lot about proving program correctness (especially induction
on recursive algorithms) for Haskell and purely functional programs,
reasoning mathematically.

If you want to do strenuous testing, you can use QuickCheck:
Automatic Specification-Based Testing: 
http://www.cs.chalmers.se/~rjmh/QuickCheck/

A professor I had at Caltech researches formal methods in constructing
reliable software systems, specifically using robust programming
language and compiler technology (in this case OCaml).
 http://mojave.caltech.edu/

  Jared.

On 1/14/06, Abigail [EMAIL PROTECTED] wrote:
 Hi,
 I have been searching papers about tha raltionship
 between formal methods in software engineering and
 functinal programmming, but i haven't found enough
 information.
 can u hel me?.
 Thanks
 Abigail.

 __
 Correo Yahoo!
 Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
 Regístrate ya - http://correo.espanol.yahoo.com/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Splitting a string into chunks

2006-01-13 Thread Jared Updike
That works except it loses single newline characters.

let s = 1234\n5678\n\nabcdefghijklmnopq\n\n,,.,.,.
Prelude blocks s
[12345678,abcdefghijklmnopq,,,.,.,.]

  Jared.

On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote:
 On 1/13/06, Sebastian Sylvan [EMAIL PROTECTED] wrote:
  On 1/13/06, Adam Turoff [EMAIL PROTECTED] wrote:
   Hi,
  
   I'm trying to split a string into a list of substrings, where substrings
   are delimited by blank lines.
  
   This feels like it *should* be a primitive operation, but I can't seem
   to find one that works.  It's neither a fold nor a partition, since each
   chunk is separated by a 2-character sequence.  It's also not a grouping
   operation, since ghc's Data.List.groupBy examines the first element in a
   sequence with each candidate member of the same sequence, as
   demonstrated by:
  
   Prelude :module + Data.List
   Prelude Data.List let t = asdfjkl;
   Prelude Data.List groupBy (\a _ - a == 's') t
   [a,sdfjkl;]
  
   As a result, I've wound up with this:
  
   -- Convert a file into blocks separated by blank lines (two
   -- consecutive \n characters.) NB: Requires UNIX linefeeds
  
   blocks :: String - [String]
   blocks s = f  s
 where
   f  [] = []
   f s [] = [s]
   f s ('\n':'\n':rest) = (s:f  rest)
   f s (a:rest) = f (s ++ [a]) rest
  
   Which somehow feels ugly.  This feels like it should be a fold, a group
   or something, where the test is something like:
  
   (\a b - (a /= '\n')  (b /= '\n'))
 
  Off the top of my head:
 
  blocks = map concat . groupBy (const null) . lines
 
  The lines function splits it into lines, the groupBy will group the
  list into lists of lists and split when the sedond of two adjacent
  elements is null (which is what an empty line passed to lines will
  give you) and then a concat on each of the elements of this list will
  undo the redundant lines-splitting that lines performed...
 

 Sorry, I got the meaning of groupBy mixed up, it should be

 blocks = map concat . groupBy (const (not . null)) . lines

 /S

 --
 Sebastian Sylvan
 +46(0)736-818655
 UIN: 44640862
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What does the Haskell type system do with show (1+2)?

2006-01-12 Thread Jared Updike
http://www.haskell.org/onlinereport/decls.html#default-decls
http://www.haskell.org/tutorial/numbers.html#sect10.4

On 1/12/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 What does the Haskell type system do with expressions such as these . . . ?
show 1
show (1+2)

 The type of the subexpressions 1 and 1+2 are ambiguous since they have
 type (Num a) = a.  I'm under the assumption before 1+2 is evaluated,
 the 1 and 2 must be coerced into a concrete type such as Int, Integer,
 Double, etc, and before show 1 is evaluated, the 1 must be coerced into
 a concrete type.  Is my assumption correct?  If so, how does Haskell know
 into which type to coerce the subexpressions?

 If I try to write a new function, my_show, which converts an expression
 into a string representation that includes type information, I run into
 errors with expressions like show 1 and show (1+2) because of the type
 ambiguity.

 class (Show a) = My_show a where
my_show :: a - String

 instance My_show Int where
my_show a = show a ++  :: Int

 instance My_show Integer where
my_show a = show a ++  :: Integer

 I can avoid the errors if I change it to my_show (1::Int) or my_show
 ((1+2)::Int).  I'm wondering what the difference is between, my_show and
 Haskell's built-in show that causes my_show to produce an error message when
 it is used with ambiguous types, but Haskell's show works okay with
 ambiguous types.




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





--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help compiling School of Expression graphics library?

2006-01-11 Thread Jared Updike
Someone else had this problem, I think.

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

  Jared.

On 1/11/06, Rakesh Malik [EMAIL PROTECTED] wrote:
 I'm trying to build the GraphicsLib code in Linux, Fedora. I have the
 March '05 version of Hugs installed (and ghc, but that doesn't seem to
 be relevant to this).

 The first bit of puzzlement comes from the error messages I'm getting:
 ffihugs +G +LX_stub_ffi.c X.hs
 Warning: unknown toggle `G'; ignoring.
 Warning: unknown toggle `L'; ignoring.
 runhugs: Unable to initialise Hugs (Unrecognised option)

 Hugs is on my path ($HOME/hugs/bin), and I edited the Makefile to point the
 hugs_install home directory to $HOME/hugs. X_dir is correct, it has
 lib/libX11.a and
 include/X11/X.h.

 My gc version is: gcc (GCC) 4.0.0 20050519 (Red Hat 4.0.0-8)
 (I don't know whether that's relevant, but just in case.)

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



--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mixing IO and STM

2005-12-29 Thread Jared Updike
Also, if you are trying to display a line that looks like
  insert 5
or
  consume 6
then consider using
   putStrLn (insert  ++ show r)
   putStrLn (consume  ++ show r)
instead of
   print (insert  ++ show r)
   print (consume  ++ show r)
to avoid printing out the extra quotation marks. The function print is
defined in the prelude as

 print  :: Show a = a - IO ()
 print x=  putStrLn (show x)

also, you could do:

 putStrLn $ insert  ++ show r

because the $ infix operator is just a tightly binding function
application... you can think of it as a sort of left parenthesis that
automatically adds a right parenthesis at the end of your expression.

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


Re: [Haskell-cafe] Re: Haskell Speed

2005-12-26 Thread Jared Updike
 Back to where this came from, my view is that this is an education
 issue - tutorials tend to focus on lazy, functional techniques, and
 not on efficiency.

 But the material is available, so people *can* learn. It just needs
 some effort (but possibly more than it should...)

Can anyone suggest some good tutorials, papers, or books to read for
learning how to reason about laziness, specifically, time and space
complexity? I seem to remember that Richard Bird's Introduction to
Functional Programming book has a chapter or so on this subject, but
what other material would anyone recommend for trying to understand
how to write efficient, lazy algorithms? Maybe in the spirit of
updating Wikis and such, we can collect this sort of material
together...

  Jared.
--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Tutorial uploaded

2005-12-22 Thread Jared Updike
SKC This entire discussion is about 'breaking a cyclic graph of conceptual
SKC dependencies'. Unfortunately, I don't think it can be done well in short
SKC amount of time.

I bet if we sat down and listed all the concepts required to write
idiomatic Haskell (even idiomatic Haskell 98 (whatever this means)),
to write programs that do the things that we all have done in other
languages (you know what I'm talking about here, but of course this is
up for debate too), we would see that it was not a linear structure
but a cyclic graph or at best a tree of concepts: we need to
understand higher order functions, polymorphic higher order types for
monads, monads to understand I/O really well (or to understand WHY I/O
in a purely functional language is the way it is), typeclasses,
laziness, etc. etc.

In a lot of situations, pedagogy is hard to 'linearize'. Why would it
be any different in programming? especially in Haskell? A lot of
learning Haskell is just helping reinforce this strong, but sometimes
subtle base of knowledge required to really start to get Haskell.
[1]

HT Btw. Simon Thompson states in his book, that he found it didactically
HT infelicitous to introduce recursion before higher order functions because
HT that let beginners stick to case discriminations and recursive programming
HT instead of taking advantage of functions like 'map', 'iterate', 'fold'
HT etc. I can confirm this experience and I think that it is similar to IO
HT vs. non-IO.

It very well may be didactically infelicitous [2]. (I wish there
were some program we can just run on a course syllabus and find out
that something is felicitous):

 conceptsInHaskell :: [haskellConcept]
 conceptsInHaskell = [...] -- abstract
 main = print $ sort conceptsInHaskell
..
 error: haskellConcept not a member of class Ord.

Maybe we'll (collectively) get better and better at this. I think we
are. Hopefully experience and sharing this information will be
beneficial to all (as well as discussion like these).
Maybe it depends on who is learning Haskell, and why: maybe the
'conflict' is that learning to program *in* Haskell /= learning to
program *with* Haskell.

But maybe it's not ultimately an optimizable piece of data, the
right order of teaching concepts in Haskell. Maybe it should be
allowed to be more random-access? (I personally like things more that
way :-) .

Cheers
  Jared.
--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:

[1] Perhaps a point in Haskell's favor for pedagogy is that there are
things you can do in Haskell that you just can't do (in the same,
succint sense) in most programming languages, e.g. even OCaml. Maybe
these things (and they are neat, simple things, like the code twos =
2:twos and then manipulating this infinite stream) can help motivate
people to really want to grok Haskell, and to stick with it and use it
for practical projects because of its many advantages. :-)

[2] Paul Hudak does this in the Haskell School of Expression. He
writes recursive code with cases, etc. and then in a later chapter
explains how to rewrite it with map, fold, etc. Fine. It takes steps
to learn how to write idiomatic Haskell. At least for me, the joy of
Haskell is not in memorizing vocabulary (as is common in a language
like Java, or C#) but rather, internalizing concepts. By writing ugly
code at first and then seeing the patterns and refactoring with map
and fold, I've personally internalized it (instead of learning some
clever rule, up front, that I'll later forget). Think Why FP Matters
by Hughes. He does this too (recursion, pattern matching, then later
swapping in higher order functions), to explain why FP is so great.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FAQ: Why no interactive definitions?

2005-12-22 Thread Jared Updike
There was a good discussion about this on an earlier thread.

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

In fact, this exact question sparked a number of long threads. :-)
(First steps in Haskell, Tutorial upload, Proposal for a First Tutorial.)

Cheers,
  Jared.
--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problems with square root...

2005-12-21 Thread Jared Updike
MG () - Parenthesis
MG {} - Braces
MG [] - Brackets
MG Sorry to be pedantic, but using the wrong terminology confuses me and
MG I'm sure others as well.

This is true for Haskell, but Daniel is correct if he is calling ()
Brackets because they are, in British English, right? (Just like '.'
is a 'period' in US, but it is a 'full stop' in UK.). Of course,
English /= Haskell so in Haskell I guess they are called Parenthesized
Expressions (in the Haskell report
http://www.haskell.org/onlinereport/exps.html).

To be extra pedantic, I would call {} Curly Braces (or Curly Brackets,
or squiggly brackets, or squiggles, or ... just use layout and
whitespace!) and I would call [] Square Brackets. Then no one gets
confused.

Cheerio,
  Jared

P.S. IANAA = I am an American, so I could very well be wrong about
British English!

 On 12/21/05, Daniel Carrera [EMAIL PROTECTED] wrote:
  Daniel Carrera wrote:
   Hey,
  
   The sqrt function is not doing what I want. This is what I want:
  
   round sqrt(2)
 
  Sigh... never fails. Spend an hour trying to solve a problem, and a
  minute after you write to the list you find the solution. I need
  brackets around sqrt. I'm surprised though. I don't understand why it
  dosn't work without brackets.
 
  Daniel.
  --
/\/`) http://oooauthors.org
   /\/_/  http://opendocumentfellowship.org
  /\/_/
  \/_/I am not over-weight, I am under-tall.
  /
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 


 --
 50% of marriages today end in divorce, the other 50% end in death.
 Which would you rather have?
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse )-:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  1   2   >