Re: [Haskell-cafe] Ideas

2007-08-26 Thread Andrew Coppin

Evan Laforge wrote:

Indeed, you can write certain DSP algorithms beautifully in Haskell.
Now, if only it could talk to the audio hardware... (Or just use common
file formats even.)



Oh, that's easy.  I wrote an FFI interface to portaudio a while back
to write a delay-looping type utility in haskell.  It was pretty
trivial.  You could do the same for libsndfile or whatever.
  


Well, since I can't do C...

(What I typically end up doing in these situations is to write a small 
server program in some language that *does* have the feature I want, and 
then talk to it over TCP from the language that *doesn't* have the 
feature. But it's typically quite a lot of typing... and the only 
language I know of that supports sound (other than C) is Java. And it's 
*very* complicated...)



The only thing I'm uncertain about is whether it would have good
enough time and space performance.  All the real work is writing yet
another set of basic envelope, oscillator, and fft primitives.  You
*should* be able to go all the way down to the samples in pure haskell
though, which would be more elegant than those other languages :)
  


Heh. FFT is tricky. But I got it to work one time... ;-)


Reaktor has abstraction. You can build a gizmo that does something
useful, call it a macro, and then use it whereever you want.



Well, except that if you then change your macro you have re-copy it
into every instrument or ensemble or other macro that uses it.  So I
consider the macros basically a copy and paste mechanism.
  


True, true...

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


Re: [Haskell-cafe] Re: Parsec is being weird at me

2007-08-26 Thread Andrew Coppin

Chris Casinghino wrote:

On 8/25/07, Andrew Coppin [EMAIL PROTECTED] wrote:
  


I thought the whole *purpose* of the endBy combinator was to keep
applying one parser until the other one succeeds?




I don't think this is a lookahead problem, but rather just a
misreading of the spec of endBy.  Here it is:

(endBy p sep) parses zero or more occurrences of p, seperated and
ended by sep. Returns a list of values returned by p.

The key text is seperated and ended by sep.  Not just ended by.
  


...so then what does sepEndBy do?

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


Re: [Haskell-cafe] Re: Parsec is being weird at me

2007-08-26 Thread Andrew Coppin

Chris Casinghino wrote:

On 8/25/07, Chris Casinghino [EMAIL PROTECTED] wrote:
  

I'm not sure there is a built in combinator for what you want,




I guess I should have looked harder.  What you want is manyTill:

manyTill  :: GenParser tok st a - GenParser tok st end - GenParser tok st [a]

(manyTill p end) applies parser p zero or more times until parser end
succeeds. Returns the list of values returned by p.
  


Yeah, OK, that looks good...

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


Re: [Haskell-cafe] Ideas

2007-08-26 Thread Claude Heiland-Allen

Evan Laforge wrote:

The only thing I'm uncertain about is whether it would have good
enough time and space performance.  All the real work is writing yet
another set of basic envelope, oscillator, and fft primitives.  You
*should* be able to go all the way down to the samples in pure haskell
though, which would be more elegant than those other languages :)


I've been playing with using Arrows as stream processors for audio, and
the dataflow syntax of arrows is quite nice for sample manipulation:

-- low pass filter (1-zero)


lop i = proc (x, f) - do
  sr - readState - SampleRate
  let c = clip (2 * pi * f / sr) 0 1
  rec y - delay i - o
  let o = x * c + (1 - c) * y
  returnA - o



lop :: (ArrowCircuit a, ArrowReader b a, Floating b, Ord b)
= b - a (b, b) b


Unfortunately it's *very* slow - to render a 5s sine oscillator sweep
from 20Hz to 2Hz through a low pass filter at 44100Hz sampling rate
takes around 17s.

Admittedly 40% of the time is spent outputting the numbers to a text
file, but it's still far far from realtime, and churns through 7GB of
memory in the process (the total memory usage at any one time is
constant and small, however).


Claude
--
http://claudiusmaximus.goto10.org


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


[Haskell-cafe] Files for Hugs on Zaurus

2007-08-26 Thread Ulrich Vollert

Hi Phillipa,

Hugs is fast enough for me to work on the Zaurus.

I packed together all the files which belong to Hugs on my Zaurus and I
hope that I didnt miss something.

Unpack them to /, the files will stay in usr/local/bin, usr/local/lib
and usr/local/share.

If you want to use Hugs not only under the console, but with pdaxqtrom
(which includes a X-Server,  a gcc-Compiler and tons of other stuff), go
to http://www.users.on.net/~hluc/myZaurus/custom.html

Please tell me, whether Hugs is working for you.

Regards,
Ulrich





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


Re: [Haskell-cafe] Style

2007-08-26 Thread Yitzchak Gale
Bjorn Bringert wrote:
 Here's a much more inefficient version, but it has the merit of being
 very easy to understand:

 tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n]

Be careful with types - use Data.List.genericLength
here instead of length. Otherwise, tm_silly n is wrong for
n = 13 (on my 32-bit machine) due to round-off error
in the Int type.

Here is another implementation:

 base5 n
  | n  1 = []
  | otherwise = let (q, r) = n `divMod` 5 in r : base5 q

 tm6 = sum . zipWith (*) [(5^k-1)`div`4 | k - [0..]] . base5

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


Re: [Haskell-cafe] Text.Xhtml.Strict

2007-08-26 Thread Henning Thielemann

On Sat, 25 Aug 2007, Marco Túlio Gontijo e Silva wrote:


Hello there.

I don't know if it's off topic, but I don't know where else to ask.

I've been using Text.Xhtml.Strict, and I'm wondering why the functions
are mostly Html - Html and not HTML a = a - Html, or something
similar.  If they were like this,  and toHtml would be not needed,
what would make it simpler to call the functions with arguments that
are not Html.

The question is specific to this library, but I think it's a very
general one: isn't it better to have more generic functions with type
changing inside?  It seems to me that it would make things better from
the users point of view. What do you think?


The disadvantage of more generic types is that they reduce the 
possibilities of type inference by the compiler. In the case of HTML 
generation it might still work well, that is, you could live without type 
annotations.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Converting CTime - Int

2007-08-26 Thread Sven Panne
[ Sorry for the *extremely* slow response, but I'm currently working through 
my backlog of 6000 mails... :-P ]

On Wednesday 16 May 2007 09:35, Tomasz Zielonka wrote:
 I wonder why CTime is not Integral - maybe there is no such guarantee
 for time_t? If so, then you shouldn't rely on Enum. The safest bet seems
 to be toRational - CTime is Real.

