[Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Magnus Therning
I'm putting together a package consisting of 2 executables. Only one of
them is pure Haskell and thus buildable on all platforms, the other
relies on Windows API calls and can only be built on that platform.  I
found the “if os(...)” conditional in the CABAL docs but I'm having
problems getting it to do what I want.

if os(mingw32)
  executable foo
...

Results in the error “Section expected”.  Swapping the two lines like this

executable foo
  if os(mingw32)
...

results in “Setup.hs: Error: No 'Main-Is' field found for executable foo”.

Is there a way to get CABAL to do what I want or should I raise a
feature request on the CABAL trac?

/M

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus@therning.org Jabber: magnus.therning@gmail.com
http://therning.org/magnus

What if I don't want to obey the laws? Do they throw me in jail with
the other bad monads?
 -- Daveman



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


Re: [Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Thomas Schilling

executable foo
  main-is: bla
  if !os(windows):
buildable: false

Unfortunately this gives rather unhelpful error messages when used  
with flags, but it works well enough for now.


/ Thomas


On 4 mar 2008, at 09.10, Magnus Therning wrote:

I'm putting together a package consisting of 2 executables. Only  
one of

them is pure Haskell and thus buildable on all platforms, the other
relies on Windows API calls and can only be built on that platform.  I
found the “if os(...)” conditional in the CABAL docs but I'm  
having

problems getting it to do what I want.

if os(mingw32)
  executable foo
...

Results in the error “Section expected”.  Swapping the two lines  
like this


executable foo
  if os(mingw32)
...

results in “Setup.hs: Error: No 'Main-Is' field found for  
executable foo”.


Is there a way to get CABAL to do what I want or should I raise a
feature request on the CABAL trac?

/M

--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus@therning.org Jabber: magnus.therning@ 
gmail.com

http://therning.org/magnus

What if I don't want to obey the laws? Do they throw me in jail with
the other bad monads?
 -- Daveman

___
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] CABAL: conditional executable?

2008-03-04 Thread Henning Thielemann


On Tue, 4 Mar 2008, Magnus Therning wrote:


I'm putting together a package consisting of 2 executables. Only one of
them is pure Haskell and thus buildable on all platforms, the other
relies on Windows API calls and can only be built on that platform.  I
found the “if os(...)” conditional in the CABAL docs but I'm having
problems getting it to do what I want.

if os(mingw32)
 executable foo
   ...

Results in the error “Section expected”.  Swapping the two lines like this

executable foo
 if os(mingw32)
   ...

results in “Setup.hs: Error: No 'Main-Is' field found for executable foo”.


It sounds like another instance of the case that parts of a package cannot 
be build under some circumstances. Keep in mind that other packages might 
rely on the installed second executable if they find that the package is 
installed. Thus, I guess it's better to extract the second executable to a 
different package for Window's only stuff.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Magnus Therning
On 3/4/08, Henning Thielemann [EMAIL PROTECTED] wrote:


 On Tue, 4 Mar 2008, Magnus Therning wrote:

  I'm putting together a package consisting of 2 executables. Only one of
  them is pure Haskell and thus buildable on all platforms, the other
  relies on Windows API calls and can only be built on that platform.  I

  found the â  if os(...)â   conditional in the CABAL docs but I'm having

  problems getting it to do what I want.
 
  if os(mingw32)
   executable foo
 ...
 

  Results in the error â  Section expectedâ  .  Swapping the two lines
 like this

 
  executable foo
   if os(mingw32)
 ...
 

  results in â  Setup.hs: Error: No 'Main-Is' field found for executable
 fooâ  .

 It sounds like another instance of the case that parts of a package cannot
 be build under some circumstances. Keep in mind that other packages might
 rely on the installed second executable if they find that the package is
 installed. Thus, I guess it's better to extract the second executable to a
 different package for Window's only stuff.



Good point.  Does CABAL 1.2 have support for multiple .cabal files in the
same directory?  If not then I'm not too happy with this solution.

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


Re: [Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Thomas Schilling


On 4 mar 2008, at 10.58, Magnus Therning wrote:



Good point.  Does CABAL 1.2 have support for multiple .cabal files  
in the same directory?  If not then I'm not too happy with this  
solution.


No.  Eventually, Cabal will support something like this, but it's  
unlikely that Cabal 1.4 will.

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


Re: [Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Magnus Therning
On 3/4/08, Thomas Schilling [EMAIL PROTECTED] wrote:

 executable foo
main-is: bla
if !os(windows):
  buildable: false

 Unfortunately this gives rather unhelpful error messages when used
 with flags, but it works well enough for now.

 / Thomas


Hmmm, I don't seem to get this to work the way I want it.  I get a Parse of
field 'buildable' failed: which means configure failed and then I can't
proceed to build the second executable, bar, in the same package.

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


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread Paul Johnson

Alan Carter wrote:

I've written up some reflections on my newbie experience together with
both versions, which might be helpful to people interested in
popularizing Haskell, at:

http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/
  

Thank you for writing this.

On the lack of simple examples showing, for example, file IO: I seem to 
recall a Perl book (maybe it was Edition 1 of the Camel Book) which had 
lots of very short programs each illustrating one typical job.  Also the 
Wiki does have some pages of worked example programs.  But I agree, we 
could do better.


I'm surprised you found the significant whitespace difficult.  Yes, the 
formal rules are a bit arcane, but I just read them as does the Right 
Thing, and it generally works for me.  I didn't know about the 
significance of comments, but then I've never written an outdented comment.


I had a look through your code, and although I admit I haven't done the 
work, I'm sure that there would be ways of factoring out all the 
commonality and thereby reducing the length.


Finally, thanks for that little story about the BBC B.  I had one of 
those, and I always wondered about that heatsink, and the stonking big 
resistor next to it.  They looked out of scale with the rest of the board.


Paul.

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


Re: [Haskell-cafe] CABAL: conditional executable?

2008-03-04 Thread Thomas Schilling


On 4 mar 2008, at 11.37, Magnus Therning wrote:


On 3/4/08, Thomas Schilling [EMAIL PROTECTED] wrote:
executable foo
   main-is: bla
   if !os(windows):
 buildable: false

Unfortunately this gives rather unhelpful error messages when used
with flags, but it works well enough for now.

/ Thomas

Hmmm, I don't seem to get this to work the way I want it.  I get a  
Parse of field 'buildable' failed: which means configure failed  
and then I can't proceed to build the second executable, bar, in  
the same package.


Oh, right.  That's a bug in Cabal 1.2 (fixed in HEAD).  Use:

  buildable: False

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


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread Ketil Malde
Paul Johnson [EMAIL PROTECTED] writes:

 I'm surprised you found the significant whitespace difficult. 

I wonder if this has something to do with the editor one uses?  I use
Emacs, and just keep hitting TAB, cycling through possible alignments,
until things align sensibly.  I haven't really tried, but I can
imagine lining things up manually would be more painful, especially
if mixing tabs and spaces.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread Luke Palmer
On Tue, Mar 4, 2008 at 4:16 AM, Ketil Malde [EMAIL PROTECTED] wrote:
 Paul Johnson [EMAIL PROTECTED] writes:

   I'm surprised you found the significant whitespace difficult.

  I wonder if this has something to do with the editor one uses?  I use
  Emacs, and just keep hitting TAB, cycling through possible alignments,
  until things align sensibly.  I haven't really tried, but I can
  imagine lining things up manually would be more painful, especially
  if mixing tabs and spaces.

Especially if mixing tabs and spaces indeed.  Haskell does the Python
thing of assuming that a tab is 8 spaces, which IMO is a mistake.  The
sensible thing to do if you have a whitespace-sensitive language that
accepts both spaces in tabs is to make them incomparable to each
other; i.e.


main = do
spspputStrLn $ Hello
spsptab++ World
-- compiles fine


main = do
spspputStrLn $ Hello
tab++ World
-- error, can't tell how indented '++ World' is...

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


[Haskell-cafe] Markup bug in HaskellWiki

2008-03-04 Thread Henning Thielemann


In the Wiki article

  http://haskell.org/haskellwiki/Comparison_chain

 there is the piece

  unzipunzip

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


Re: [Haskell-cafe] Markup bug in HaskellWiki

2008-03-04 Thread Dougal Stanton
On 04/03/2008, Henning Thielemann [EMAIL PROTECTED] wrote:

  In the Wiki article

http://haskell.org/haskellwiki/Comparison_chain

   there is the piece

unzipunzip

   which is improperly formatted.

I guess the wiki uses GeSHi, and it's because of a bug in the keyword
list. I reported it to the maintainer a few weeks ago (when I wrote
this [1]) but I haven't heard any word back. It's dead easy to fix if
someone has access to the PHP source.

There's a file called, IIRC, haskell.php with a large list of
keywords. Two of them, 'unzip' and 'unzip3' appear twice. Delete one
of each and it all works fine again.


[1] 
http://www.dougalstanton.net/blog/index.php/2008/02/12/spot-the-deliberate-mistake


-- 
Dougal Stanton
[EMAIL PROTECTED] // http://www.dougalstanton.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread Paul Moore
On 04/03/2008, Alan Carter [EMAIL PROTECTED] wrote:
 http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/

That was an interesting read. Thanks for posting it. I also liked the
tale of the BBC ULA - it reminded me of a demo I saw once at an Acorn
show, where they had a RISC PC on show, with a (IBM) PC card in it.
They were demonstrating how hot the PC chip runs compared to the ARM
RISC chip by using it to make toast. I dread to think what you could
do with one of today's monsters :-)

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


Re: [Haskell-cafe] Connection helpers: for people interested in network code

2008-03-04 Thread Bjorn Bringert
On Fri, Feb 29, 2008 at 8:50 PM, Adam Langley [EMAIL PROTECTED] wrote:
 I generally find that I'm wrapping sockets in the same functions a lot
  and now I'm looking writings code which works with both Sockets and
  SSL connections. So I wrote a module, presumptuously called
  Network.Connection, although I'm not actually going to try and take
  that name (even in Hackage) unless I get a general agreement that this
  is a good thing.

  So, any comments on the interface, similar things that I should look at etc?

  
 http://www.imperialviolet.org/binary/network-connection/Network-Connection.html

  I made the BaseConnection an ADT, rather than a class because I wanted
  to avoid hitting the monomorphism restriction in code. That might have
  been a mistake, I'm not sure yet.

  If it doesn't excite anyone enough to reply, I'll change the name and
  put it in Hackage, mostly as is. Then I'll tie HsOpenSSL into it so
  that SSL connections work transparently.

Hi Adam,

you may want to have a look at the socket abstraction used in the HTTP package:

http://hackage.haskell.org/packages/archive/HTTP/3001.0.4/doc/html/Network-Stream.html

It would be great to get HTTPS support going!

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


[Haskell-cafe] problem in using wash

2008-03-04 Thread Vikrant
Hi,
   I was trying to use wash to learn it. I am using ubuntu and I have
ghc6.6.1 installed on my system.
I have also installed the package libghc6-wash-dev

but in my code when i write

import WASH.CGI

it gives me following error

firstCGI.hs:5:7:
Could not find module `WASH.CGI':
  locations searched:
WASH/CGI.hs
WASH/CGI.lhs
Failed, modules loaded: none.



can somebody help me in this?

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


Re: [Haskell-cafe] Connection helpers: for people interested in network code

2008-03-04 Thread Adam Langley
On Tue, Mar 4, 2008 at 7:31 AM, Bjorn Bringert [EMAIL PROTECTED] wrote:
  you may want to have a look at the socket abstraction used in the HTTP 
 package:

  
 http://hackage.haskell.org/packages/archive/HTTP/3001.0.4/doc/html/Network-Stream.html

  It would be great to get HTTPS support going!

I should have mentioned that I had seen this in the original email. I
think the major problem with this interface was that it was written in
the time before ByteStrings. Now that we have ByteStrings I think that
it makes a lot of sense for networking to use them.

However, it shouldn't be too hard to wrap HsOpenSSL in this interface.
I might try this this week. Then HTTPS should Just Work (maybe ;)

AGL


-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Markup bug in HaskellWiki

2008-03-04 Thread Wolfgang Jeltsch
Am Dienstag, 4. März 2008 16:10 schrieb Dougal Stanton:
 […]

 There's a file called, IIRC, haskell.php with a large list of
 keywords. Two of them, 'unzip' and 'unzip3' appear twice. Delete one
 of each and it all works fine again.

Why do they appear at all?  They are not keywords.

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


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread Cale Gibbard
On 04/03/2008, Luke Palmer [EMAIL PROTECTED] wrote:
 On Tue, Mar 4, 2008 at 4:16 AM, Ketil Malde [EMAIL PROTECTED] wrote:
   Paul Johnson [EMAIL PROTECTED] writes:
  
 I'm surprised you found the significant whitespace difficult.
  
I wonder if this has something to do with the editor one uses?  I use
Emacs, and just keep hitting TAB, cycling through possible alignments,
until things align sensibly.  I haven't really tried, but I can
imagine lining things up manually would be more painful, especially
if mixing tabs and spaces.


 Especially if mixing tabs and spaces indeed.  Haskell does the Python
  thing of assuming that a tab is 8 spaces, which IMO is a mistake.  The
  sensible thing to do if you have a whitespace-sensitive language that
  accepts both spaces in tabs is to make them incomparable to each
  other; i.e.
snip

I honestly think that tab characters occurring anywhere but in a
comment should be considered a lexical error and rejected by the
compiler outright. More problems are caused by trying to continue with
only tabs, or some mixture of tabs and spaces than just getting one's
editor to expand tabs automatically.

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


Re: [Haskell-cafe] Annotating GHC assembler output?

2008-03-04 Thread Justin Bailey
On Mon, Mar 3, 2008 at 5:41 PM, Ben Lippmeier [EMAIL PROTECTED] wrote:
 Hi Justin.

  try:  ghc -c file -ddump-to-file -ddump-asm


Thanks, that does it. I also tried the -keep-s-files (possibly new to
6.8) and found it produces the same output.

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


Re: [Haskell-cafe] Markup bug in HaskellWiki

2008-03-04 Thread Henning Thielemann

On Tue, 4 Mar 2008, Wolfgang Jeltsch wrote:

 Am Dienstag, 4. März 2008 16:10 schrieb Dougal Stanton:
  […]

  There's a file called, IIRC, haskell.php with a large list of
  keywords. Two of them, 'unzip' and 'unzip3' appear twice. Delete one
  of each and it all works fine again.

 Why do they appear at all?  They are not keywords.

They link to the online Haddock documentation of Prelude.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Markup bug in HaskellWiki

2008-03-04 Thread Dougal Stanton
On 04/03/2008, Wolfgang Jeltsch [EMAIL PROTECTED] wrote:
 Am Dienstag, 4. März 2008 16:10 schrieb Dougal Stanton:
   […]


   There's a file called, IIRC, haskell.php with a large list of
   keywords. Two of them, 'unzip' and 'unzip3' appear twice. Delete one
   of each and it all works fine again.


 Why do they appear at all?  They are not keywords.

Well, keywords is a bit of a misnomer. Geshi isn't very smart, it just
recognises the standard prelude and adds in links to the online API.


D

-- 
Dougal Stanton
[EMAIL PROTECTED] // http://www.dougalstanton.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Edsko de Vries
Hi,

Is there an intuition that can be used to explain adjunctions to
functional programmers, even if the match isn't necessary 100% perfect
(like natural transformations and polymorphic functions?).

Thanks,

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


Re: [Haskell-cafe] (flawed?) benchmark : sort

2008-03-04 Thread Chaddaï Fouché
2008/3/4, Krzysztof Skrzętnicki [EMAIL PROTECTED]:
 Hi

 I was playing with various versions of sorting algorithms. I know it's very
 easy to create flawed benchmark and I don't claim those are good ones.
 However, it really seems strange to me, that sort - library function - is
 actually the worse measured function. I can hardly belive it, and I'd rather
 say I have made a mistake preparing it.

 The overall winner seems to be qsort_iv - which is nothing less but old sort
 replaced by mergesort now.

 Any clues?

Part of what you may be missing :
-- cut here --
module Main where

import Control.Parallel.Strategies
import Control.Arrow
import System.CPUTime
import System.IO
import System.Environment
import System.Random
import Data.List( partition, sort )

data Tree a =
Node (Tree a) a (Tree a)
| Leaf


qsort_i []  = []
qsort_i (x:xs) = qsort_i (filter ( x) xs) ++ [x] ++ qsort_i (filter (= x) xs)

qsort_ii [] = []
qsort_ii (x:xs) = let (ls,gt) = partition ( x) xs in qsort_ii ls ++
[x] ++ qsort_ii gt

qsort_iii xs = qsort_iii' [] xs
qsort_iii' acc [] = acc
qsort_iii' acc (x:xs) =
let (ls,gt) = partition ( x) xs in
let acc' = (x:(qsort_iii' acc gt)) in qsort_iii' acc' ls

qsort_v [] = []
qsort_v (x:xs) = let (xlt, xgt ) = foldl (\ (lt,gt) el - case compare x el of
GT - (el:lt, gt)
_  - (lt,
el:gt) ) ([],[]) xs
 in qsort_v xlt ++ [x] ++ qsort_v xgt

-- zmodyfikowany i
qsort_vi [] = []
qsort_vi (x:xs) = qsort_vi (filter (\y- compare x y == GT) xs) ++ [x]
++ qsort_vi (filter (\y- compare x y /= GT) xs)


-- zmodyfikowany iii
qsort_vii xs = qsort_vii' [] xs
qsort_vii' acc [] = acc
qsort_vii' acc (x:xs) =
let (ls,gt) = partition (\y- compare x y == GT) xs in
let acc' = (x:(qsort_vii' acc gt)) in qsort_vii' acc' ls



-- qsort is stable and does not concatenate.
qsort_iv xs = qsort_iv' (compare) xs []

qsort_iv' _   [] r = r
qsort_iv' _   [x]r = x:r
qsort_iv' cmp (x:xs) r = qpart cmp x xs [] [] r

-- qpart partitions and sorts the sublists
qpart cmp x [] rlt rge r =
-- rlt and rge are in reverse order and must be sorted with an
-- anti-stable sorting
rqsort_iv' cmp rlt (x:rqsort_iv' cmp rge r)
qpart cmp x (y:ys) rlt rge r =
case cmp x y of
GT - qpart cmp x ys (y:rlt) rge r
_  - qpart cmp x ys rlt (y:rge) r

-- rqsort is as qsort but anti-stable, i.e. reverses equal elements
rqsort_iv' _   [] r = r
rqsort_iv' _   [x]r = x:r
rqsort_iv' cmp (x:xs) r = rqpart cmp x xs [] [] r

rqpart cmp x [] rle rgt r =
qsort_iv' cmp rle (x:qsort_iv' cmp rgt r)
rqpart cmp x (y:ys) rle rgt r =
case cmp y x of
GT - rqpart cmp x ys rle (y:rgt) r
_  - rqpart cmp x ys (y:rle) rgt r


-- code by Orcus

-- Zadanie 9 - merge sort
mergeSort :: Ord a = [a] - [a]
mergeSort []= []
mergeSort [x]   = [x]
mergeSort xs= let(l, r) = splitAt (length xs `quot` 2) xs
  in mergeSortP (mergeSort l) (mergeSort r)

-- funkcja pomocnicza scalajÄ…ca dwie listy uporzÄ…dkowane w jednÄ…
mergeSortP :: Ord a = [a] - [a] - [a]
mergeSortP xs []= xs
mergeSortP [] ys= ys
mergeSortP (x:xs) (y:ys)
| x = y = x:(mergeSortP xs (y:ys))
| otherwise = y:(mergeSortP (x:xs) ys)

-- Zadanie 10 - tree sort
treeSort :: Ord a = [a] - [a]
-- pointless po raz drugi
treeSort = (treeSortInorder . treeSortToTree)

treeSortToTree :: Ord a = [a] - Tree a
treeSortToTree []   = Leaf
treeSortToTree (x:xs)   = let (xlt, xgt) = foldl (\ (lt,gt) el - case
compare x el of
GT - (el:lt, gt)
_  - (lt,
el:gt) ) ([],[]) xs
  in Node (treeSortToTree xlt) x (treeSortToTree xgt)

treeSortInorder :: Ord a = Tree a - [a]
treeSortInorder Leaf= []
treeSortInorder (Node l x r)= (treeSortInorder l) ++ [x] ++
(treeSortInorder r)

-- end code by Orcus

-- begin benchmark making code

makeBenchs benchs xs = do
  let (funcNames, funcs) = unzip benchs
  tBegin - getCPUTime
  timers - mapM (\f- print (f xs)  getCPUTime) funcs
  let times = zipWith (-) timers (tBegin:timers)
  sortedResults = sort $ zip times funcNames
  minT = fromIntegral $ fst $ head sortedResults
  scaled = map (((/minT) . fromIntegral) *** id) sortedResults
  hPutStr stderr $ unlines $ map show scaled

onRandom eltCnt = do
  gen - getStdGen
  let xs = take eltCnt (randomRs (1::Int, bigNum) gen) `using` rnf
  xs `seq` return xs

onSorted eltCnt = do
  gen - getStdGen
  let xs = take eltCnt (randomRs (1::Int, bigNum) gen) `using` rnf
  sxs = sort xs `using` rnf
  xs `seq` sxs `seq` return sxs

bigNum = 100 :: Int

-- end of benchmark making code

main = makeBenchs [(i,qsort_i),
   (ii,qsort_ii),
   (iii,qsort_iii),
   (iv,qsort_iv),
   

Re: [Haskell-cafe] (flawed?) benchmark : sort

2008-03-04 Thread Neil Mitchell
Hi

  -- Zadanie 9 - merge sort
  mergeSort :: Ord a = [a] - [a]
  mergeSort []= []
  mergeSort [x]   = [x]
  mergeSort xs= let(l, r) = splitAt (length xs `quot` 2) xs
   in mergeSortP (mergeSort l) (mergeSort r)

splitAt is not a particularly good way to split a list, since you
recurse over the list twice. Try instead:

split (x:xs) = (x:b,a)
where (a,b) = split xs
split [] = ([], [])

Perhaps adding some strictness annotations and turning the where into a case.

Also remember that a standard benchmark for sorting is an
ordered/reverse ordered list, as that causes quicksort to go to O(n^2)
given a bad pivot choice.

If the sort in the standard libraries can be improved on, it should be replaced.

Thanks

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


Re: [Haskell-cafe] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Derek Elkins
On Tue, 2008-03-04 at 17:16 +, Edsko de Vries wrote:
 Hi,
 
 Is there an intuition that can be used to explain adjunctions to
 functional programmers, even if the match isn't necessary 100% perfect
 (like natural transformations and polymorphic functions?).

Well when you pretend Hask is Set, many things can be discussed fairly
directly.

F is left adjoint to U, F -| U, if Hom(FA,B) is naturally isomorphic to
Hom(A,UB), natural in A and B.  A natural transformation over Set is
just a polymorphic function. So we have an adjunction if we have two
functions:

phi :: (F a - b) - (a - U b)
and
phiInv :: (a - U b) - (F a - b)

such that phi . phiInv = id and phiInv . phi = id and F and U are
instances of Functor.

The unit and counit respectively is then just phi id and phiInv id.

You can work several examples using this framework, though it gets
difficult when it is difficult to model other categories.

Also discussing and proving some properties of adjunctions (namely
continuity properties) would help.

Of course, this is a concrete example using basic ideas of programming
and not some intuitive analogy.  I feel comfortable working with
adjunctions, but I don't have some general analogy that I use.

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


Re: [Haskell-cafe] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Edsko de Vries
On Tue, Mar 04, 2008 at 11:58:38AM -0600, Derek Elkins wrote:
 On Tue, 2008-03-04 at 17:16 +, Edsko de Vries wrote:
  Hi,
  
  Is there an intuition that can be used to explain adjunctions to
  functional programmers, even if the match isn't necessary 100% perfect
  (like natural transformations and polymorphic functions?).
 
 Well when you pretend Hask is Set, many things can be discussed fairly
 directly.
 
 F is left adjoint to U, F -| U, if Hom(FA,B) is naturally isomorphic to
 Hom(A,UB), natural in A and B.  A natural transformation over Set is
 just a polymorphic function. So we have an adjunction if we have two
 functions:
 
 phi :: (F a - b) - (a - U b)
 and
 phiInv :: (a - U b) - (F a - b)
 
 such that phi . phiInv = id and phiInv . phi = id and F and U are
 instances of Functor.
 
 The unit and counit respectively is then just phi id and phiInv id.

Sure, but that doesn't really explain what an adjunction *is*. For me,
it helps to think of a natural transformation as a polymorphic function:
it gives me an intuition about what a natural transformation is.
Specializing the definition of an adjunction for Hask (or Set) helps
understanding the *definitions*, but not the *intention*, if that makes
any sense..

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


Re: [Haskell-cafe] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Miguel Mitrofanov
Well, we have at least one very useful example of adjunction. It's  
called curry. See, if X is some arbitrary type, you can define


type F = (,X)
instance Functor F where
fmap f (a,x) = (fa,x)
type G = (-) X
instance Functor G where
fmap f h = \x - f (h x)

Now, we have the adjunction:

phi :: ((a,X) - b) - (a - (X - b))
phi = curry
phiInv :: (a - (X - b)) - ((a,X) - b)
phiInv = uncurry

On 4 Mar 2008, at 21:30, Edsko de Vries wrote:


On Tue, Mar 04, 2008 at 11:58:38AM -0600, Derek Elkins wrote:

On Tue, 2008-03-04 at 17:16 +, Edsko de Vries wrote:

Hi,

Is there an intuition that can be used to explain adjunctions to
functional programmers, even if the match isn't necessary 100%  
perfect

(like natural transformations and polymorphic functions?).


Well when you pretend Hask is Set, many things can be discussed  
fairly

directly.

F is left adjoint to U, F -| U, if Hom(FA,B) is naturally  
isomorphic to

Hom(A,UB), natural in A and B.  A natural transformation over Set is
just a polymorphic function. So we have an adjunction if we have two
functions:

phi :: (F a - b) - (a - U b)
and
phiInv :: (a - U b) - (F a - b)

such that phi . phiInv = id and phiInv . phi = id and F and U are
instances of Functor.

The unit and counit respectively is then just phi id and phiInv id.


Sure, but that doesn't really explain what an adjunction *is*. For me,
it helps to think of a natural transformation as a polymorphic  
function:

it gives me an intuition about what a natural transformation is.
Specializing the definition of an adjunction for Hask (or Set) helps
understanding the *definitions*, but not the *intention*, if that  
makes

any sense..

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


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


[Haskell-cafe] Re: Functional programmer's intuition for adjunctions?

2008-03-04 Thread Dominic Steinitz
 Well, we have at least one very useful example of adjunction. It's  
 called curry. See, if X is some arbitrary type, you can define
 

This adjunction is the one that makes a category cartesian closed.

Dominic.

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


[Haskell-cafe] Haskell Perl architecture question

2008-03-04 Thread Marty Landman
I'm looking at a production system running Perl  Haskell in an 
Apache environment and trying to get a handle on the system 
architecture. Are there online resources anyone could recommend I start with?


Thanks in advance,
Marty


--
Marty Landman, Face 2 Interface Inc. 845-679-9387
Drupal Development Blog: http://drupal.face2interface.com/
Free Database Search App: http://face2interface.com/Products/FormATable.shtml

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


Re: [Haskell-cafe] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Dan Piponi
Edsko asked:

  Is there an intuition that can be used to explain adjunctions to
  functional programmers, even if the match isn't necessary 100% perfect
  (like natural transformations and polymorphic functions?).

I think there's a catch because many interesting examples of
adjunctions involve multiple distinct categories. So there's a sense
in which you have to go outside of programming to explain what they
are, apart from a few simple examples like currying. But if you're
familiar with the category of monoids and monoid homomorphisms, then
we can generate another example:

One intuition is the notion of trying to approximate an object in one
category using objects in another.

For example, consider the category of monoids. How best can we
approximate an arbitrary type in a monoid? Suppose our type, T, has
elements a,b and c. We could try to represent this as a monoid. But
monoids should have products and an identity. So if the monoid
contains a,b and c it should also contain 1, ab, bc, abcba and so on.
And what should ab equal? Might it be the same as bc? The simplest
strategy is to assume that all of these products are distinct and
approximate the type T with the monoid containing 1, a, b and c and
assuming no element equals any other unless the monoid laws say so
(ie. 1a=a1=a). This is called the *f*ree monoid generated by T, and we
can write it F(T).

Now go the other way: given a monoid, S, how can we map it back to a
type? There's an obvious idea, just make a type whose elements are the
*u*nderlying elements of the monoid, discarding the multiplication
rule. Call this U(S). (We're treating Hask like Set here.)

So what's U(F(T))? T gets mapped to the free monoid generated by T,
and mapped back to the elements of this monoid. In other words, the
elements of U(F(T)) are (possibly non-empty) strings of elements of T.
So UF is the list type constructor.

Any homomorphism, f, between monoids is completely determined once you
know where a set of generators of the monoid map under the
homomorphism, and vice versa. All of the other elements can be deduced
using f(1) = 1 and f(xy)=f(x)f(y). So if F(a) is the free monoid
generated by a, then a homomorphism F(a)-b is completely determined
by a function a-U(b), and vice versa. We have an isomorphism
(F(a)-b) - (a-U(b)) and (F,U) forms an adjunction, according to
Derek's definition.

So intuitively, what's going on is that Haskell lists emerge as a
result of an attempt to approximate types with monoids and adjunctions
formalise what we mean by 'approximation'. When we go from a type, to
a monoid, and back again, we don't end up where we started, but at a
new type.

Other adjunctions can be seen in this way. But because different
examples use different categories, it's hard to picture a uniform way
of viewing adjunctions that spans them all.

It's also no coincidence now that lists form a monad...
--
Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Doubting Haskell

2008-03-04 Thread hjgtuyl


About the line length needed for Haskell programs, there was a discussion
about this some time ago, that could be regarded as a tutorial for
reducing indentation:
   http://haskell.org/pipermail/haskell-cafe/2007-July/028787.html

As for the idle core you mention: I keep one core fully occupied with a
program that searches for a cure against cancer, see:
   http://www.computeagainstcancer.org/

The example you gave for the use of map can be simplified:
   map func (take (10 [0..]))  -- should actually be: map func (take 10
[0..])
-
   map func [0..9]

Regards,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--


On Tue, 04 Mar 2008 07:29:24 +0100, Alan Carter [EMAIL PROTECTED]
wrote:


Many thanks for the explanations when I was first experimenting with
Haskell. I managed to finish translating a C++ wxWidgets program into
Haskell wxHaskell, and am certainly impressed.

I've written up some reflections on my newbie experience together with
both versions, which might be helpful to people interested in
popularizing Haskell, at:

http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/

Regards,

Alan





--
--
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--

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


Re: [Haskell-cafe] Haskell Perl architecture question

2008-03-04 Thread Sterling Clover
Not quite sure what you're looking for? Do you mean that you're looking at
the possibility of setting such a system up, or that you're looking at a
system that is already set up and trying to grok how it works? If the
latter, you might want to get a sense of how ghc manages its packages and
dependencies at
http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html, which
also includes links to the information on the cabal infrastructure. If
that's not your question, then that material might either be too basic for
you or too offbase. The GHC manual is generally very well documented in
terms of describing package infrastructure, the linking process and the
runtime environment, etc.
If, rather, you're looking at issues more directly related to Haskell/web
stuff, you might want to specify what exactly you're looking to do, as there
are a number of solutions in use rather than a single, e.g., mod_haskell. If
it's an established system, then either it will be using a haskell webserver
(WASH, HAppS, etc) or it will be written using the CGI/FastCGI libraries. If
you're looking to set up a system, then of course it depends what you want
to do with it... for lightweight solutions, a combination of FastCGI and
HDBC seems to be pretty popular at the moment. In all these cases, note that
generally you'll be working with Haskell binaries, rather than scripts, and
that such binaries should either be built on the system in question
directly, or on one with the same architecture.
Hope that helps,
Sterl.

On Tue, Mar 4, 2008 at 2:06 PM, Marty Landman [EMAIL PROTECTED]
wrote:

 I'm looking at a production system running Perl  Haskell in an
 Apache environment and trying to get a handle on the system
 architecture. Are there online resources anyone could recommend I start
 with?

 Thanks in advance,
 Marty


 --
 Marty Landman, Face 2 Interface Inc. 845-679-9387
 Drupal Development Blog: http://drupal.face2interface.com/
 Free Database Search App:
 http://face2interface.com/Products/FormATable.shtml

 ___
 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] Doubting Haskell

2008-03-04 Thread Chaddaï Fouché
2008/3/4, Alan Carter [EMAIL PROTECTED]:
  I've written up some reflections on my newbie experience together with
  both versions, which might be helpful to people interested in
  popularizing Haskell, at:

  http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/

This is truly interesting, any learning experience is enlightening, we
truly do need to lower this barrier of admittance of which you speak.

On another subject, there are still point in your code that could be
clearer or done with less  cruft :

maxOfHistogram stats = snd (foldl (\(cA, vA) (cB, vB) - if (vA  vB)
then (cA, vA)
else (cB, vB))
  (0, 0)
  stats)

can become :

maxofHistogram stats = foldl' max 0 (map snd stats)

(foldl' max 0 could be replaced by maximum but there wouldn't be a
default 0 anymore)

more importantly, you can replace this kind of code :
  vA - varCreate []
  vB - varCreate []
  -- ...
  vL - varCreate []
  vM - varCreate []
  vN - varCreate []
  vO - varCreate []

by :
  [vA, vB, vC, vD, vE, vF, vG, vH, vI, vJ, vK, vL, vM, vN, vO] -
replicateM 15 (varCreate [])

(true also for the dA - textEntry statusFrame [text := 0,
alignment := AlignRight] sequence)

I'm not sure that functions like getdTotal couldn't be improved, I
wonder if a small Map for the elements of d wouldn't make the code
much better and offer other opportunities for abstractions. As it is,
enumeration like :

 [[label Total Entries,   widget (getdTotal d)]
 ,[label Valid Entries,   widget (getdValid d)]
 -- ...
 ,[label MDMA,widget (getdMdma d)]
 ,[label Caffeine,widget (getdCaffeine d)]]

could be slightly reduced by :
let bindLabelAndWidget (lbl,getter) = [label lbl, widget (getter d)]
in map bindLabelAndWidget [(Total Entries, getdTotal), (Valid
Entries, getdValid)
  ,(...)]

And little thing like :
mapM_ (\f - do repaint f) knownFrames
becoming :
mapM_ repaint knownFrames


I also do concur that a flag or a warning to signal mixed tabulations
and space would be a _very_ good idea !

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


Re: [Haskell-cafe] (flawed?) benchmark : sort

2008-03-04 Thread Krzysztof Skrzętnicki
Thanks for improved code. My point was to measure which programming patterns
are faster than the others so I can learn which ones I should use. However,
the thing that is really bad is the fact, that even oneliner qsort_i is
faster than library sort. Which is very different from what I've expected.
My intuition is only best and fastest code goes to library, to the point
that people can learn from it. It seems I was mislead.


 It could probably be improved (with classics solution (better
 selection of the pivot...)), but the mergesort is only 3 times slower
 in worse case, and much more regular, if someone needs a faster sort
 in a specific case, it isn't hard to code.

 --
 Jedaï

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


Re: [Haskell-cafe] (flawed?) benchmark : sort

2008-03-04 Thread Chaddaï Fouché
2008/3/4, Krzysztof Skrzętnicki [EMAIL PROTECTED]:
 Thanks for improved code. My point was to measure which programming patterns
 are faster than the others so I can learn which ones I should use. However,
 the thing that is really bad is the fact, that even oneliner qsort_i is
 faster than library sort. Which is very different from what I've expected.
 My intuition is only best and fastest code goes to library, to the point
 that people can learn from it. It seems I was mislead.

I think you did not correctly got the point of my and Neil Mitchell's
message : you benchmarked those function on a completely random
sequences so qsort was at his best, but in the real world, most
sequences would have bias, and it is not infrequent at all to sort a
partially sorted (or reverse sorted) list... In this case the
performance of all your qsort are abysmal... Which is the reason the
old sort was replaced by the actual mergesort in the library. Try my
code (with 1 elements for example), you'll see that sort is the
best on a sorted list, and that qsort is at least 60 times slower (on
1, in fact it is degenerating in O(n^2)).

In the real world, the library maintainers decided it was ok to pay a
slight overhead in the case where the list to sort is really randomly
distributed since mergesort won so hugely over qsort in the pretty
frequent case (in programs) of lists which present regularities.

There is no sort which is ideal in all situations, but we can try to
get a sort that works well in all situations, and don't trash in
situations not so infrequent.

(On the other hand, don't expect libraries functions to always be the
best to use in your particular situation, they tend to be all-purpose
as we just saw and the maintainers prefer simple generic
implementations rather than complicated ones who could be slightly (or
even significantly) faster in some case)

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


[Haskell-cafe] Re: problem in using wash

2008-03-04 Thread Ferenc Wagner
Vikrant [EMAIL PROTECTED] writes:

 I was trying to use wash to learn it. I am using ubuntu and I have ghc6.6.1
 installed on my system.
 I have also installed the package libghc6-wash-dev

 but in my code when i write

 import WASH.CGI

 it gives me following error

 firstCGI.hs:5:7:
 Could not find module `WASH.CGI':
   locations searched:
 WASH/CGI.hs
 WASH/CGI.lhs
 Failed, modules loaded: none.



 can somebody help me in this?

Check with 'ghc-pkg list' if the package is present, then use
'ghc-pkg describe WashNGo' to get the exported module names.  Also
don't forget to use --make when compiling (or explicit package name).
-- 
Regards,
Feri.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] (flawed?) benchmark : sort

2008-03-04 Thread Krzysztof Skrzętnicki
I get it now, thanks. Also, I guess it is possible to find a better
algorithm for standard library sort.

Christopher Skrzętnicki

On Wed, Mar 5, 2008 at 12:04 AM, Chaddaï Fouché [EMAIL PROTECTED]
wrote:

 2008/3/4, Krzysztof Skrzętnicki [EMAIL PROTECTED]:
  Thanks for improved code. My point was to measure which programming
 patterns
  are faster than the others so I can learn which ones I should use.
 However,
  the thing that is really bad is the fact, that even oneliner qsort_i is
  faster than library sort. Which is very different from what I've
 expected.
  My intuition is only best and fastest code goes to library, to the point
  that people can learn from it. It seems I was mislead.

 I think you did not correctly got the point of my and Neil Mitchell's
 message : you benchmarked those function on a completely random
 sequences so qsort was at his best, but in the real world, most
 sequences would have bias, and it is not infrequent at all to sort a
 partially sorted (or reverse sorted) list... In this case the
 performance of all your qsort are abysmal... Which is the reason the
 old sort was replaced by the actual mergesort in the library. Try my
 code (with 1 elements for example), you'll see that sort is the
 best on a sorted list, and that qsort is at least 60 times slower (on
 1, in fact it is degenerating in O(n^2)).

 In the real world, the library maintainers decided it was ok to pay a
 slight overhead in the case where the list to sort is really randomly
 distributed since mergesort won so hugely over qsort in the pretty
 frequent case (in programs) of lists which present regularities.

 There is no sort which is ideal in all situations, but we can try to
 get a sort that works well in all situations, and don't trash in
 situations not so infrequent.

 (On the other hand, don't expect libraries functions to always be the
 best to use in your particular situation, they tend to be all-purpose
 as we just saw and the maintainers prefer simple generic
 implementations rather than complicated ones who could be slightly (or
 even significantly) faster in some case)

 --
 Jedaï

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


Re: [Haskell-cafe] Re: Functional programmer's intuition for adjunctions?

2008-03-04 Thread Derek Elkins
On Tue, 2008-03-04 at 19:01 +, Dominic Steinitz wrote:
  Well, we have at least one very useful example of adjunction. It's  
  called curry. See, if X is some arbitrary type, you can define
  
 
 This adjunction is the one that makes a category cartesian closed.

and the monad for it gives rise to the state monad.

And the other adjunction relating to exponentials and symmetry gives
rise to the continuation monad.

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


[Haskell-cafe] Re: [Yhc] Yhc Web Service quietly opened for public testing

2008-03-04 Thread Thomas Hartman
That is seriously cool.

Congratulations Dmitry!

thomas.

2008/3/4, Dimitry Golubovsky [EMAIL PROTECTED]:
 Hi,

  I finally got the Yhc Web Service (web-based front end to the
  compiler) running in public testing mode. There hasn't been any
  documentation written, and Haddock stuff not brought in order, but if
  anyone wants to just get a taste of it, please open this hpaste entry:

  http://hpaste.org/6094

  and follow the instructions.

  In 10 steps, you'll get Haskell to work in your web browser* ;) No
  need to install anything.

  Feel free to edit the source code, and even deliberately make errors
  to see how error log looks. At the moment, I do not run automatic
  cleanup of failed compilations.

  This is one of my old tests, not showing any GUI interaction. However,
  both documents browser and new entry form were written in Haskell
  which gives some idea about what can be done. Sources of these forms
  are in the Yhc repo.

  Thanks.

  ---
  * Likely, your results will be better with Firefox than with MSIE. But
  MSIE should work as well.


  --
  Dimitry Golubovsky

  Anywhere on the Web
  ___
  Yhc mailing list
  [EMAIL PROTECTED]
  http://www.haskell.org/mailman/listinfo/yhc

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


Re: [Haskell-cafe] Re: Functional programmer's intuition for adjunctions?

2008-03-04 Thread Miguel Mitrofanov
Well, I think it's really cool to be sitting in cafe exchanging some  
сute facts from category theory we happen to know. Girls would  
definitely like it.


On 5 Mar 2008, at 03:33, Derek Elkins wrote:


On Tue, 2008-03-04 at 19:01 +, Dominic Steinitz wrote:

Well, we have at least one very useful example of adjunction. It's
called curry. See, if X is some arbitrary type, you can define



This adjunction is the one that makes a category cartesian closed.


and the monad for it gives rise to the state monad.

And the other adjunction relating to exponentials and symmetry gives
rise to the continuation monad.

___
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] Functional programmer's intuition for adjunctions?

2008-03-04 Thread Derek Elkins
On Tue, 2008-03-04 at 18:30 +, Edsko de Vries wrote:
 On Tue, Mar 04, 2008 at 11:58:38AM -0600, Derek Elkins wrote:
  On Tue, 2008-03-04 at 17:16 +, Edsko de Vries wrote:
   Hi,
   
   Is there an intuition that can be used to explain adjunctions to
   functional programmers, even if the match isn't necessary 100% perfect
   (like natural transformations and polymorphic functions?).
  
  Well when you pretend Hask is Set, many things can be discussed fairly
  directly.
  
  F is left adjoint to U, F -| U, if Hom(FA,B) is naturally isomorphic to
  Hom(A,UB), natural in A and B.  A natural transformation over Set is
  just a polymorphic function. So we have an adjunction if we have two
  functions:
  
  phi :: (F a - b) - (a - U b)
  and
  phiInv :: (a - U b) - (F a - b)
  
  such that phi . phiInv = id and phiInv . phi = id and F and U are
  instances of Functor.
  
  The unit and counit respectively is then just phi id and phiInv id.
 
 Sure, but that doesn't really explain what an adjunction *is*. For me,
 it helps to think of a natural transformation as a polymorphic function:
 it gives me an intuition about what a natural transformation is.
 Specializing the definition of an adjunction for Hask (or Set) helps
 understanding the *definitions*, but not the *intention*, if that makes
 any sense..

I explicitly mentioned this at the end of my first email:


Of course, this is a concrete example using basic ideas of programming
and not some intuitive analogy.  I feel comfortable working with
adjunctions, but I don't have some general analogy that I use.


I'm suggesting that trying to find such an analogy may be more trouble
than it is worth.   The best analogy I've heard is to relate the problem
of finding an adjunction to optimization problems.  Personally, I find
representability to be simpler, more useful, and easier to get an
intuition about.  Adjunction is then a particular case of parameterized
representability.

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


[Haskell-cafe] Re: Exporting Haskell Libraries to C Programmers

2008-03-04 Thread Bruce, Joseph R (Joe)
Don Stewart dons at galois.com writes:

 
 joseph.bruce:
  Hi,
  
  I have a Haskell library that I want to make available via FFI to C
  programmers on my project team.  I read this thread
  (http://thread.gmane.org/gmane.comp.lang.haskell.cafe/21447) which had
  some interesting ideas, but they seemed unresolved.  Or maybe it answers
  my question but I don't understand it.
  
  Is there a way I can package (ghc-)compiled Haskell code into a
  statically-linked library and not force the C programmers to include
  headers and libraries that they have no knowledge of and undefine a
  seemingly endless list of preprocessor symbols (run ghc with the verbose
  flag and look at the calls to gcc)?  Can this process be automated?
 
 Yes, check the FFI documentation for the main story. 
 
 In short, build the Haskell code with cabal, with your foreign export
 Haskell functions in the cbits. That bundle can then be linked against
 C code.
 
 You do need to link your app against libHSrts.a and libHSbase.a (and
 other libs you use), but assuming you foreign export, the code 
 to call will look just like normal C stuff.
 

Thanks Don.  I finally got back to this.

I hadn't looked at CABAL before.  It's a very useful tool and met all my 
library-forming needs.
That's only half my problem though.  I'm trying to make the use of this Haskell 
code as transparent as possible to the C programmers on the team.  Telling them 
about the Haskell base libraries dependency or distributing those libraries 
with my code is not too bad, but the list of -u flags that the linker needs is 
brutal.  Is there a way to avoid it, or embed it in the package?

Ex (using ghc-6.8.2 -v):
...
gcc -v -o primes Primes.o ./Primes_stub.o hs_primes_wrapper.o cprimes.c 
-Bc:\ghc\ghc-6.8.2\gcc-lib/ -DDONT_WANT_WIN32_DLL_SUPPORT 
-Lc:/ghc/ghc-6.8.2/lib\base-3.0.1.0 -Lc:/ghc/ghc-6.8.2 
-Lc:/ghc/ghc-6.8.2/gcc-lib -lHSbase-3.0.1.0 -lwsock32 -lmsvcrt -lkernel32 
-luser32 -lshell32 -lHSrts -lm -lgmp -lwsock32 -u 
_base_GHCziBase_Izh_static_info -u _base_GHCziBase_Czh_static_info -u 
_base_GHCziFloat_Fzh_static_info -u _base_GHCziFloat_Dzh_static_info -u 
_base_GHCziPtr_Ptr_static_info -u _base_GHCziWord_Wzh_static_info -u 
_base_GHCziInt_I8zh_static_info -u _base_GHCziInt_I16zh_static_info -u 
_base_GHCziInt_I32zh_static_info -u _base_GHCziInt_I64zh_static_info -u 
_base_GHCziWord_W8zh_static_info -u _base_GHCziWord_W16zh_static_info -u 
_base_GHCziWord_W32zh_static_info -u _base_GHCziWord_W64zh_static_info -u 
_base_GHCziStable_StablePtr_static_info -u _base_GHCziBase_Izh_con_info -u 
_base_GHCziBase_Czh_con_info -u _base_GHCziFloat_Fzh_con_info -u 
_base_GHCziFloat_Dzh_con_info -u _base_GHCziPtr_Ptr_con_info -u 
_base_GHCziPtr_FunPtr_con_info -u _base_GHCziStable_StablePtr_con_info -u 
_base_GHCziBase_False_closure -u _base_GHCziBase_True_closure -u 
_base_GHCziPack_unpackCString_closure -u 
_base_GHCziIOBase_stackOverflow_closure -u 
_base_GHCziIOBase_heapOverflow_closure -u 
_base_GHCziIOBase_NonTermination_closure -u 
_base_GHCziIOBase_BlockedOnDeadMVar_closure -u 
_base_GHCziIOBase_BlockedIndefinitely_closure -u 
_base_GHCziIOBase_Deadlock_closure -u 
_base_GHCziIOBase_NestedAtomically_closure -u 
_base_GHCziWeak_runFinalizzerBatch_closure -u 
_base_GHCziConc_ensureIOManagerIsRunning_closure
...

This particular example is a build on a windows system and makes use of the 
.o's directly and not the .a I create, but those are of no consequence as this 
is ultimately a linking issue, not a compilation issue.  I don't know what 
these -u's are for, but I know that if I take them out, the linker fails.  They 
do change from one system to another (this list fails with the linker on RHEL 
5).  But right now my solution for the C programmers is a make file with 
$haskell_undefine_flags = that mess up there, and I'd prefer something more 
elegant and less system dependent.  I am willing to accept that there is no 
good way around it, but perhaps someone has dealt with this issue before.

Any help?  Thanks.

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


[Haskell-cafe] Re: problem in using wash

2008-03-04 Thread Vikrant
Thanks for the information. Now I could find mistake in what I was
importing.
'ghc-pkg describe WashNGo' told me correct exported module names.


On 05/03/2008, Ferenc Wagner [EMAIL PROTECTED] wrote:

 Vikrant [EMAIL PROTECTED] writes:

  I was trying to use wash to learn it. I am using ubuntu and I have
 ghc6.6.1
  installed on my system.
  I have also installed the package libghc6-wash-dev
 
  but in my code when i write
 
  import WASH.CGI
 
  it gives me following error
 
  firstCGI.hs:5:7:
  Could not find module `WASH.CGI':
locations searched:
  WASH/CGI.hs
  WASH/CGI.lhs
  Failed, modules loaded: none.
 
 
 
  can somebody help me in this?


 Check with 'ghc-pkg list' if the package is present, then use
 'ghc-pkg describe WashNGo' to get the exported module names.  Also
 don't forget to use --make when compiling (or explicit package name).

 --
 Regards,
 Feri.

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