Re: [Haskell-cafe] Use of uninstantiated type class

2011-03-05 Thread Maciej Marcin Piechotka
On Sat, 2011-03-05 at 00:51 +0100, Yves Parès wrote:
> 
> 
> But I don't have an explicit type to put.
> I cound do:
> 
> data CtxFooInst
> instance CtxFoo CtxFooInst
> 
> and declare runFoo as this:
> 
> runFoo :: MyIO CtxFooInst a -> IO a
> 
> But I loose the ability to make functions that can run several
> contexts.
> 

He meant:

newtype MyIO c a = MyIO (IO a)

data CtxFooInst
instance CtxFoo CtxFooInst

runMyIO :: CtxFoo c => MyIO c a -> IO a
runMyIO (MyIO x) = x

someAction :: CtxFoo c => MyIO c ()
someAction = MyIO (PutStrLn "Foo")

main = runMyIO (someAction :: MyIO CtxFooInst ())

In such way you push the abstraction down to main but actions are
contex-independent.

Regards



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


Re: [Haskell-cafe] Thoughts on program annotations.

2011-03-05 Thread wren ng thornton

On 3/4/11 2:32 PM, Jason Dusek wrote:

On Fri, Mar 4, 2011 at 07:01, wren ng thornton  wrote:

where the annotation of MergeAnn is merged with the previous
annotation up the tree (via mappend), thus allowing for
annotations to be inherited and modified incrementally based
on the Monoid instance; whereas the NewAnn constructor uses
the annotation directly, overriding any contextual
annotations. This can be helpful to reduce the amount of
duplication in the AST, though how helpful will depend on how
you plan to use/generate the ASTs.


   To handle this situation, I thought I'd leave it in the hands
   of the user (who will be me later) to use Data.Foldable.fold
   (or not) to arrive at the annotation when building up their
   tree of statements. I don't anticipate a problem with this but
   I may not use monoidal annotations on this AST for some time.
   (I anticipate using comments and raw text inclusions in the
   near future.)


That could be a workable solution. The tricky thing is that sometimes 
you want to mix the monoidal merge behavior of the annotation with the 
monoidal override behavior I mentioned, and it can get ugly to do that 
in one monoid. Whenever dealing with problems like this I often find 
myself running into semirings-- i.e., two monoids that interact in a 
sensible way. If you'll be wanting a semiring then the Foldable solution 
doesn't work very well. Again, it depends on what exactly you're 
planning to do with these ASTs.


--
Live well,
~wren

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


Re: [Haskell-cafe] Use of uninstantiated type class