The Single Unix Specification has the answer:

http://www.opengroup.org/onlinepubs/95399/basedefs/sys/types.h.html#tag_13_67

   time_t and clock_t shall be integer or real-floating types.

CTime's Enum instance is as debatable as the ones for Float and Double, but 
for consistency reasons we included it in the FFI spec.

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


Re: [Haskell-cafe] Ideas

2007-08-26 Thread Henning Thielemann


On Sat, 25 Aug 2007, Andrew Coppin wrote:

Would be nice if I could build something in Haskell that overcomes these. 
OTOH, does Haskell have any way to talk to the audio hardware?


Maybe a JACK interface?
 http://haskell.org/haskellwiki/Applications_and_libraries/Music_and_sound
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] :, infix operator, infix constructor, et cetera

2007-08-26 Thread Isaac Dupree

Andrew Coppin wrote:

Daniel C. Bastos wrote:
But that won't compile, because it doesn't obey the syntax rules of 
Haskell. You could, however, write


 data List x = x : (List x) | End

and it would work.

 1 : (2 : (3 : End))


Except that (for no particularly good reason) : is a reserved symbol 
that always refers to the Prelude list version.  You could define a 
similar name like:


data List x = x :- (List x) | End

  1 :- (2 :- (3 :- End))



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


Re: [Haskell-cafe] Ideas

2007-08-26 Thread Henning Thielemann


On Sat, 25 Aug 2007, Evan Laforge wrote:


Reaktor has a few limitations though.

1. It's virtually impossible to debug the thing! (I.e., if your synth
doesn't work... good luck working out why.)

2. It lacks looping capabilities. For example, you cannot build a
variable-size convolution block - only a fixed-size one. (If you want to
draw *a lot* of wires!) If you look through the standard library, you'll
find no end of instruments that use a hack of using voice polyphony to
crudely simulate looping... but it's not too hot.

Would be nice if I could build something in Haskell that overcomes
these. OTOH, does Haskell have any way to talk to the audio hardware?


...

To get this back to haskell, at the time I wondered if a more natural
implementation might be possible in haskell, seeing as it was more
naturally lazy.  Not sure how to implement the behaviours though
(which were simply macros around a let of *dynamic-something*).  I'm
sure people have done plenty of signal processing, and there's always
haskore... but what about a sound generation language like csound or
clm or nyquist?  It could fit in nicely below haskore.


I'm playing around with Haskore controlling signal synthesis 
implemented in pure Haskell for some time now:

 http://darcs.haskell.org/synthesizer/src/Haskore/Interface/Signal/
  It works, but it's still slow and hard to install.


This discussion is certainly also of interest for the haskell-art mailing 
list.

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


[Haskell-cafe] Audio output (Was: Re: Ideas)

2007-08-26 Thread Henning Thielemann


On Sat, 25 Aug 2007, Andrew Coppin wrote:


Evan Laforge wrote:

To get this back to haskell, at the time I wondered if a more natural
implementation might be possible in haskell, seeing as it was more
naturally lazy.  Not sure how to implement the behaviours though
(which were simply macros around a let of *dynamic-something*).  I'm
sure people have done plenty of signal processing, and there's always
haskore... but what about a sound generation language like csound or
clm or nyquist?  It could fit in nicely below haskore.


Indeed, you can write certain DSP algorithms beautifully in Haskell. Now, if 
only it could talk to the audio hardware... (Or just use common file formats 
even.)


I invoke a variety of sound converters/players (sox, alsaplayer, ecasound) 
in order to fix this problem. Writing and playing this way is easy. 
Reading files is problematic because the converters cannot output header 
information.

 'http://darcs.haskell.org/synthesizer/src/Sox/File.hs'
 'http://darcs.haskell.org/synthesizer/src/Sox/Play.hs'
 'http://darcs.haskell.org/dafx/src/Presentation.hs'
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ideas

2007-08-26 Thread Henning Thielemann


On Sat, 25 Aug 2007, Andrew Coppin wrote:

How easy would it be to make / would anybody care / has somebody already made 
... in Haskell?


- An interactive function plotter. (GNUplot is nice, but it can't plot 
recursive functions...)


I'm be interested to use such a library.


- A graphical programming tool. (You add boxes and put in lines, it constructs a 
program that you can run.)


Would be nice for editing signal processing that is coded in Haskell.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ideas

2007-08-26 Thread Henning Thielemann


On Sun, 26 Aug 2007, Andrew Coppin wrote:


The only thing I'm uncertain about is whether it would have good
enough time and space performance.  All the real work is writing yet
another set of basic envelope, oscillator, and fft primitives.  You
*should* be able to go all the way down to the samples in pure haskell
though, which would be more elegant than those other languages :)


Heh. FFT is tricky. But I got it to work one time... ;-)


There's already an extensive FFT implementation in Haskell by Matt 
Donadio:

 http://haskelldsp.sourceforge.net/

(I'm working on some clean up at
 http://darcs.haskell.org/dsp/Numeric/Transform/Fourier/ )
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Style

2007-08-26 Thread Chaddaï Fouché
2007/8/26, Yitzchak Gale [EMAIL PROTECTED]:
 Bjorn Bringert wrote:
  Here's a much more inefficient version, but it has the merit of being
  very easy to understand:
 
  tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n]

 Be careful with types - use Data.List.genericLength
 here instead of length. Otherwise, tm_silly n is wrong for
 n = 13 (on my 32-bit machine) due to round-off error
 in the Int type.

Are you sure you really tested tm_silly ? length is perfectly enough
to count the 0 in n! since the number of zeros don't go over the Int
limit before n = 8_589_934_615 (though this solution will stack
overflow due to the product much sooned than that).

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


Re: [Haskell-cafe] :, infix operator, infix constructor, et cetera

2007-08-26 Thread Andrew Coppin

Isaac Dupree wrote:

Andrew Coppin wrote:

Daniel C. Bastos wrote:
But that won't compile, because it doesn't obey the syntax rules of 
Haskell. You could, however, write


 data List x = x : (List x) | End

and it would work.

 1 : (2 : (3 : End))


Except that (for no particularly good reason) : is a reserved symbol 
that always refers to the Prelude list version.  You could define a 
similar name like:


Really? That's interesting... AFAIK, according to the Report, it 
shouldn't be.


