[Haskell-cafe] Re: quoting in Haskell

2007-08-28 Thread apfelmus

Peter Verswyvelen wrote:
In Scheme, on can quote code, so that it becomes data. Microsoft's F# 
and C# 3.0 also have something similar that turns code into expression 
trees.


I can't find something similar for Haskell? Maybe I am looking at the 
wrong places?


Quoting/Inspecting code at runtime is not possible in Haskell since this 
would break referential transparency, i.e. one could tell that two 
extensionally equal values like


  3 `add` 4
  1 `add` (2 `mul` 3)

are different by inspecting their internal structure.

Of course, you can use constructors for  add  and  mul  and then inspect 
and transform the result


  data Expr = Val Int | Add Expr Expr | Mul Expr Expr

  add, mul :: Expr - Expr - Expr
  add = Add
  mul = Mul

  x :: Expr
  x = Val 1 `add` (Val 2 `mul` Val 3)

By making  Expr  an instance of the class  Num , you can use overloaded 
arithmetic operations


  instance Num Expr where
(+) = Add
(*) = Mul
fromInteger = Val . fromInteger

  x :: Expr
  x = 1 + 2*3



I want to write something like

selectiveQuote [add] (1 `add` 2 `mul` 3)

which would result in an expression tree like

  add
 /  \
16

So the `mul` is not quoted because it is not part of the context = [add]


I'm not sure why you'd want to do that, but it's not well-defined. What 
would


 selectiveQuote [add] ((1 `add` 2) `mul` 3)

be? How to expand `mul` here when `add` isn't expanded?


Regards,
apfelmus

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


[Haskell-cafe] Re: [ANN] An efficient lazy suffix tree library

2007-08-28 Thread Gleb Alexeyev

Bryan O'Sullivan wrote:

ChrisK wrote:

That is almost certainly because the algorithm expects the source 
string to have

a unique character at its end.


Chris is correct.  I'll ensure that the docs make this clear.


Apologies, I should have thought of this myself.

Thanks.

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


[Haskell-cafe] GHC 6.6.1 and SELinux issues

2007-08-28 Thread Alexander Vodomerov
  Hello!

Does anybody here uses GHC on Linux with SELinux turned on?

I've just installed SELinux and run into GHC/SELinux incompatibility.
It seems that the similar problem was reported some time ago and was fixed in
6.4.3. However, I use 6.6.1 and the problem is still here.

$ ghc
ghc-6.6.1: internal error: getMBlock: mmap: Permission denied
(GHC version 6.6.1 for i386_unknown_linux)
Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Exactly the same bug is appearing on x86_64 architecture.

Much more details is available at http://hackage.haskell.org/trac/ghc/ticket/738

Any ideas?

With best regards,
   Alexander.

PS. Is it possible to turn on global allow_execmem boolean in SELinux policy,
thus enabling executable memory mapping. This solves the problem. However, this
is major drawback for system security and should be avoided at any cost.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] [Off Topic Amusement] Lylle Lovett lyrics

2007-08-28 Thread David Pollak
http://www.lyricsdepot.com/lyle-lovett/west-texas-highway.html


-- 
lift, the fast, powerful, easy web framework
http://liftweb.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Wildly off-topic

2007-08-28 Thread Andrew Coppin

http://importantshock.wordpress.com/2007/08/21/haskell-curry-yes-i-dated-his-daughter/

(Actually, you hardly need to click that. The URL says it all...)

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


Re: [Haskell-cafe] GHC 6.6.1 and SELinux issues

2007-08-28 Thread Alexander Vodomerov
On Tue, Aug 28, 2007 at 08:05:02AM -0600, Stuart Jansen wrote:
 I'm using it on Fedora 7 without any problems.

 $ ls -Z $(which ghc)
 lrwxrwxrwx  root root system_u:object_r:bin_t  /usr/bin/ghc -
 ghc-6.6.1*
 $ ls -Z $(which ghci)
 lrwxrwxrwx  root root system_u:object_r:bin_t  /usr/bin/ghci -
 ghci-6.6.1*

In what domain do you run GHC? The commands about just show that
/usr/bin/ghc has the bin_t type, however it is just a symlink or shell
wrapper. Real GHC executable may have another permission.

See for example (taken from my Debian box):