2011-03-05 Thread John Lato
> Message: 8
> Date: Sat, 5 Mar 2011 00:45:33 +0100
> From: Yves Par?s 
> Subject: [Haskell-cafe] Use of uninstantiated type class
> To: Haskell-Cafe 
> Message-ID:
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello,
>
> For testing purposes, I am trying to make an overlay to IO which carries a
> phantom type to ensure a context.
> I define contexts using empty type classes :
>
> class CtxFoo c
> class CtxBar c
>
> The overlay :
>
> newtype MyIO c a = MyIO (IO a)
>
> Then I define some methods that run only a specific context :
>
> runFoo :: (CtxFoo c) => MyIO c a -> IO a
> runFoo (MyIO x) = x
>
> runBar :: (CtxBar c) => MyIO c a -> IO a
> runBar (MyIO x) = x
>
> And then an action that runs in context 'Foo' :
>
> someAction :: (CtxFoo c) => MyIO c ()
> someAction = putStrLn "FOO"
>
> Then I run it :
>
> main = runFoo someAction
>
> But obiously, GHC complains that my type 'c' remains uninstantiated :
>
>Ambiguous type variable `c' in the constraint:
>  (CtxFoo c) arising from a use of `runFoo'
>Probable fix: add a type signature that fixes these type variable(s)
>In the expression: runFoo someAction
>In an equation for `main': main = runFoo someAction
>
>
> Is there a way to deal with this ?
> The interest of using type classes and not empty types to represent the
> contexts is that it stays simple, and that I can do that :
>
> someAction2 :: (CtxFoo c, CtxBar c) => MyIO c ()
> someAction2 = putStrLn "FOO and BAR"
>
> ... a function that can run in both contexts.
>

You can accomplish this with Rank2Types (and ScopedTypeVariables).  Try
this:

class CtxFoo c
class CtxBar c

data Ctx
instance CtxFoo Ctx where
instance CtxBar Ctx where

runFoo :: forall a. (forall c. (CtxFoo c) => MyIO c a) -> IO a
runFoo x = case (x :: MyIO CtxFooD a) of
  (MyIO x') -> x'

It's useful to compare the type of this "runFoo" with the old "runFoo"

*Main> :t runFoo
runFoo :: (forall c. CtxFoo c => MyIO c a) -> IO a
*Main> :t runFooOld
runBar :: CtxFoo c => MyIO c a -> IO a

Note that the "c" type var is no longer universally quantified.  This means
that "runFoo" can't be used with any actions that specify a concrete
context, the action must specify only the "CtxFoo" type class.

There's a drawback to this approach though.  The number of "run" functions
is combinatorial in the number of contexts.  With only two contexts, you
already need "runFoo", "runBar", and "runFooBar".  Unless you'll only ever
need a single context, or you won't need to have combinations of them, this
approach quickly grows unwieldy.

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


Re: [Haskell-cafe] Learn You a Haskell for Great Good - a few doubts

2011-03-05 Thread wren ng thornton

On 3/4/11 4:33 PM, Alexander Solla wrote:

On Thu, Mar 3, 2011 at 10:14 PM, wren ng thornton  wrote:

On 3/3/11 2:58 AM, Antti-Juhani Kaijanaho wrote:

On Thu, Mar 03, 2011 at 12:29:44PM +0530, Karthick Gururaj wrote:


Thanks - is this the same "unit" that accompanies IO in "IO ()" ? In
any case, my question is answered since it is not a tuple.



It can be viewed as the trivial 0-tuple.



Except that this is problematic since Haskell doesn't have 1-tuples (which
would be distinct from plain values in that they have an extra bottom).



I don't get this line of thought.  I understand what you're saying, but why
even bother trying to distinguish between bottoms when they can't be
compared by equality, or even computed?


If we have,

   data OneTuple a = One a

Then

_|_ /= One _|_

This can be detected by seq: the left-hand side doesn't terminate, 
whereas the right-hand side does. And moreover, this can mess up other 
things (e.g., monads) by introducing too much laziness. Space leaks are 
quite a serious matter and they have nothing to do with trying to 
compare uncomputable values. Do you want a seemingly insignificant 
refactoring to cause your program to suddenly hang forever? Or to take 
up gobs more space than it used to?


This is very similar to the problems that people run into because,

_|_ /= (\x -> _|_)



The type (forall a . a) doesn't contain any values!


Nope, it contains one. Just ask any proof theorist, or anyone who uses 
witnesses to capture information in the type system.




If you choose to interpret all bottoms as being the same non-existent,
unquantifiable (in the language of Haskell) "proto-value", you get the
isomorphism between types a and (a), as types.


Nope, because we have

notBottom :: OneTuple a -> Bool
notBottom x = x `seq` True

whereas

isBottom :: a -> Bool
isBottom x = x `seq` True



Indeed, those are the
semantics in use by the language.  A value written (a) is interpreted as a.
  A type written (a) is interpreted as a.


That's a syntactic matter. Those are parentheses of grouping, not 
parentheses of tuple construction. For example, you can say:


(,) a b

or

(,,) a b c

But you can't say

() a


In an idealized world, yes, unit can be thought of as the nullary product
which serves as left- and right-identity for the product bifunctor.
Unfortunately, Haskell's tuples aren't quite products.[1]


I'm not seeing this either.  (A,B) is certainly the Cartesian product of A
and B.  In what sense are you using "product" here? Is your complaint a
continuation of your previous (implicit) line of thought regarding distinct
bottoms?


It is not the case that for every pair, ab, we have that:

ab == (fst ab, snd ab)

Why? Well consider ab = undefined:

_|_ /= (_|_,_|_)

I'm using "product" in the category theoretic sense, which is the sense 
in which it applies to Compact Closed Categories (i.e., the models of 
lambda calculi). Though it also works in the domain theoretic sense 
(i.e., how people reason about laziness), since Haskell's tuples are 
neither domain products nor smash products.


--
Live well,
~wren

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


[Haskell-cafe] Benchmarks game updated

2011-03-05 Thread Don Stewart
Isaac Gouy from the Language Benchmarks game tells me that they're
starting to use GHC 7.0.2, there are a few tweaks, new flags (e.g. the
LLVM backend) and other experiments people might like to try.

Additionally, there are a couple of build failures that should be fixed.

http://shootout.alioth.debian.org/u64q/measurements.php?lang=ghc

-- Don

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


[Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Bas van Dijk
Hello,

I like to turn my Haskell program into a unix daemon. One of the steps
in "daemonizing" a process is to fork it then exit the parent and
continue with the child. All this is nicely abstracted in
hdaemonize[1] which internally calls forkProcess[2].

I would also like to use multiple simultaneous threads in my program.
Unfortunately forkProcess is not supported when running with +RTS -N
so I can't use hdaemonize.

I understand why it's problematic to fork a process which is in the
middle of running multiple simultaneous threads. However, in the case
of a daemon the fork happens in the beginning of the program. So if I
can manage to create a program that first daemonizes my process then
starts the Haskell program, all is good.

My current plan is to have a custom Haskell main function which is
exported using the FFI:

-
{-# LANGUAGE ForeignFunctionInterface #-}

module MyMain where

import Control.Monad   ( forM_ )
import Control.Concurrent  ( threadDelay )

-- from hsyslog:
import System.Posix.Syslog ( Priority(Debug), syslog )

foreign export ccall myMain :: IO ()

myMain :: IO ()
myMain = forM_ [1..10 :: Int] $ \n -> do
   syslog Debug $ "test " ++ show n
   threadDelay 100
-

Then create a C program that first daemonizes my process (using the
'daemon'[3] function from unistd) then start up my custom Haskell main
function:

-
#include 
#include "HsFFI.h"
#include "MyMain_stub.h"

extern void __stginit_Main ( void );

int main(int argc, char *argv[])
{
  int r;
  r = daemon(0,0);
  if (r < 0)
  {
return r;
  }

  hs_init(&argc, &argv);
  hs_add_root(__stginit_Main);
  myMain();
  hs_exit();
  return 0;
}
-

My question is: how can I combine these two into a single program?

I very much prefer to do this using Cabal since my actual program
contains lots of dependencies.

Thanks,

Bas

[1] http://hackage.haskell.org/package/hdaemonize
[2] 
http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-Process.html#v:forkProcess
[3] http://www.kernel.org/doc/man-pages/online/pages/man3/daemon.3.html

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


[Haskell-cafe] Linking errors when compiling projects with the ncurses-0.2 library

2011-03-05 Thread Román González
Greetings,

Right now I'm developing an app, and I want to use the ncurses library,
everything compiles correctly, however when I'm linking, ugly things start
to happen:

I'm on Mac OS X Snow Leopard, with Haskell Platform
2010.2.0.0


This is the installation process I'm following, everything runs as expected
until trying to build the project with Cabal.

Thanks in advance.

*$ brew install ncursesw --universal*
Warning: It appears you have MacPorts or Fink installed.
Software installed with MacPorts and Fink are known to cause problems.
If you experience issues try uninstalling these tools.
==> Downloading http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz
File already downloaded and cached to /Users/roman/Library/Caches/Homebrew
==> ./configure --prefix=/Users/roman/.homebrew/Cellar/ncursesw/5.7
--mandir=/Users/roman/.homebrew/Cellar/ncursesw/5.7/share/man
--disable-debug --disable-dependency-tracking --e
==> make install
/Users/roman/.homebrew/Cellar/ncursesw/5.7: 2734 files, 14M, in 93 seconds

*$ cabal install ncurses --extra-include-dirs=/Users/roman/.homebrew/include
--extra-lib-dirs=/Users/roman/.homebrew/lib --reinstall*
Resolving dependencies...
Configuring ncurses-0.2...
Preprocessing library ncurses-0.2...
Building ncurses-0.2...
[1 of 4] Compiling UI.NCurses.Enums ( dist/build/UI/NCurses/Enums.hs,
dist/build/UI/NCurses/Enums.o )
[2 of 4] Compiling UI.NCurses.Types ( UI/NCurses/Types.hs,
dist/build/UI/NCurses/Types.o )
[3 of 4] Compiling UI.NCurses   ( dist/build/UI/NCurses.hs,
dist/build/UI/NCurses.o )
[4 of 4] Compiling UI.NCurses.Panel ( dist/build/UI/NCurses/Panel.hs,
dist/build/UI/NCurses/Panel.o )

UI/NCurses/Panel.chs:49:0:
Warning: The import of `UI.NCurses' is redundant
   except perhaps to import instances from `UI.NCurses'
 To import instances alone, use: import UI.NCurses()
Registering ncurses-0.2...
Installing library in /Users/roman/.cabal/lib/ncurses-0.2/ghc-6.12.3
Registering ncurses-0.2...

*$ cabal build*
Preprocessing executables for TicTacToe-0.1...
Building TicTacToe-0.1...
Linking dist/build/TicTacToe/TicTacToe ...
ld: warning: in /Users/roman/.homebrew/lib/libncursesw.dylib, file was built
for unsupported file format which is not the architecture being linked
(i386)
Undefined symbols:
  "_start_color", referenced from:
  _s9ZP_info in libHSncurses-0.2.a(NCurses.o)
  "_wget_wch", referenced from:
  _sfkI_info in libHSncurses-0.2.a(NCurses.o)
  "_wenclose", referenced from:
  _s9Fs_info in libHSncurses-0.2.a(NCurses.o)
  "_beep", referenced from:
  _ncurseszm0zi2_UIziNCurses_beep1_info in libHSncurses-0.2.a(NCurses.o)
 (maybe you meant: _ncurseszm0zi2_UIziNCurses_beep2_closure,
_ncurseszm0zi2_UIziNCurses_beep1_srt , _ncurseszm0zi2_UIziNCurses_beep_srt ,
_ncurseszm0zi2_UIziNCurses_beep3_info , _ncurseszm0zi2_UIziNCurses_beep2_srt
, _ncurseszm0zi2_UIziNCurses_beep3_srt ,
_ncurseszm0zi2_UIziNCurses_beep1_closure ,
_ncurseszm0zi2_UIziNCurses_beep_info , _ncurseszm0zi2_UIziNCurses_beep1_info
, _ncurseszm0zi2_UIziNCurses_beep3_closure ,
_ncurseszm0zi2_UIziNCurses_beep2_info ,
_ncurseszm0zi2_UIziNCurses_beep_closure )
  "_echo", referenced from:
  _sc50_info in libHSncurses-0.2.a(NCurses.o)
 (maybe you meant: ___hscore_echo)
  "_can_change_color", referenced from:
  _ncurseszm0zi2_UIziNCurses_canDefineColor1_info in
libHSncurses-0.2.a(NCurses.o)
  "_init_color", referenced from:
  _s97K_info in libHSncurses-0.2.a(NCurses.o)
  _scw2_info in libHSncurses-0.2.a(NCurses.o)
  "_wnoutrefresh", referenced from:
  _s2JC_info in NCurses.o
  _scSh_info in libHSncurses-0.2.a(NCurses.o)
  "_noraw", referenced from:
  _scaE_info in libHSncurses-0.2.a(NCurses.o)
  "_wtouchln", referenced from:
  _sd53_info in libHSncurses-0.2.a(NCurses.o)
  _sd53_info in libHSncurses-0.2.a(NCurses.o)
  "_wcolor_set", referenced from:
  _sav6_info in libHSncurses-0.2.a(NCurses.o)
  "_meta", referenced from:
  _s9KC_info in libHSncurses-0.2.a(NCurses.o)
  _scV2_info in libHSncurses-0.2.a(NCurses.o)
  "_initscr", referenced from:
  _ncurseszm0zi2_UIziNCurses_runCurses2_info in
libHSncurses-0.2.a(NCurses.o)
  "_stdscr", referenced from:
  _stdscr$non_lazy_ptr in NCurses.o
  _stdscr$non_lazy_ptr in libHSncurses-0.2.a(NCurses.o)
 (maybe you meant: _stdscr$non_lazy_ptr)
  "_wbkgrndset", referenced from:
  _scOA_info in libHSncurses-0.2.a(NCurses.o)
  "_raw", referenced from:
  _scaE_info in libHSncurses-0.2.a(NCurses.o)
 (maybe you meant: _ffi_closure_raw_SYSV$non_lazy_ptr,
_ffi_closure_raw_SYSV , _ffi_raw_call , _ffi_prep_raw_closure_loc )
  "__nc_has_mouse", referenced from:
  _hsncurses_has_mouse in libHSncurses-0.2.a(hsncurses-shim.o)
  "_wtimeout", referenced from:
  _s9KE_info in libHSncurses-0.2.a(NCurses.o)
  _scV4_info in libHSncurses-0.2.a(NCurses.o)
  _sfkG_info in libHSncurses-0.2.a(NCurses.o)
  "_doupdate

Re: [Haskell-cafe] Linking errors when compiling projects with the ncurses-0.2 library

2011-03-05 Thread Román González
> Greetings,
>
> Right now I'm developing an app, and I want to use the ncurses library,
> everything compiles correctly, however when I'm linking, ugly things start
> to happen:
>
> I'm on Mac OS X Snow Leopard, with Haskell Platform 
> 2010.2.0.0
>
>
> This is the installation process I'm following, everything runs as expected
> until trying to build the project with Cabal.
>
> Thanks in advance.
>
> *$ brew install ncursesw --universal*
> Warning: It appears you have MacPorts or Fink installed.
> Software installed with MacPorts and Fink are known to cause problems.
> If you experience issues try uninstalling these tools.
> ==> Downloading http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz
> File already downloaded and cached to /Users/roman/Library/Caches/Homebrew
> ==> ./configure --prefix=/Users/roman/.homebrew/Cellar/ncursesw/5.7
> --mandir=/Users/roman/.homebrew/Cellar/ncursesw/5.7/share/man
> --disable-debug --disable-dependency-tracking --e
> ==> make install
> /Users/roman/.homebrew/Cellar/ncursesw/5.7: 2734 files, 14M, in 93 seconds
>
> *$ cabal install ncurses
> --extra-include-dirs=/Users/roman/.homebrew/include
> --extra-lib-dirs=/Users/roman/.homebrew/lib --reinstall*
> Resolving dependencies...
> Configuring ncurses-0.2...
> Preprocessing library ncurses-0.2...
> Building ncurses-0.2...
> [1 of 4] Compiling UI.NCurses.Enums ( dist/build/UI/NCurses/Enums.hs,
> dist/build/UI/NCurses/Enums.o )
> [2 of 4] Compiling UI.NCurses.Types ( UI/NCurses/Types.hs,
> dist/build/UI/NCurses/Types.o )
> [3 of 4] Compiling UI.NCurses   ( dist/build/UI/NCurses.hs,
> dist/build/UI/NCurses.o )
> [4 of 4] Compiling UI.NCurses.Panel ( dist/build/UI/NCurses/Panel.hs,
> dist/build/UI/NCurses/Panel.o )
>
> UI/NCurses/Panel.chs:49:0:
> Warning: The import of `UI.NCurses' is redundant
>except perhaps to import instances from `UI.NCurses'
>  To import instances alone, use: import UI.NCurses()
> Registering ncurses-0.2...
> Installing library in /Users/roman/.cabal/lib/ncurses-0.2/ghc-6.12.3
> Registering ncurses-0.2...
>
> *$ cabal build*
> Preprocessing executables for TicTacToe-0.1...
> Building TicTacToe-0.1...
> Linking dist/build/TicTacToe/TicTacToe ...
> ld: warning: in /Users/roman/.homebrew/lib/libncursesw.dylib, file was
> built for unsupported file format which is not the architecture being linked
> (i386)
> Undefined symbols:
>   "_start_color", referenced from:
>   _s9ZP_info in libHSncurses-0.2.a(NCurses.o)
>   "_wget_wch", referenced from:
>   _sfkI_info in libHSncurses-0.2.a(NCurses.o)
>   "_wenclose", referenced from:
>   _s9Fs_info in libHSncurses-0.2.a(NCurses.o)
>   "_beep", referenced from:
>   _ncurseszm0zi2_UIziNCurses_beep1_info in
> libHSncurses-0.2.a(NCurses.o)
>  (maybe you meant: _ncurseszm0zi2_UIziNCurses_beep2_closure,
> _ncurseszm0zi2_UIziNCurses_beep1_srt , _ncurseszm0zi2_UIziNCurses_beep_srt ,
> _ncurseszm0zi2_UIziNCurses_beep3_info , _ncurseszm0zi2_UIziNCurses_beep2_srt
> , _ncurseszm0zi2_UIziNCurses_beep3_srt ,
> _ncurseszm0zi2_UIziNCurses_beep1_closure ,
> _ncurseszm0zi2_UIziNCurses_beep_info , _ncurseszm0zi2_UIziNCurses_beep1_info
> , _ncurseszm0zi2_UIziNCurses_beep3_closure ,
> _ncurseszm0zi2_UIziNCurses_beep2_info ,
> _ncurseszm0zi2_UIziNCurses_beep_closure )
>   "_echo", referenced from:
>   _sc50_info in libHSncurses-0.2.a(NCurses.o)
>  (maybe you meant: ___hscore_echo)
>   "_can_change_color", referenced from:
>   _ncurseszm0zi2_UIziNCurses_canDefineColor1_info in
> libHSncurses-0.2.a(NCurses.o)
>   "_init_color", referenced from:
>   _s97K_info in libHSncurses-0.2.a(NCurses.o)
>   _scw2_info in libHSncurses-0.2.a(NCurses.o)
>   "_wnoutrefresh", referenced from:
>   _s2JC_info in NCurses.o
>   _scSh_info in libHSncurses-0.2.a(NCurses.o)
>   "_noraw", referenced from:
>   _scaE_info in libHSncurses-0.2.a(NCurses.o)
>   "_wtouchln", referenced from:
>   _sd53_info in libHSncurses-0.2.a(NCurses.o)
>   _sd53_info in libHSncurses-0.2.a(NCurses.o)
>   "_wcolor_set", referenced from:
>   _sav6_info in libHSncurses-0.2.a(NCurses.o)
>   "_meta", referenced from:
>   _s9KC_info in libHSncurses-0.2.a(NCurses.o)
>   _scV2_info in libHSncurses-0.2.a(NCurses.o)
>   "_initscr", referenced from:
>   _ncurseszm0zi2_UIziNCurses_runCurses2_info in
> libHSncurses-0.2.a(NCurses.o)
>   "_stdscr", referenced from:
>   _stdscr$non_lazy_ptr in NCurses.o
>   _stdscr$non_lazy_ptr in libHSncurses-0.2.a(NCurses.o)
>  (maybe you meant: _stdscr$non_lazy_ptr)
>   "_wbkgrndset", referenced from:
>   _scOA_info in libHSncurses-0.2.a(NCurses.o)
>   "_raw", referenced from:
>   _scaE_info in libHSncurses-0.2.a(NCurses.o)
>  (maybe you meant: _ffi_closure_raw_SYSV$non_lazy_ptr,
> _ffi_closure_raw_SYSV , _ffi_raw_call , _ffi_prep_raw_closure_loc )
>   "__nc_has_mouse", referenced from:
>   _hsncurses_has_mouse in libHSncurse

Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Donn Cave
Quoth Bas van Dijk ,
...
> I understand why it's problematic to fork a process which is in the
> middle of running multiple simultaneous threads. However, in the case
> of a daemon the fork happens in the beginning of the program. So if I
> can manage to create a program that first daemonizes my process then
> starts the Haskell program, all is good.

type ProcessID = CInt
type Fd = CInt

foreign import ccall "fork" c_fork :: IO CInt
foreign import ccall "_exit" _exit :: CInt -> IO ()

fork :: IO Int -> IO ProcessID
fork fn = do
pid <- c_fork
if pid == 0
then do
fn >>= _exit . fromIntegral
return 0 -- unused, I reckon
else if pid > 0
then return pid
else throwErrno "fork"

System.PosixProcess (exitImmediately) is supposed to be "_exit".

I would not care to hazard a guess as to whether this will work
reliably for you.

If you figure out how to use your own custom C main() function,
I'd be interested to know.  I use separate C programs that
exec my Haskell programs.  My current GHC can't compile -via-C,
but if you can compile a minimal "main" module to C that way,
it probably calls hs_main() or something like that?  and you
could add your own xx_main() to the stack.

Donn Cave, d...@avvanta.com

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Vincent Hanquez
On Sat, Mar 05, 2011 at 08:51:59PM +0100, Bas van Dijk wrote:
> Hello,
> 
> I like to turn my Haskell program into a unix daemon. One of the steps
> in "daemonizing" a process is to fork it then exit the parent and
> continue with the child. All this is nicely abstracted in
> hdaemonize[1] which internally calls forkProcess[2].
> 
> I would also like to use multiple simultaneous threads in my program.
> Unfortunately forkProcess is not supported when running with +RTS -N
> so I can't use hdaemonize.
> 
> I understand why it's problematic to fork a process which is in the
> middle of running multiple simultaneous threads. However, in the case
> of a daemon the fork happens in the beginning of the program. So if I
> can manage to create a program that first daemonizes my process then
> starts the Haskell program, all is good.
> 
> My current plan is to have a custom Haskell main function which is
> exported using the FFI:

Hi,

Did you alternatively though about daemonizing in your haskell program normally
without using +RTS -N, and exec'ing yourself (using executeFile) with the extra
cmdline +RTS -N options, and also --no-daemon option to avoid 
re-daemon/exec'ing ?

I think that would be simpler than your current approch.

-- 
Vincent

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Bas van Dijk
On 5 March 2011 21:43, Donn Cave  wrote:
> Quoth Bas van Dijk ,
> ...
>> I understand why it's problematic to fork a process which is in the
>> middle of running multiple simultaneous threads. However, in the case
>> of a daemon the fork happens in the beginning of the program. So if I
>> can manage to create a program that first daemonizes my process then
>> starts the Haskell program, all is good.
>
> type ProcessID = CInt
> type Fd = CInt
>
> foreign import ccall "fork" c_fork :: IO CInt
> foreign import ccall "_exit" _exit :: CInt -> IO ()
>
> fork :: IO Int -> IO ProcessID
> fork fn = do
>        pid <- c_fork
>        if pid == 0
>                then do
>                        fn >>= _exit . fromIntegral
>                        return 0 -- unused, I reckon
>                else if pid > 0
>                        then return pid
>                        else throwErrno "fork"
>
> System.PosixProcess (exitImmediately) is supposed to be "_exit".
>
> I would not care to hazard a guess as to whether this will work
> reliably for you.

Thanks, I thought about this too, however I consider myself too
unfamiliar with the RTS to know if this is safe.

Bas

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Bas van Dijk
On 5 March 2011 21:51, Vincent Hanquez  wrote:
> On Sat, Mar 05, 2011 at 08:51:59PM +0100, Bas van Dijk wrote:
>> Hello,
>>
>> I like to turn my Haskell program into a unix daemon. One of the steps
>> in "daemonizing" a process is to fork it then exit the parent and
>> continue with the child. All this is nicely abstracted in
>> hdaemonize[1] which internally calls forkProcess[2].
>>
>> I would also like to use multiple simultaneous threads in my program.
>> Unfortunately forkProcess is not supported when running with +RTS -N
>> so I can't use hdaemonize.
>>
>> I understand why it's problematic to fork a process which is in the
>> middle of running multiple simultaneous threads. However, in the case
>> of a daemon the fork happens in the beginning of the program. So if I
>> can manage to create a program that first daemonizes my process then
>> starts the Haskell program, all is good.
>>
>> My current plan is to have a custom Haskell main function which is
>> exported using the FFI:
>
> Hi,
>
> Did you alternatively though about daemonizing in your haskell program 
> normally
> without using +RTS -N, and exec'ing yourself (using executeFile) with the 
> extra
> cmdline +RTS -N options, and also --no-daemon option to avoid 
> re-daemon/exec'ing ?
>
> I think that would be simpler than your current approch.

What a nice idea! I actually looked for a unix command line tool that
could do this but did not think further about doing it myself.

Thanks,

Bas

P.S.
So is there a tool that daemonizes another program? Sounds like a job
for a neat little Haskell program...

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


Re: [Haskell-cafe] Convert a function to a string of operators?

2011-03-05 Thread Evgeny Grablyk
Many thanks for your help! Seems to be what I need. Two more related questions:

Will methods explained here work for boolean expressions?
Is there a way to extract parameter names from function definition to
use them in Show instance? Or should I just use same names everywhere?

In case  that helps, here's the code I need to convert (the code in
where part of solveScheme): http://npaste.de/aKY3cn0xZf/

-- 
Evgeny

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


[Haskell-cafe] Haskell Platform 2011.2

2011-03-05 Thread tsuraan
The wiki page for Haskell Platform is still listing March 5 (today) as
the planned release date.  Is this still the plan, or should the page
be updated?

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


Re: [Haskell-cafe] Haskell Platform 2011.2

2011-03-05 Thread Don Stewart
We're currently testing the installers, with a view to announcing the
release early in the week.

Cheers,
  Don

P.S. you can help by testing the installers, and reporting issues on
the HP trac and mailing list. The candidate installers are here:

   http://code.galois.com/darcs/haskell-platform/download-website/

On Sat, Mar 5, 2011 at 4:39 PM, tsuraan  wrote:
> The wiki page for Haskell Platform is still listing March 5 (today) as
> the planned release date.  Is this still the plan, or should the page
> be updated?
>
> ___
> 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] How to daemonize a threaded Haskell program?

2011-03-05 Thread Sterling Clover
On Mar 5, 2011, at 5:59 PM, Bas van Dijk wrote:

> On 5 March 2011 21:51, Vincent Hanquez  wrote:
>> On Sat, Mar 05, 2011 at 08:51:59PM +0100, Bas van Dijk wrote:
>>> Hello,
>>> 
>>> I like to turn my Haskell program into a unix daemon. One of the steps
>>> in "daemonizing" a process is to fork it then exit the parent and
>>> continue with the child. All this is nicely abstracted in
>>> hdaemonize[1] which internally calls forkProcess[2].

Have you looked at direct-daemonize[1]?

I'm not sure if it will do the job, but it's certainly worth mentioning.

Cheers,
Sterl


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


[Haskell-cafe] GHC 7.0.2 and haddock

2011-03-05 Thread Maciej Marcin Piechotka
Is there any version of haddock that builds with ghc 7.0.2?

For 2.9.1 I get:

src/Haddock/Interface/Create.hs:282:11:
Couldn't match expected type `Located b0'
with actual type `[LTyClDecl id0]'
Expected type: HsGroup id0 -> [Located b0]
  Actual type: HsGroup id0 -> [[LTyClDecl id0]]
In the first argument of `mkDecls', namely `hs_tyclds'
In the first argument of `(++)', namely
  `mkDecls hs_tyclds TyClD group_'