I just tested. GHC won't let me, WinHugs will. Hmm...

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


[Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread manu

Hello,

After reading Peter Norvig's take on writing a Sudoku solver (http:// 
norvig.com/sudoku.html)
I decided that I would port his program to Haskell, without changing  
the algorithm, that'll make a nice exercise I thought

and should be fairly easy... Boy, was I wrong !

Anyway, I eventually managed to tiptoe around for loops, mutable  
state, etc...
However, when I run my program against the test data provided (http:// 
norvig.com/top95.txt),
I find it takes around 1m20 s to complete (compiled with -fvia-C and - 
O2, on a MacBook Pro 2.33GHz Intel Core 2 Duo).
That's roughly 8 times longer than Norvig's Python script. That's not  
what I expected !

My program is also longer than the Python version.

Being a beginner, I am convinced my implementation is super naive and  
non idiomatic. A seasonned Haskeller would do much shorter and much  
faster. I don't know how to improve it though !


Should I introduce more strictness ? replace lists with more  
efficient data structures (ByteStrings, Arrays) ?


Here is my program, and part of the profiling (memory allocation  
looks huge !)


I hope this post wasn't too long. Thanks for any advice !

Emmanuel.

{-

This is an attempt to implement in Haskell, Peter Norvig's sudoku  
solver :

Solving Every Sudoku Puzzle (http://norvig.com/sudoku.html)

In Norvig's program, methods which change a grid return either a new  
grid, either False (failure).

Here I use Maybe, and return Just grid or Nothing in case of failure

-}

module Main where

import Prelude hiding (lookup)
import Data.List hiding (lookup)
import qualified Data.Map as M
import Control.Monad
import Maybe
import System.IO

--
-- Types
type Digit  = Char
type Square = String
type Unit   = [Square]

-- We represent our grid as a Map
type Grid = M.Map Square [Digit]


--
-- Setting Up the Problem

rows = ABCDEFGHI
cols = 123456789
digits = 123456789

cross :: String - String - [String]
cross rows cols = [ r:c:[] | r - rows, c - cols ]

squares :: [Square]
squares = cross rows cols  -- [A1,A2,A3,...]

unitlist :: [Unit]
unitlist = [ cross rows [c] | c - cols ] ++
   [ cross [r] cols | r - rows ] ++
   [ cross rs cs | rs - [ABC,DEF,GHI], cs -  
[123,456,789]]


units :: M.Map Square [Unit]
units = M.fromList [ (s, [ u | u - unitlist, elem s u ]) | s -  
squares ]


peers :: M.Map Square [Square]
peers = M.fromList [ (s, set [[ p | p - e, p /= s ] | e - lookup s  
units ]) | s - squares ]

  where set = nub . concat

--
-- Wrapper around M.lookup used in list comprehensions

lookup :: (Ord a, Show a) = a - M.Map a b - b
lookup k v = case M.lookup k v of
Just x - x
Nothing - error $ Error : key  ++ show k ++  not  
in map !


-- lookup k m = fromJust . M.lookup k m
--
-- Parsing a grid into a Map

parsegrid :: String - Maybe Grid
parsegrid g= do regularGrid g
foldM assign allPossibilities (zip squares g)

  where  allPossibilities :: Grid
 allPossibilities = M.fromList [ (s,digits) | s - squares ]
 regularGrid   :: String - Maybe String
 regularGrid g  = if all (\c - (elem c 0.-123456789)) g
 then (Just g)
 else Nothing

--
-- Propagating Constraints

assign:: Grid - (Square, Digit) - Maybe Grid
assign g (s,d) = if (elem d digits) then do -- check that we are  
assigning a digit and not a '.'

let toDump = delete d (lookup s g)
res - foldM eliminate g (zip (repeat s) toDump)
return res
 else return g

eliminate ::  Grid - (Square, Digit) - Maybe Grid
eliminate g (s,d) = let cell = lookup s g in
if not (elem d cell) then return g -- already  
eliminated

-- else d is deleted from s' values
   else do let newCell = delete d cell
   newV = M.insert s newCell g --
   newV2 - case length newCell of
   -- contradiction :  
Nothing terminates the computation

   0 - Nothing
   -- if there is only one  
value (d2) left in square, remove it from peers
   1 - do let peersOfS =  
[ s' | s' - lookup s peers ]
   res - foldM  
eliminate newV (zip peersOfS (cycle newCell))

   return res
   -- else : return the new  
grid

   _ - return newV
   -- Now check 

Re: [Haskell-cafe] is there a way to run tests at compile time using TH

2007-08-26 Thread Chris Mears
Alex Jacobson [EMAIL PROTECTED] writes:

 I'd like to have code not compile if it doesn't pass the tests.

 Is there a way to use TH to generate compiler errors if the tests
 don't pass?

What about something like this?

import Language.Haskell.TH

import Tests -- this should export testsPass :: Bool

-- don't bother trying to call this function.
check = $( if testsPass then [| () |]
   else error test failed )

main = print hi

If testsPass returns False, the compiler will throw an exception during
compilation, like this:

Exception when trying to run compile-time code:
  test failed
  [...]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] :, infix operator, infix constructor, et cetera

2007-08-26 Thread Ian Lynagh
On Sun, Aug 26, 2007 at 01:35:33PM +0100, Andrew Coppin wrote:
 Isaac Dupree wrote:
 
 Except that (for no particularly good reason) : is a reserved symbol 
 
 Really? That's interesting... AFAIK, according to the Report, it 
 shouldn't be.

It is; from http://haskell.org/onlinereport/syntax-iso.html

consym   -  (: {symbol | :})reservedop
reservedop   -  .. | : | :: | = | \ | | | - | - | @ | ~ | =

 I just tested. GHC won't let me, WinHugs will. Hmm...

Sounds like a WinHugs bug if you haven't enabled extensions.


Thanks
Ian

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


Re: [Haskell-cafe] is there a way to run tests at compile time using TH

2007-08-26 Thread Ian Lynagh
On Sun, Aug 26, 2007 at 01:20:52AM -0700, Alex Jacobson wrote:
 I'd like to have code not compile if it doesn't pass the tests.
 
 Is there a way to use TH to generate compiler errors if the tests don't 
 pass?

This should do it, in a different module to that which defines runtests:

$( case runtests of
   Success - return []
   Failure - error Tests failed
 )


Thanks
Ian

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


Re: [Haskell-cafe] renderString problems