$ ls -Z `which ghc`
lrwxrwxrwx  root root system_u:object_r:bin_t:s0   /usr/bin/ghc -
/etc/alternatives/ghc
$ ls -Z /usr/lib/ghc-6.6.1/bin/ghc-6.6.1
-rwxr-xr-x  root root system_u:object_r:bin_t:s0
/usr/lib/ghc-6.6.1/bin/ghc-6.6.1
$ file /usr/lib/ghc-6.6.1/bin/ghc-6.6.1
/usr/lib/ghc-6.6.1/bin/ghc-6.6.1: POSIX shell script text executable
$ cat /usr/lib/ghc-6.6.1/bin/ghc-6.6.1
#!/bin/sh
GHCBIN=/usr/lib/ghc-6.6.1/ghc-6.6.1;
TOPDIROPT=-B/usr/lib/ghc-6.6.1;
# Mini-driver for GHC
exec $GHCBIN $TOPDIROPT ${1+$@}
$ file /usr/lib/ghc-6.6.1/ghc-6.6.1
/usr/lib/ghc-6.6.1/ghc-6.6.1: ELF 32-bit LSB executable, Intel 80386,
version 1 (SYSV), for GNU/Linux 2.6.1, dynamically linked (uses shared
libs), stripped
$ ls -Z /usr/lib/ghc-6.6.1/ghc-6.6.1
-rwxr-xr-x  root root system_u:object_r:lib_t:s0
/usr/lib/ghc-6.6.1/ghc-6.6.1

In this case the real domain for ghc is lib_t, not bin_t.

With best regards,
   Alexander.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Searching for a subsequence in Data.Sequence structure?

2007-08-28 Thread Justin Bailey
Does anyone have code for finding a subsequence within a
Data.Sequence.Seq value, or is there a way to do it with the already
defined instances that I am missing? A quick search didn't turn up
much. Thanks in advance!

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


Re: [Haskell-cafe] Ideas

2007-08-28 Thread Joachim Breitner
Hi,

Am Samstag, den 25.08.2007, 12:50 +0100 schrieb Andrew Coppin:
 How easy would it be to make / would anybody care / has somebody already 
 made ... in Haskell?
 
 - A wiki program. (Ditto.)

I wrote a wiki in haskell, but it focuses on full-sized LaTeX-Documents,
so the “regular” wiki party is rather limited. But of course it can be
extended... (It’s based on subversion, and the small CGI-part is written
in python).

Wiki (self-hosting): http://latexki.nomeata.de/
Application: http://mitschriebwiki.nomeata.de/

Greetings,
Joachim
-- 
Joachim nomeata Breitner
  mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C
  JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/
  Debian Developer: [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] runInteractiveCommand behaves differently on linux and windows

2007-08-28 Thread Thomas Hartman
Maybe this is by design, but I just thought I would point this behavior 
out and ask for comment.

test1 merely shows that runInteractiveCommand reacts differently to perl 
warnings than perl errors. Okay, maybe the inconsistency in that case is 
due to perl and not haskell.

test2 behaves the same on win and nix. This is pipe like in that the 
ouptut of a command (which could be the result of a shell call, but just 
as easily be the return of a haskell function) gets fed into a shell 
command. In this case, if the shell command is simply tail the behavior 
is consistent from win to nix.

test3 shows that the behavior stops being consistent if ssh enters the 
picture. (piping to tail via ssh). again, maybe this is due to ssh and not 
haskell.

however... note however that on windows

ghc -e 'mapM_ ( putStrLn . show ) [1..1000] ' | ssh [EMAIL PROTECTED] 
'tail -n2'

works fine.  so it's not *just* ssh, but ssh in conjuction with 
runInteractiveCommand which seems to cause problems

FWIW, using 10 lines instead of 1000 still hangs on windows.

Is there a way to code up shell pipelike behavior in a more portable way?

curious what the cafe thinks...

thomas.

import Test.HUnit
import Misc ( (=^) )
import System.Process
import System.IO
import System.Exit

-- works on linux, error on windows

test1 = do 
  res1 - test_shellrunStderrOk
  runTestTT $ TestCase ( assertEqual test1 made it  res1 )
  where test_shellrunStderrOk = do
  runprocessStdErrAllowed'  cmdPerlwarn
  return made it
cmdPerldie =   perl -e 'die \error\' 
cmdPerlwarn =  perl -e 'warn \blee\' 

-- works on linux, windows
test2 = pipeTo tail -n2

-- works on linux, hangs on windows
test3 = pipeTo ssh [EMAIL PROTECTED] 'tail -n2'