Regards



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


Re: [Haskell-cafe] GHC 7.0.2 and haddock

2011-03-05 Thread Daniel Fischer
On Sunday 06 March 2011 02:34:58, Maciej Marcin Piechotka wrote:
> Is there any version of haddock that builds with ghc 7.0.2?

The source tarball comes with 2.9.2, that built and works here. While 2.9.2 
is not on hackage, you could try the darcs version.


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


Re: [Haskell-cafe] GHC 7.0.2 and haddock

2011-03-05 Thread Maciej Piechotka
On Sun, 2011-03-06 at 02:56 +0100, Daniel Fischer wrote:
> On Sunday 06 March 2011 02:34:58, Maciej Marcin Piechotka wrote:
> > Is there any version of haddock that builds with ghc 7.0.2?
> 
> The source tarball comes with 2.9.2, that built and works here. While 2.9.2 
> is not on hackage, you could try the darcs version.
> 

Ok. Thanks.

Regards


signature.asc
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linking errors when compiling projects with the ncurses-0.2 library

2011-03-05 Thread Gregory Collins
2011/3/5 Román González :
> ld: warning: in /Users/roman/.homebrew/lib/libncursesw.dylib, file was built 
> for unsupported file format which is not the architecture being linked (i386)

You're trying to link a 64-bit library with a 32-bit GHC. Either
upgrade to the new 64-bit GHC installer, or rebuild your libraries
with 32-bit support.