2007-08-26 Thread Sven Panne
On Wednesday 01 August 2007 18:30, Dave Tapley wrote:
 I'm having a lot of trouble using renderString from Graphics.UI.GLUT.Fonts.
 All my attempts to render a StrokeFont have so far failed.
 Using a BitmapFont I can get strings to appear but they demonstrate
 the odd behaviour of translating themselves a distance equal to their
 length every time my displayCallback function is evaluated.

This is actually not a bug, but a feature. :-) From the Haddock docs for 
renderString:


Render the string in the named font, without using any display lists. 
Rendering a nonexistent character has no effect.

If the font is a bitmap font, renderString automatically sets the OpenGL 
unpack pixel storage modes it needs appropriately and saves and restores the 
previous modes before returning. The generated call to bitmap will adjust the 
current raster position based on the width of the string. If the font is a 
stroke font, translate is used to translate the current model view matrix to 
advance the width of the string. 


The rational behind this is that you set a position once, and subsequent 
multiple renderString calls will render the individual strings one after the 
other, just like printf appends strings on the output. If this is not clear 
from the documentation, any suggestions how to improve the docs?

And another hint: On usual consumer graphic cards, stroke fonts are normally 
faster than bitmapped fonts. The fastest, most flexible (scaling, 
filtering, ...) and visually nicest option would be textured quads, but this 
is not supported by GLUT.

 My requests are:
   * Does anyone know how to keep the position fixed?

For bitmapped fonts, explicitly set the currentRasterPosition. For stroke 
fonts, you can use the normal modelview machinery 
(loadIdentity/preservingMatrix/...).

   * Are there any good examples of (working) GLUT code available on
 the web, I'm finding it very hard to make any progress at the moment.
 Certainly not at Haskell speed :(

Depending on the distribution you use, you probably have the example already 
somewhere on your disk or you can directly have a look at the repository:

   http://darcs.haskell.org/packages/GLUT/examples/

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


Re: [Haskell-cafe] renderString problems

2007-08-26 Thread Martin DeMello
On 8/26/07, Sven Panne [EMAIL PROTECTED] wrote:

 This is actually not a bug, but a feature. :-) From the Haddock docs for
 renderString:

 
 Render the string in the named font, without using any display lists.
 Rendering a nonexistent character has no effect.

 If the font is a bitmap font, renderString automatically sets the OpenGL
 unpack pixel storage modes it needs appropriately and saves and restores the
 previous modes before returning. The generated call to bitmap will adjust the
 current raster position based on the width of the string. If the font is a
 stroke font, translate is used to translate the current model view matrix to
 advance the width of the string.
 

 The rational behind this is that you set a position once, and subsequent
 multiple renderString calls will render the individual strings one after the
 other, just like printf appends strings on the output. If this is not clear
 from the documentation, any suggestions how to improve the docs?

Why not add the rationale to the docs too? Invoking printf should make
the thing jump into focus for anyone who hasn't got it.

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


Re: [Haskell-cafe] Re: Parsec is being weird at me

2007-08-26 Thread Chris Casinghino
On 8/26/07, Andrew Coppin [EMAIL PROTECTED] wrote:

 ...so then what does sepEndBy do?


With endBy, the sequence must end with the separator, with sepEndBy,
the final occurrence of the separator is optional.

The documentation here is very good:

http://legacy.cs.uu.nl/daan/parsec.html

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


Re: [Haskell-cafe] Style

2007-08-26 Thread Yitzchak Gale
I wrote:
 Be careful with types - use Data.List.genericLength
 here instead of length. Otherwise, tm_silly n is wrong for
 n = 13 (on my 32-bit machine) due to round-off error
 in the Int type.

 Are you sure you really tested tm_silly ?
 length is perfectly enough
 to count the 0 in n! since the number
 of zeros don't go over the Int limit

True, that is not the problem.

Using length forces the result to
be Int, which is different than all of
the other tm's so far. So for example,
try this:

[n | n - [0..25], tm_silly n /= tm n]

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


[Haskell-cafe] nested datatypes

2007-08-26 Thread Thomas Girod
Hi there.

recently I was trying to represent complex data by defining several
datatypes and nesting them, such as

data Foo = Foo { foo :: Bar }
deriving (Eq,Show)
data Bar = Bar { bar :: Int }
deriving (Eq,Show)

To change only a part of the data, syntactic sugar is quite convenient. But
it seems to be quite painful with nested datatypes.

b = Bar 10
f = Foo b

foobar :: Int - Foo - Foo
foobar i f =
let nb = (foo f){bar = i}
in f{foo = nb}

So, my question is : is there a nifty way to modify data within a nested
datatype, similar to the f{foo = bar} style ? If not, anyone is using some
kind of workaround for this ?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread Derek Elkins
On Sun, 2007-08-26 at 14:50 +0200, manu wrote:
 Hello,
 
 After reading Peter Norvig's take on writing a Sudoku solver (http:// 
 norvig.com/sudoku.html)
 I decided that I would port his program to Haskell, without changing  
 the algorithm, that'll make a nice exercise I thought
 and should be fairly easy... Boy, was I wrong !
 
 Anyway, I eventually managed to tiptoe around for loops, mutable  
 state, etc...
 However, when I run my program against the test data provided (http:// 
 norvig.com/top95.txt),
 I find it takes around 1m20 s to complete (compiled with -fvia-C and - 
 O2, on a MacBook Pro 2.33GHz Intel Core 2 Duo).
 That's roughly 8 times longer than Norvig's Python script. That's not  
 what I expected !
 My program is also longer than the Python version.
 
 Being a beginner, I am convinced my implementation is super naive and  
 non idiomatic. A seasonned Haskeller would do much shorter and much  
 faster. I don't know how to improve it though !
 
 Should I introduce more strictness ? replace lists with more  
 efficient data structures (ByteStrings, Arrays) ?

Yes.  Treating lists like arrays is always a recipe for heartbreak.  If
you did want to try to match the python code exactly there are mutable
arrays and such.

http://www.haskell.org/haskellwiki/Sudoku has a bunch of different
implementations going for different things.

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


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread Malte Milatz
manu [EMAIL PROTECTED]:
 After reading Peter Norvig's take on writing a Sudoku solver (http:// 
 norvig.com/sudoku.html)
 I decided that I would port his program to Haskell