pipeTo cmd = do
  res2 - test_shellrunPipeinLike
  runTestTT $ TestCase ( assertEqual ( pipe to, cmd:  ++ cmd) (show l) 
res2 )
  where test_shellrunPipeinLike = do
  runprocessStdErrAllowed' (unlines $ map show [1..l]) ( cmd )
  =^ filter (not . ( == '\n') )
l = 1000

runprocessStdErrAllowed' inp s = do
(ih,oh,eh,pid) - runInteractiveCommand s
so - hGetContents oh
se - hGetContents eh
hPutStrLn ih inp
hClose ih
ex - waitForProcess pid
case ex of
ExitFailure e  - fail $ shell command  ++ s ++ \nFailed 
with status:  ++ show e
_   | otherwise - return so



---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal install of HDBC-odbc fails on ghc 6.7, -I flag causes problems

2007-08-28 Thread Thomas Hartman
Well, I built with -v3 as suggested, but the ouptut doesn't seem that 
helpful to me. ghc compile commands, at any rate, do not appear to be 
outputted


$ echo :main build | /usr/local/bin/ghci-6.7.20070816 -v3 Setup.hs 
1build.out 2build.err

build.out: 

GHCi, version 6.7.20070816: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Ok, modules loaded: Main.
*Main Loading package array-0.1 ... linking ... done.
Loading package containers-0.1 ... linking ... done.
Loading package old-locale-1.0 ... linking ... done.
Loading package old-time-1.0 ... linking ... done.
Loading package filepath-1.0 ... linking ... done.
Loading package directory-1.0 ... linking ... done.
Loading package unix-2.0 ... linking ... done.
Loading package process-1.0 ... linking ... done.
Loading package pretty-1.0 ... linking ... done.
Loading package Cabal-1.1.7 ... linking ... done.
Reading parameters from 
/home/hartthoma/installs/HDBC-odbc-1.0.1.0/HDBC-odbc.buildinfo
Preprocessing library HDBC-odbc-1.0.1.0...
*** Exception: exit: ExitFailure 1
*Main Leaving GHCi.

build.err: 

Glasgow Haskell Compiler, Version 6.7.20070816, for Haskell 98, stage 2 
booted by GHC version 6.6.1
Using package config file: /usr/local/lib/ghc-6.7.20070816/package.conf
hiding package regex-base-0.72 to avoid conflict with later version 
regex-base-0.91
hiding package HDBC-1.0.1 to avoid conflict with later version HDBC-1.1.2
wired-in package base mapped to base-2.1
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0
wired-in package template-haskell mapped to template-haskell-0.1
wired-in package ndp not found.
Hsc static flags: -static
*** Parser:
*** Desugar:
*** Simplify:
*** CorePrep:
*** ByteCodeGen:
*** Parser:
*** Desugar:
*** Simplify:
*** CorePrep:
*** ByteCodeGen:
*** Parser:
*** Desugar:
*** Simplify:
*** CorePrep:
*** ByteCodeGen:
*** Chasing dependencies:
Chasing modules from: 
Stable obj: []
Stable BCO: []
unload: retaining objs []
unload: retaining bcos []
Ready for upsweep []
Upsweep completely successful.
*** Deleting temp files:
Deleting: 
*** Chasing dependencies:
Chasing modules from: Setup.hs
Stable obj: []
Stable BCO: []
unload: retaining objs []
unload: retaining bcos []
Ready for upsweep
  [NONREC
  ModSummary {
 ms_hs_date = Mon Aug 20 09:49:47 EDT 2007
 ms_mod = main:Main,
 ms_imps = [System.Exit, Distribution.PackageDescription,
Distribution.Simple.Utils, Data.List, System.Info,
Distribution.Simple]
 ms_srcimps = []
  }]