G
-- 
Gregory Collins 

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Gregory Collins
On Sat, Mar 5, 2011 at 11:59 PM, Bas van Dijk  wrote:
> So is there a tool that daemonizes another program? Sounds like a job
> for a neat little Haskell program...

There are a few I'm aware of:

  * http://software.clapper.org/daemonize/
  * http://cr.yp.to/daemontools.html (warning, DJ Bernstein code :) )

G
-- 
Gregory Collins 

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


Re: [Haskell-cafe] Haskell Platform 2011.2

2011-03-05 Thread tsuraan
> We're currently testing the installers, with a view to announcing the
> release early in the week.

Very cool.  Thanks!

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread Brandon Moore
Hi Bas

If you want to use your own C main(), that's documented here:


http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/ffi-ghc.html#using-own-main


  

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


[Haskell-cafe] ANN: bash-0.0.0

2011-03-05 Thread Jason Dusek
  Many-a-time, have I used higher level languages to generate
  Bash scripts. Here, for the first time, I have taken the time
  to write a structured and safe Bash pretty printer, leveraging
  some work on shell escaping I did some months ago.


http://hackage.haskell.org/packages/archive/bash/0.0.0/doc/html/Language-Bash.html

  A wide range of Bash constructs are supported. It's easiest to
  point out what's not supported at present:

 .  Arithmetic substitutions (those within "$(( ))").

 .  Bash's test special form (using "[[ ]]"). Ordinary uses of