Your program was wrapped by your mail client, so you may want to hpaste
your program for easier digestion.

 Being a beginner, I am convinced my implementation is super naive and  
 non idiomatic. A seasonned Haskeller would do much shorter and much  
 faster. I don't know how to improve it though !

Disclaimer: I'm not an experienced Haskeller either, and I haven't had
a real look at your code at all. The following is only what stroke me
by a quick look. Gurus may eventually reduce your code into a
thirty-line version that also runs quickly.

 -- Types
 type Digit  = Char
 type Square = String
 type Unit   = [Square]
 
 -- We represent our grid as a Map
 type Grid = M.Map Square [Digit]

Your profiling output suggests that much time is consumed by the lookup
function. Since you're using (fromJust . lookup) everywhere anyway, a
data structure not envolving the Maybe type is probably a more succint
choice. And why bother with characters and strings? So I propose

type Square = (Int,Int)
type Grid   = Array Square Int -- or [Int], if the algorithm requires
that

Where the array's bound are (0,0), (8,8) or (1,1), (9,9), according to
your taste.

  newV2 - case length newCell of
  0 - Nothing
  1 - do let peersOfS =  [ s' | s' - lookup s peers ]
  res - foldM  eliminate newV (zip peersOfS (cycle 
 newCell))
  return res 
   _ - return newV

The use of “length” here is not an actual performance problem, but
unnecessary. Simply write: case newCell of []  - ...
  [_] - ...
  _   - ...

The same is valid for your other use of length.

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


[Haskell-cafe] Re: Ideas

2007-08-26 Thread John MacFarlane
+++ Andrew Coppin [Aug 25 07 12:50 ]:
 How easy would it be to make / would anybody care / has somebody already 
 made ... in Haskell?
 
 - A wiki program. (Ditto.)

I wrote a simple wiki using HAppS and pandoc.  See demonstration #15
on the pandoc web page:

http://sophos.berkeley.edu/macfarlane/pandoc/examples.html

It's by no means a finished product, but might serve as a good base
if you decide to work on a wiki.

John

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


[Haskell-cafe] Re: Hugs on Zaurus