compile: input file Setup.hs
*** Checking old interface for main:Main:
[1 of 1] Compiling Main ( Setup.hs, interpreted )
*** Parser:
*** Renamer/typechecker:
*** Desugar:
Result size = 435
*** Simplify:
Result size = 464
Result size = 437
*** Tidy Core:
Result size = 437
*** CorePrep:
Result size = 491
*** ByteCodeGen:
*** Deleting temp files:
Deleting: 
Upsweep completely successful.
*** Deleting temp files:
Deleting: 
*** Parser:
*** Desugar:
*** Simplify:
*** CorePrep:
*** ByteCodeGen:
ghc-6.6.1: unrecognised flags: -I
Usage: For basic information, try the `--help' option.
compiling dist/build/Database/HDBC/ODBC/Connection_hsc_make.c failed
command was: ghc -c -I dist/build/Database/HDBC/ODBC/Connection_hsc_make.c 
-o dist/build/Database/HDBC/ODBC/Connection_hsc_make.o
*** Deleting temp files:
Deleting: 
*** Deleting temp dirs:
Deleting: 








Duncan Coutts [EMAIL PROTECTED] 
08/22/2007 04:53 PM

To
Thomas Hartman/ext/[EMAIL PROTECTED]
cc
haskell-cafe@haskell.org
Subject
Re: [Haskell-cafe] cabal install of HDBC-odbc fails on ghc 6.7, -I flag 
causes problems






On Mon, 2007-08-20 at 13:10 -0400, Thomas Hartman wrote:
 
 problemw with the -I flag to ghc are causing cabal install to fail for
 hdbc-odbc (darcs head). 

 Any tips on debugging this cabal install would be appreciated. 

 $ runghc Setup.hs configure; runghc Setup.hs build 

Try with -v3 is:

runghc Setup.hs build -v3

this will give extremely verbose output. We'd like to see the last bit
to see what ghc command line exactly is failing. It'll show the command
line arguments in Haskell show format eg [-I, /]

Duncan





---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal install of HDBC-odbc fails on ghc 6.7, -I flag causes problems

2007-08-28 Thread Duncan Coutts
On Tue, 2007-08-28 at 18:19 -0400, Thomas Hartman wrote:
 
 Well, I built with -v3 as suggested, but the ouptut doesn't seem that
 helpful to me. ghc compile commands, at any rate, do not appear to be
 outputted 

Sorry, I meant to pass -v3 to cabal, not to ghc compiling/running
Setup.hs

 $ echo :main build | /usr/local/bin/ghci-6.7.20070816 -v3 Setup.hs
 1build.out 2build.err 

like:

runghc Setup.hs build -v3


Duncan

___
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-28 Thread Donald Bruce Stewart
chaddai.fouche:
 For the translation of the above OCaml code, there is not much to do,
 in fact it is mostly functional, and so easily translated in Haskell
 code, note that I add a code to handle input of the form
 4.8.5.3..7..2.6.8.4..1...6.3.7.5..2.1.4..,
 to resolve it and print a solution :

Spencer Janssen also wrote a rather elegant translation, which you can
find on hpaste.org

import Data.List
import Data.Ord

n = 3 :: Int

invalid (i, j) (i', j') = i == i' || j == j' ||
  i `div` n == i' `div` n  j `div` n == j' `div` n

select p n p' ns | invalid p p' = filter (/= n) ns
 | otherwise= ns
  
add p n sols = sortBy (comparing (length . snd)) $ map f sols
  where f (p', ns) = (p', select p n p' ns)

search [] = [[]]
search ((p, ns):sols) = [(p, n):ss | n - ns, ss - search $ add p n sols]

You can see the development here,

http://hpaste.org/2348  

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


[Haskell-cafe] Serial Communications in Haskell

2007-08-28 Thread Ronald Guida

I'm on a Windows box and I'm looking for a way to talk to a serial
port (for example, RS-232) from Haskell.  I couldn't find a library to
do this, so I am wondering how to create one.

I have a fairly thorough understanding of how to open and use a serial
port with the Windows API.  In particular, to open a serial port, I
have to use CreateFile, which is the same API call that opens files.
In fact, if I call openFile from GHC, and pass COM1: as the
filename, then I can get a writable serial port.

 module Serial
 where
 import System.IO

 main = do
   h - openFile COM1: ReadWriteMode
   hPutStrLn h Hello World

I can't read from the port (I always get an immediate EOF), and I have
no way of configuring things like the baud rate or the parity
settings.  Nevertheless, this demonstrates that openFile can at least
open the serial port.

What I would like to do is create some functions that would allow me
to open and configure a serial port, and get a Handle back so that I
can use the existing IO functions like hGetChar and hPutChar.  I am
assuming that hGetChar eventually calls win32::ReadFile and hPutChar
eventually calls win32::WriteFile.  These same two API calls would
work for serial ports.

In Windows, there are 23 API functions that apply specifically to
serial ports.  Out of these 23 functions, only a few of them are
actually necessary if I just want to send and receive data.

Of course, I don't know how to call Windows API functions from Haskell,
and I have no idea how to hook things to the IO library so that I can
use a Handle for a serial port.  I'm looking for some advice on how to
proceed.

-- Ron

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