the test command are of course fully supported.

 .  Specialized expression de-referencing forms that allow
substitution and substring selection; the only thing
supported in this domain is defaulting and length:

  ${#var}   # Length of var in bytes.
  ${var:-}  # If var is not set, yield the empty string.

  Many other forms that are tedious to get right -- special
  variable names, array expansions, even eval -- are fully
  supported.

  I'll be using this tool to support a config generation system.
  Another interesting application is generating Bash completion
  scripts.

  If you decide to use it and have trouble please let me know;
  this is the first Language.Something that I have written and
  it may not present the friendliest interface. Do let me know,
  also, if the omitted syntactic structures would be helpful to
  you and I will see what I can do to include them.

--
Jason Dusek
Linux User #510144 | http://counter.li.org/

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


Re: [Haskell-cafe] ANN: bash-0.0.0

2011-03-05 Thread Ivan Lazar Miljenovic
On 6 March 2011 14:57, Jason Dusek  wrote:
>  Many-a-time, have I used higher level languages to generate
>  Bash scripts. Here, for the first time, I have taken the time
>  to write a structured and safe Bash pretty printer, leveraging
>  some work on shell escaping I did some months ago.
>
>    
> http://hackage.haskell.org/packages/archive/bash/0.0.0/doc/html/Language-Bash.html

Maybe this could be integrated with language-sh [1] to get parsing
support as well?

[1]: http://hackage.haskell.org/package/language-sh

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

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


Re: [Haskell-cafe] How to daemonize a threaded Haskell program?

2011-03-05 Thread David Anderson
I humbly recommend doing such daemonizations from outside your program.
Programs that daemonize on startup make it very difficult to monitor them by
direct means, instead forcing you to rely on PID files and other mechanisms
which may not always be available or fresh.

For reference, Upstart, the new PID 1 on Ubuntu and friends, has a horrible
hack[1] built in specifically to keep track of processes that "helpfully"
daemonize themselves, so that it can offer additional services like
restarting crashed services or notifying the owner of a problem.

As has been pointed out elsewhere on thread, there are plenty of standalone
programs that implement daemonization if you end up not using service
management software to do it for you. It's also trivial to implement a
Haskell program that would do this for you, since that standalone program
would not need threads or the complications that they bring to forking.

Or if you really must, make daemonization a startup option of your real
server, but please please please have a flag to turn that behavior off, so
that your service isn't a nightmare to manage for us poor sysadmins :-).

- Dave

[1]: if you care, the hack in question is ptrace(): if you declare to
Upstart that your service daemonizes itself, it will boot your binary,
ptrace() it, and track the process across two fork/clone syscalls, then
un-ptrace() and use the second child as the "real" service process. Please
don't make binaries where daemonization can't be turned off. Machine
management software should not have to use debugging facilities to correctly
monitor your program.

On Sat, Mar 5, 2011 at 11:51 AM, Bas van Dijk  wrote:

> Hello,
>
> I like to turn my Haskell program into a unix daemon. One of the steps
> in "daemonizing" a process is to fork it then exit the parent and
> continue with the child. All this is nicely abstracted in
> hdaemonize[1] which internally calls forkProcess[2].
>
> I would also like to use multiple simultaneous threads in my program.
> Unfortunately forkProcess is not supported when running with +RTS -N
> so I can't use hdaemonize.
>
> I understand why it's problematic to fork a process which is in the
> middle of running multiple simultaneous threads. However, in the case
> of a daemon the fork happens in the beginning of the program. So if I
> can manage to create a program that first daemonizes my process then
> starts the Haskell program, all is good.
>
> My current plan is to have a custom Haskell main function which is
> exported using the FFI:
>
> -
> {-# LANGUAGE ForeignFunctionInterface #-}
>
> module MyMain where
>
> import Control.Monad   ( forM_ )
> import Control.Concurrent  ( threadDelay )
>
> -- from hsyslog:
> import System.Posix.Syslog ( Priority(Debug), syslog )
>
> foreign export ccall myMain :: IO ()
>
> myMain :: IO ()
> myMain = forM_ [1..10 :: Int] $ \n -> do
>   syslog Debug $ "test " ++ show n
>   threadDelay 100
> -
>
> Then create a C program that first daemonizes my process (using the
> 'daemon'[3] function from unistd) then start up my custom Haskell main
> function:
>
> -
> #include 
> #include "HsFFI.h"
> #include "MyMain_stub.h"
>
> extern void __stginit_Main ( void );
>
> int main(int argc, char *argv[])
> {
>  int r;
>  r = daemon(0,0);
>  if (r < 0)
>  {
>return r;
>  }
>
>  hs_init(&argc, &argv);
>  hs_add_root(__stginit_Main);
>  myMain();
>  hs_exit();
>  return 0;
> }
> -
>
> My question is: how can I combine these two into a single program?
>
> I very much prefer to do this using Cabal since my actual program
> contains lots of dependencies.
>
> Thanks,
>
> Bas
>
> [1] http://hackage.haskell.org/package/hdaemonize
> [2]
> http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-Process.html#v:forkProcess
> [3] http://www.kernel.org/doc/man-pages/online/pages/man3/daemon.3.html
>
> ___
> 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] Benchmarks game updated

2011-03-05 Thread Nikitiskiy Dmitriy
05.03.2011 20:55, Don Stewart пишет:
> Isaac Gouy from the Language Benchmarks game tells me that they're
> starting to use GHC 7.0.2, there are a few tweaks, new flags (e.g. the
> LLVM backend) and other experiments people might like to try.
>
> Additionally, there are a couple of build failures that should be fixed.
>
> http://shootout.alioth.debian.org/u64q/measurements.php?lang=ghc
>
> -- Don
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>   
Hello,

As I see, some examples compilled with similar flags:

/usr/local/src/ghc-7.0.2/bin/ghc --make -O2 -fglasgow-exts -rtsopts 
-funbox-strict-fields -fexcess-precision -fvia-c -optc-O3 spectralnorm.ghc-4.hs 
-o spectralnorm.ghc-4.ghc_run

Does this flags enable LLVM optimizations in 7.0.2?

--
Dmitriy



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


Re: [Haskell-cafe] ANN: bash-0.0.0

2011-03-05 Thread Jason Dusek
On Sun, Mar 6, 2011 at 04:27, Ivan Lazar Miljenovic
 wrote:
> Maybe this could be integrated with language-sh [1] to get parsing
> support as well?
>
> [1]: http://hackage.haskell.org/package/language-sh

  It's hard to say without testing it; but anything labeled Sh
  probably won't parse real Bash very well.

  Would parsing a subset be enough? There are certain kinds of
  unescaped variable references that I don't plan to support in
  the Syntax; so there'd be nothing to parse them in to. Maybe I
  will have to rethink this part; I considered a

Quoted (Expression t)

  constructor for Expression. A real parser should probably
  preserve comments, too.

  It is normal to include parsers in Language.Something modules;
  in this particular case, I assumed Bash analysis would not be
  used much. If you are interested in a way to wrap Bash you
  pull out of a file into a script you construct with the
  Syntax, you might try the Language.Bash.Annotations.Lines
  datatype.

--
Jason Dusek
Linux User #510144 | http://counter.li.org/

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