2007-08-26 Thread Radosław Grzanka
2007/8/26, Ulrich Vollert [EMAIL PROTECTED]:
  Haskell could run on such a platform. Ofcourse this is completly
  other way around in terms of power and memory. :)
 
  But anyway, did anyone do it?

 I compiled Hugs for my Sharp Zaurus SL-C3200 (http://www.trisoft.de)
 which is a PDA with an ARM processor.

 (System: Lineo uLinux , CPU: Intel(r) XScale™ (PXA270, 416 MHz))

 Hugs was compiled by gcc 2.95.3 and can be used in the console,
 additionally under a special X/Qt-Environment called pdaXqtrom
 (http://www.users.on.net/~hluc/myZaurus/).

 So, it is possible to use graphics on the Zaurus, too. I didnt dare to
 port ghc or Yhc - which would be great to use on the Zaurus, too.

This is so cool. Unfortunatly I own Treo 650 and running Linux here is
a lot of hackery. It would be awsomely cool to use Hugs on it.

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


Re: [Haskell-cafe] Ideas

2007-08-26 Thread luc.taesch


John MacFarlane wrote:
 
 +++ Andrew Coppin [Aug 25 07 12:50 ]:
 
 
 I wrote a simple wiki using HAppS and pandoc.  See demonstration #15
 on the pandoc web page:
 
 http://sophos.berkeley.edu/macfarlane/pandoc/examples.html
 
 
o
Hey ! that s exactly whatI had in mind.. cool

indeed, I am toying with the idea to 
- produce book, nicely (automatically) typeset with Latex or docbook
- out of a wiki as interface ( as wikibook for instance)
- with either free and informal text , 
  - or formally ( automatically  produced) sets or reference or docs ( a
bit like literate programming embed code into the text), but these table
would be more and more refined set of requirement..

This last point  was with a software ingeniering backgroud in mind, 
ie to produce the requirement, and specification of software, , imagine a
lot of reference and cross reference to manage, and to establish
tracability..( if you heard about Cleanroom, just to examplify )

may i ask you what did you had in mind as an application when you started
that ?




-- 
View this message in context: 
http://www.nabble.com/Ideas-tf4327747.html#a12337130
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] Re: nested datatypes

2007-08-26 Thread apfelmus
(Note that the term nested data type also/already carries the meaning 
non-regular data type, an example being

  data PerfectBinaryTree a = One a | Succ (PerfectBinaryTree (a,a))
)

Thomas Girod wrote:

recently I was trying to represent complex data by defining several
datatypes and nesting them, such as

data Foo = Foo { foo :: Bar }
deriving (Eq,Show)
data Bar = Bar { bar :: Int }
deriving (Eq,Show)

To change only a part of the data, syntactic sugar is quite convenient. But
it seems to be quite painful with nested datatypes.

b = Bar 10
f = Foo b

foobar :: Int - Foo - Foo
foobar i f =
let nb = (foo f){bar = i}
in f{foo = nb}

So, my question is : is there a nifty way to modify data within a nested
datatype, similar to the f{foo = bar} style ? If not, anyone is using some
kind of workaround for this ?


There is a nifty way, called functional references. They're a pair of 
get and set functions


  data Ref s a = Ref { get :: s - a, set :: a - s - s }

The nice thing about them is that we can compose them like functions

  o :: Ref b c - Ref a b - Ref a c
  f `o` g = Ref (get f . get g) (\c a - set (set c f $ get g a) g a)

The example becomes

  data Foo = Foo Bar
  data Bar = Bar Int

  foo :: Ref Foo Bar
  foo = Ref (\(Foo x) - x) (\x (Foo _) - Foo y)

  bar :: Ref Bar Int
  bar = Ref (\(Bar x) - x) (\x (Bar _) - Bar x)


  foobar :: Ref Foo Int
  foobar = bar `o` foo

See also

  http://luqui.org/blog/archives/2007/08/05/
  haskell-state-accessors-second-attempt-composability/

and

  Sander Evers, Peter Achten, and Jan Kuper. A Functional Programming
  Technique for Forms in Graphical User Interfaces.
  http://www.st.cs.ru.nl/papers/2005/eves2005-FFormsIFL04.pdf


Writing getter and setter functions by hand can be tedious but somebody 
already automated this with Template Haskell or other other 
preprocessing tools.



Regards,
apfelmus

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


[Haskell-cafe] Re: Ideas

2007-08-26 Thread John MacFarlane
 may i ask you what did you had in mind as an application when you started
 that ?

This was just recreational programming: I wanted to see what writing a
web application in Haskell would be like. I think it would be great to
have a fully featured wiki program in Haskell, but I don't have time to
do it myself. Your idea sounds very interesting. Feel free to extend
pandocwiki if that works for you; it's GPL.

John

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


Re: [Haskell-cafe] Re: Parsec is being weird at me

2007-08-26 Thread Andrew Coppin

Chris Casinghino wrote:

On 8/26/07, Andrew Coppin [EMAIL PROTECTED] wrote:
  

...so then what does sepEndBy do?




With endBy, the sequence must end with the separator, with sepEndBy,
the final occurrence of the separator is optional.
  


Oh. I see...

*sigh* Another wetware error. :-/

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


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread Yitzchak Gale
Hi Manu,

You wrote:
 After reading Peter Norvig's take on writing a Sudoku solver
 (http:// norvig.com/sudoku.html)
 I decided that I would port his program to Haskell, without changing
 the algorithm, that'll make a nice exercise I thought
 and should be fairly easy... Boy, was I wrong !

Welcome to the Haskell Sudoku club!

http://haskell.org/haskellwiki/Sudoku

Please add your solver there.

I enjoyed reading your solver, and comparing
it to the Python version. It was a nice idea
to port the imperitive parts of this algorithm using
the Maybe monad.

The algorithm of your solver is essentially identical
to the solver I posted on the wiki page; even the data
structures are more or less the same. But mine is
written in a more native Haskell style (happens to
be based on a State monad).

 When I run my program against the test data
 provided (http://norvig.com/top95.txt),
 I find it takes around 1m20 s to complete

I just ran mine against that file,
also on a MacBook like yours, but only
2Ghz. It took about 28s, only about double
Norvig's claim. There are other solvers on
the wiki page that claim to be considerably faster.

 (compiled with -fvia-C

The GHC gurus can correct me, but I understand
that there isn't likely to be any advantage to -fvia-C
nowadays.

 My program is also longer than the Python version.

Yes, but for porting foreign code I think you did great.

The use of strings, copied from the Python, looks
a bit arcane in Haskell, but it shouldn't hurt anything.
Perhaps you would gain something if you used Data.Map.!
instead of your lookup. Other than that, I'm not
sure why your code runs slower than mine.

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


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread Yitzchak Gale
Manu wrote:
 Should I introduce more strictness ? replace lists with more
 efficient data structures (ByteStrings, Arrays) ?

Derek wrote:
 Yes.  Treating lists like arrays is always a recipe
 for heartbreak.

Here it costs very little - the lists are all short, mostly of
length exactly 9.

 If you did want to try to match the python code exactly
 there are mutable arrays and such.

I think Manu's code is about as exact as you can get
for a direct translation into pure Haskell. You could
emulate Python using imperitive-style Haskell, but that
would be a different sort of port.

If speed is really important for you, there are many
ways to optimize a Haskell program - the techniques
Derek mentioned, and many more, all the way down
to low-level bit fiddling on the bare metal. There are
some great people on this list who are very, very
good at that.

But I personally find that for my own purposes,
pure, simple, clear Haskell is almost always more
than fast enough. And it saves truckloads of
debugging time.

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


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread manu

From: Malte Milatz [EMAIL PROTECTED]
Subject: Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

Your program was wrapped by your mail client, so you may want to  
hpaste

your program for easier digestion.



here it is : http://hpaste.org/2452



Your profiling output suggests that much time is consumed by the  
lookup

function. Since you're using (fromJust . lookup) everywhere anyway, a
data structure not envolving the Maybe type is probably a more succint
choice. And why bother with characters and strings?



no rationale except that's what the original Python script did use





 newV2 - case length newCell of
 0 - Nothing
 1 - do let peersOfS =  [ s' | s' - lookup s peers ]
 res - foldM  eliminate newV (zip peersOfS  
(cycle newCell))

 return res
  _ - return newV


The use of “length” here is not an actual performance problem, but
unnecessary. Simply write: case newCell of []  - ...
  [_] - ...
  _   - ...

The same is valid for your other use of length.

Malte


I see, thanks !

E.D





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


[Haskell-cafe] arrows-.02 fails when rebuilding ghc 6.6.1

2007-08-26 Thread Luc TAESCH
I try download and build 6.6.1 ( as ubntu has just 6.6 on package) and
most went ok ( compiler and most libs) but arrows

i tried and download arrow 0.2 from hackage but no more success

any ideas ? ( knowing 6.6 is also on the machine if that matters)


[EMAIL PROTECTED]:~/src/arrows-0.2$ runghc Setup.hs build
Preprocessing library arrows-0.2...
Building arrows-0.2...
[ 1 of 13] Compiling Data.Stream  ( Data/Stream.hs,
dist/build/Data/Stream.o )
[ 2 of 13] Compiling Control.Arrow.Transformer (
Control/Arrow/Transformer.hs, dist/build/Control/Arrow/Transformer.o )
[ 3 of 13] Compiling Control.Arrow.Operations (
Control/Arrow/Operations.hs, dist/build/Control/Arrow/Operations.o )
[ 4 of 13] Compiling Control.Arrow.Transformer.CoState (
Control/Arrow/Transformer/CoState.hs,
dist/build/Control/Arrow/Transformer/CoState.o )
[ 5 of 13] Compiling Control.Arrow.Internals (
Control/Arrow/Internals.hs, dist/build/Control/Arrow/Internals.o )
[ 6 of 13] Compiling Control.Arrow.Transformer.Automaton (
Control/Arrow/Transformer/Automaton.hs,
dist/build/Control/Arrow/Transformer/Automaton.o )

Control/Arrow/Transformer/Automaton.hs:98:0:
Illegal instance declaration for `ArrowWriter w (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowWriter w (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:104:0:
Illegal instance declaration for `ArrowError r (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowError r (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:115:0:
Illegal instance declaration for `ArrowReader r (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowReader r (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:120:0:
Illegal instance declaration for `ArrowState s (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowState s (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:126:0:
Illegal instance declaration for `ArrowAddWriter w
 (Automaton a)
 (Automaton a')'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowAddWriter w (Automaton a)
(Automaton a')'
I discovered recently that my ubuntu package were providing only 6.6
and the latest cabal needs 6.6.1.
when rebuilding this one from the tar ( not the head on darcs)

most went ok but the arrows lib.

I also tried to get it from hackage, but idem:
( I also have 6.6 on the machaine  dos it matters ?)
here is the build from hacakge with runghc :

[EMAIL PROTECTED]:~/src/arrows-0.2$ runghc Setup.hs build
Preprocessing library arrows-0.2...
Building arrows-0.2...
[ 1 of 13] Compiling Data.Stream  ( Data/Stream.hs,
dist/build/Data/Stream.o )
[ 2 of 13] Compiling Control.Arrow.Transformer (
Control/Arrow/Transformer.hs, dist/build/Control/Arrow/Transformer.o )
[ 3 of 13] Compiling Control.Arrow.Operations (
Control/Arrow/Operations.hs, dist/build/Control/Arrow/Operations.o )
[ 4 of 13] Compiling Control.Arrow.Transformer.CoState (
Control/Arrow/Transformer/CoState.hs,
dist/build/Control/Arrow/Transformer/CoState.o )
[ 5 of 13] Compiling Control.Arrow.Internals (
Control/Arrow/Internals.hs, dist/build/Control/Arrow/Internals.o )
[ 6 of 13] Compiling Control.Arrow.Transformer.Automaton (
Control/Arrow/Transformer/Automaton.hs,
dist/build/Control/Arrow/Transformer/Automaton.o )

Control/Arrow/Transformer/Automaton.hs:98:0:
Illegal instance declaration for `ArrowWriter w (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowWriter w (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:104:0:
Illegal instance declaration for `ArrowError r (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowError r (Automaton a)'

Control/Arrow/Transformer/Automaton.hs:115:0:
Illegal instance declaration for `ArrowReader r (Automaton a)'
(the Coverage Condition fails for one of the functional dependencies;
 Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ArrowReader r (Automaton a)'


Re: [Haskell-cafe] arrows-.02 fails when rebuilding ghc 6.6.1

2007-08-26 Thread Ross Paterson
On Sun, Aug 26, 2007 at 11:16:17PM +0200, Luc TAESCH wrote:
 I try download and build 6.6.1 ( as ubntu has just 6.6 on package) and
 most went ok ( compiler and most libs) but arrows
 
 i tried and download arrow 0.2 from hackage but no more success

You need to change the Extensions line in arrows.cabal to

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


[Haskell-cafe] Re: Ideas

2007-08-26 Thread Luc TAESCH
thanks John for replying...

when building , i cannot find the lcs mentionned in the cabal file not
on hasckage nor on goggle.
could you help?
( your papers on philosophy looks quite serious .. impressive you are
in haskell too ..  math backgroud ? logics ?)


2007/8/26, John MacFarlane [EMAIL PROTECTED]:
  may i ask you what did you had in mind as an application when you started
  that ?

 This was just recreational programming: I wanted to see what writing a
 web application in Haskell would be like. I think it would be great to
 have a fully featured wiki program in Haskell, but I don't have time to
 do it myself. Your idea sounds very interesting. Feel free to extend
 pandocwiki if that works for you; it's GPL.

 John


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


Re: [Haskell-cafe] Norvig's Sudoku Solver in Haskell

2007-08-26 Thread Yitzchak Gale
I wrote:
 Perhaps you would gain something if you used Data.Map.!
 instead of your lookup.

Manu wrote:
 I'm not sure I understand, do you mean I should have use a strict Map
 constructor ?
 like : Map !key !value ?

No, there is an operator in Data.Map called !.

 how can it replace the lookup function ?

Use

 import qualified Data.Map as M
 import Data.Map (!)

Then, instead of lookup k m
use m ! k.

 Other than that, I'm not
 sure why your code runs slower than mine.

Malte Milatz wrote:
MM The use of length here is not an actual
MM performance problem...

Maybe not there, but I think Malte's suggestion might
actually improve performance if you do the same
thing a few lines further down, where you wrote:

 case length dPlaces of

By using Malte's idea there instead of length, you might
allow some calculations inside dPlaces to be lazily
skipped.

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


[Haskell-cafe] Re: Ideas

2007-08-26 Thread John MacFarlane
lcs can be found at http://urchin.earth.li/darcs/igloo/lcs/

+++ Luc TAESCH [Aug 26 07 23:45 ]:
 when building , i cannot find the lcs mentionned in the cabal file not
 on hasckage nor on goggle.
 could you help?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Style

2007-08-26 Thread Chaddaï Fouché
2007/8/26, Yitzchak Gale [EMAIL PROTECTED]:
 True, that is not the problem.

 Using length forces the result to
 be Int, which is different than all of
 the other tm's so far. So for example,
 try this:

 [n | n - [0..25], tm_silly n /= tm n]


You mean to say that tm_silly returns Int, which means we can't use it
directly in a comparison but have to use toInteger or fromInteger ?
Ok, in this case, but it's still a nice test for our more optimized
functions (and using genericLength is much slower than toInteger .
length, though of course the results differ for really long list)

$ [n | n - [1..1000], toInteger (tm_silly n) /= tm n]
[]

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


[Haskell-cafe] Help understanding a partial application

2007-08-26 Thread Levi Stephen

Hi,

I was browsing through the source code for Data.Foldable and having trouble 
comprehending it (which was kind of the point of browsing the code, so I could 
learn something ;) )


I'm looking at foldl

foldl :: (c - d - c) - c - t d - c
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z

But, I haven't got very far. I'm still trying to follow:

Endo . flip f

f is of type c-d-c, so this makes flip f of type d-c-c.

I think the Endo constructor is of type (a-a)-Endo a

I think a is binding to a function type here, but can not work out what.

(From memory) ghci reports

 :t Endo . flip (+)
Num a = a - Endo a

So, this looks like a partial application of the constructor?

But, this still isn't helping me understand.

Any thoughts or pointers that might help me comprehend what's happening?

Thanks,
Levi
lstephen.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Geometry

2007-08-26 Thread Tony Morris
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I went camping on the weekend and a friend of mine who is a builder
asked me many questions on geometry as they apply to his every day work
- - most of which I could answer.

However, there was one that I couldn't and I am having trouble googling
a solution (for lack of keywords?). I'm hoping a fellow Haskeller could
help me out (in Haskell of course).

The problem is finding the unknown x from the two knowns a and b in the
given image below (excuse my Microsoft Paintbrush skills). I may have
misunderstood his problem (we were drawing in dirt) and actually, it is
the straight line between the two points on the circumference that are
known and not the specified 'b', but I figure I could derive one
solution from another if I have misunderstood him.

Here is my image:
http://tinyurl.com/2kgsjy

Thanks for any tips or keywords with which to google!

- --
Tony Morris
http://tmorris.net/

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG0iM6mnpgrYe6r60RAqfDAJ4gFAdr7zP1ehLl8H2MaCzCNfAvhQCgmL8D
4nrxrK13O9EBNv/ojPIMJXI=
=eaxX
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Joel Koerwer
Hi Tony,

x is called the sagitta. At least when making a telescope mirror it is[1].

By bisecting your angle with another radius, you'll see that you have
a right triangle with hypotenuse a, and legs of length (b/2) and
(a-x). Then

sagitta a b = a - sqrt (a*a - b*b/4)

Considered as a function of half the angle subtended by the points on
the circumference, this is called the versine.
http://en.wikipedia.org/wiki/Versine

[1] http://www.stellafane.com/atm/atm_grind/atm_measure_sag.htm
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Chaddaï Fouché
You've got a which is the radius of the circle, and b which is the
length of the arc, thus you've got the angle between the two red
radiuses : u = b / a
So with basic trigonometry, we can deduce a - x = a * cos(u/2)
x = a *( cos(u/2) - 1)

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


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Stefan O'Rear
On Mon, Aug 27, 2007 at 11:04:58AM +1000, Tony Morris wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 I went camping on the weekend and a friend of mine who is a builder
 asked me many questions on geometry as they apply to his every day work
 - - most of which I could answer.
 
 However, there was one that I couldn't and I am having trouble googling
 a solution (for lack of keywords?). I'm hoping a fellow Haskeller could
 help me out (in Haskell of course).
 
 The problem is finding the unknown x from the two knowns a and b in the
 given image below (excuse my Microsoft Paintbrush skills). I may have
 misunderstood his problem (we were drawing in dirt) and actually, it is
 the straight line between the two points on the circumference that are
 known and not the specified 'b', but I figure I could derive one
 solution from another if I have misunderstood him.
 
 Here is my image:
 http://tinyurl.com/2kgsjy

This is a fairly simple exercise in trigonometry.  Call the angle
subtended by b, θ.  Then:

b = a sin(θ/2)
a - x = a cos(θ/2)

by the relation between circles and trig functions.  From this we can
(algebraicly) derive:

sin(θ/2) = b / a
x = a - a cos(θ/2)
x = a - a (1 - b² / a²)^½   (nb, I'm assuming θ is less than 180° here)

And as you request:

problem a b = a - a * sqrt (1 - b*b / a*a)

Stefan


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


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Chaddaï Fouché
2007/8/27, Chaddaï Fouché [EMAIL PROTECTED]:
 You've got a which is the radius of the circle, and b which is the
 length of the arc, thus you've got the angle between the two red
 radiuses : u = b / a
 So with basic trigonometry, we can deduce a - x = a * cos(u/2)
 x = a *( cos(u/2) - 1)

 --
 Jedaï


Actually that would be x = a * (1 - cos (b/(2a)))
Ooops o_O

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


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Steve Schafer
On Mon, 27 Aug 2007 11:04:58 +1000, you wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I went camping on the weekend and a friend of mine who is a builder
asked me many questions on geometry as they apply to his every day work
- - most of which I could answer.

However, there was one that I couldn't and I am having trouble googling
a solution (for lack of keywords?). I'm hoping a fellow Haskeller could
help me out (in Haskell of course).

The problem is finding the unknown x from the two knowns a and b in the
given image below (excuse my Microsoft Paintbrush skills). I may have
misunderstood his problem (we were drawing in dirt) and actually, it is
the straight line between the two points on the circumference that are
known and not the specified 'b', but I figure I could derive one
solution from another if I have misunderstood him.

Here is my image:
http://tinyurl.com/2kgsjy

Thanks for any tips or keywords with which to google!

So a is the radius of the circle, and b is half the length of the chord.

From basic trigonometry:

 b = a * sin @

where @ is half of the angle between the two radii as drawn in the
picture.

Then:

 x = a * (1 - cos @)

Using the trigonometric identity sin^2 @ + cos^2 @ = 1 and rearranging,
we get:

 x = a - sqrt(a^2 - b^2)

I don't know offhand if there's a straightforward way to arrive at this
result without using trigonometry.

By the way, I found http://www.1728.com/circsect.htm by Googling height
chord.

Steve Schafer
Fenestra Technologies Corp.
http://www.fenestra.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Geometry

2007-08-26 Thread Steve Schafer
On Sun, 26 Aug 2007 21:30:30 -0400, you wrote:

I don't know offhand if there's a straightforward way to arrive at this
result without using trigonometry.

Duh. Of course there is

Steve Schafer
Fenestra Technologies Corp.
http://www.fenestra.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help understanding a partial application

2007-08-26 Thread Ryan Ingram
Just expand out the function composition:
Dual . Endo . flip f = (\x - Dual (Endo (flip f x)))
which has the type d - Dual (Endo c).

  -- ryan


On 8/26/07, Levi Stephen [EMAIL PROTECTED] wrote:

 Hi,

 I was browsing through the source code for Data.Foldable and having
 trouble
 comprehending it (which was kind of the point of browsing the code, so I
 could
 learn something ;) )

 I'm looking at foldl

 foldl :: (c - d - c) - c - t d - c
 foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z

 But, I haven't got very far. I'm still trying to follow:

 Endo . flip f

 f is of type c-d-c, so this makes flip f of type d-c-c.

 I think the Endo constructor is of type (a-a)-Endo a

 I think a is binding to a function type here, but can not work out what.

 (From memory) ghci reports

  :t Endo . flip (+)
 Num a = a - Endo a

 So, this looks like a partial application of the constructor?

 But, this still isn't helping me understand.

 Any thoughts or pointers that might help me comprehend what's happening?

 Thanks,
 Levi
 lstephen.wordpress.com
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] Help understanding a partial application

2007-08-26 Thread Levi Stephen

Ryan Ingram wrote:

Just expand out the function composition:
Dual . Endo . flip f = (\x - Dual (Endo (flip f x)))
which has the type d - Dual (Endo c).
 
  -- ryan




Aha.

I didn't get this straight away, but once I looked at the type signature for 
function composition, it became clear.


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