Re: [Haskell-cafe] Monadic style with Streams (as in Data.Array.Parallel.Stream)

2010-05-16 Thread Mark Wassell



Roman Leshchinskiy wrote:

On 16/05/2010, at 11:54, Mark Wassell wrote:

  

Hi,

This possibly might go against the spirit of what Stream programming is about 
but I having difficulties converting an imperative algorithm [1] into Haskell 
and think it would be easier if I was able to write it in a monadic style with 
operations to read and write from and to the streams.

I first tried to approach it by delving into the innards of other Stream 
functions to devise what I needed. I only got so far and the sticking point was 
defining the Monad. I then approached it from the Monad side and although what 
I have is workable, it probably isn't going to perform (for one it uses 
fromStream and tailS on each read off the front of the stream).



Data.Array.Parallel.Stream serves only one purpose: to represent loops produced by 
DPH in such a way that the compiler is able to optimise them well. Putting a monad 
on top of that will very very likely break this. To be honest, I'm not sure why 
you need the monad anyway. I would expect compression/decompression to be pure 
functions of type Stream Word8 - Stream Word8.

In any case, I would urgently recommend not to use Data.Array.Parallel.Stream 
for anything at this point. This whole subsystem will soon die of old age and 
be replaced by the much nicer stuff from package vector, specifically 
Data.Vector.Fusion.Stream and Data.Vector.Fusion.Stream.Monadic. Note that the 
latter implements monadic streams as described in 
http://www.cse.unsw.edu.au/~rl/publications/recycling.html. Perhaps those can 
be useful for you if you really need a monad.

Roman
  
Thanks. No, I don't need a Monad and I suspected it was a bad idea. It 
was really needed for convenience as all I had to go on was a C 
implementaiton of arithmetic coding (which included a getc part-way 
through the code block which I hoped to map to something like a get from 
the stream).  However thanks to Stephen I have something better to work 
from. I will also take a look at Data.Vector.Fusion.Stream.


Cheers

Mark

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


[Haskell-cafe] Monadic style with Streams (as in Data.Array.Parallel.Stream)

2010-05-15 Thread Mark Wassell

Hi,

This possibly might go against the spirit of what Stream programming is 
about but I having difficulties converting an imperative algorithm [1] 
into Haskell and think it would be easier if I was able to write it in a 
monadic style with operations to read and write from and to the streams.


I first tried to approach it by delving into the innards of other Stream 
functions to devise what I needed. I only got so far and the sticking 
point was defining the Monad. I then approached it from the Monad side 
and although what I have is workable, it probably isn't going to perform 
(for one it uses fromStream and tailS on each read off the front of the 
stream).


So:

1. Is this monadic style within the spirit of what Stream programming is 
about?
2. Is there anyway to do this more elegantly and without the user of 
fromStream and tailS, for example.


This is the workable solution I have:

module StreamMonad where

import Data.Array.Parallel.Stream

import Data.Monoid
import Control.Monad.Writer
import Control.Monad.State

instance Monoid (Stream a) where
mempty = emptyS
mappend = (+++)

type SM a b c = StateT (Stream a) (Writer (Stream b)) c

readS :: SM a b a
readS = do
   s - get
   let a = head $ fromStream s
   put $ tailS s
   return a

writeS :: b - SM a b ()
writeS x = tell $ singletonS x


t1' :: SM (Int,Int) Int ()
t1' = mapM_ (\_ - do
   (x,y) - readS
   writeS x
   writeS y) [1..2]

t1 = fromStream $ snd $ runWriter $ runStateT t1' $ toStream [(1,2),(3,4)]

-- At least this works ..
t2 = fromStream $ snd $ runWriter $ runStateT t1' $ toStream 
[(2*x-1,2*x) | x - [1..] ]


Cheers

Mark

[1] The arithmentic coding and decoding algorithms given in 
http://mattmahoney.net/dc/dce.html#Section_32
 


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


Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-01 Thread Mark Wassell
Check the laws that instances of MonadPlus and Alternative should comply 
with to help you make your decision.


Cheers

Mark

Sean Leather wrote:
I want to generalize a set of functions from lists to some functor 
type. I require the following three operation types.


  f a
  a - f a
  f a - f a - f a

Should I choose MonadPlus and use these?

  mzero
  return
  mplus

Or should I choose Alternative and use these?

  empty
  pure
  (|)

Or should I make my own class? Or is there another option?

Thanks,
Sean


___
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] games of chance

2010-02-19 Thread Mark Wassell

Take a look at:

http://hackage.haskell.org/package/probability

and

http://web.engr.oregonstate.edu/~erwig/pfp/

Mark


Dupont Corentin wrote:


Hello,
are you aware of a framework to find probabilities in a given game of
chance, in Haskell?

l would like to compute probabilities like:
roll 3 dices, sum the result,  then roll 3 other dices, sum the result,
what is the probability to obtain the same sum?

Cheers,
Corentin






___
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] Collection of sets containing no sets which are a subset of another in the collection

2009-11-13 Thread Mark Wassell

Hi,

I am looking for a data structure that will represent a collection of 
sets such that no element in the collection is a subset of another set. 
In other words, inserting an element that is already a subset of another 
element will return the original collection, and inserting an element 
that is a superset of any elements will result in a collection with the 
superset added and the subsets removed.


What I have so far is the below but I am wondering if there has been any 
prior work on this (particularly using Haskell but also conceptual 
work). Inserting a set that is a subset is easy to handle, inserting a 
superset and remove subsets of it is a little tricker.


Cheers

Mark


module SetTrie where

--
-- A set of sets which does not contain elements which are subsets of 
any other element.
-- ie insert a element which is a proper subset of another set returns 
the same set of sets
--insert a element which is a proper superset of one or more 
elements causes those elements to be removed

-- (and the first element to be added)
--


import Data.Set hiding (toList,singleton,map,insert)
import Data.Map hiding 
(fromList,showTreeWith,toAscList,toList,singleton,map,insert)

import qualified Data.Map as M (toList,fromList,lookup,insert)
import qualified Data.Set as S (toList,fromList)



-- Normally we would have a flag at a node to indicate a subset is 
there, but we

-- don't store subsets.


data SetTrie a = Leaf [a] | Node (Map a (SetTrie a)) deriving (Show,Eq)

singleton :: Ord a = Set a - SetTrie a
singleton = Leaf . S.toList

toList' :: Ord a = SetTrie a - [[a]]
toList' (Leaf xs) = [xs]
toList' (Node m) = concatMap (\(x,y) - map (x:) (toList' y)) $ M.toList m

toList :: Ord a = SetTrie a - [Set a]
toList x = map S.fromList $ toList' x

insert :: Ord a = SetTrie a - Set a - SetTrie a
insert t s = insert' t $ toAscList s

insert':: Ord a = SetTrie a - [a] - SetTrie a
insert' (Leaf (y:ys)) (x:xs) = Node (M.fromList [(y,Leaf ys),(x,Leaf xs)])
insert' (Node m) (x:xs) = case M.lookup x m of
Nothing - case xs of
  [] - Node $ M.insert x 
(Leaf xs) m
  _ -  Node $ M.insert x 
(Leaf xs) m

Just t' - case xs of
  [] - Node m
  _ -  Node $ M.insert x 
(insert' t' xs) m


-- removeSubsets ::

-- terminate (Node m) = Node mTrue m
-- terminate (Leaf (x:xs)) = Node True (M.fromList [(x,Leaf xs)])


s1 = fromList [1,2,3,5,2]
s2 = fromList [2,3,5]

t1 = Node (M.fromList [(1,Leaf [2]),(3,Leaf [5]),(2,Node (M.fromList 
[(4,Leaf [6])]))])


t2 = insert (singleton (S.fromList [1])) $ S.fromList [1,2,3]

t3 = insert t1 $ S.fromList [2,4,7]

t4 = insert t2 $ S.fromList [1]

t5 = insert t3 $ S.fromList [2,5]

t6 = insert t5 $ S.fromList [2,4]

-- Now add a superset of everything
t7 = insert (singleton (S.fromList [8])) $ S.fromList [1,2,3,4,5,6,7,8,9]


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


[Haskell-cafe] Converting typeset mathematics into Haskell ?

2009-08-21 Thread Mark Wassell
Does anyone know of any papers or projects, either for Haskell or any 
other language, that relate to what I am going to attempt to describe in 
the following:


Go to any paper or book that includes some amount of calculation type 
mathematics. An example is the formula in the Description section of 
http://en.wikipedia.org/wiki/K-means_clustering.


Think about how you would convert this into Haskell. You might then find 
yourself wondering why you have to convert it into Haskell at all. Given 
that most mathematics online is typeset using something like latex or 
mathml, why can't we parse this typesetting and convert it into Haskell 
code? In all likelyhood the conversion might be ambiguous so some rules 
might be needed to guide the conversion.


Furthermore, if there are editors that allow you to edit these sorts of 
equations in a wysiwyg style, why not leverage these to edit the 
Haskell+Math code also in a wysiwyg style.


I think this goes to the larger question of why are most programming 
languages (or to be more exact the way we write programs in those 
languages) is still based around a linear sequence of tokens rather than 
something that is more 2D (there is still some linearity as even in math 
formula there is still a top down and left to right flow).


Mark

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


[Haskell-cafe] Using -Nx Option with GHC

2009-08-08 Thread Mark Wassell

Hi,

I am trying to compile and run my program so that it utilises more than 
one core on my machine. I have looked at 
http://haskell.org/haskellwiki/Shootout/Parallel/BinaryTrees and am 
using parMap at a point in my code.


I compile with

ghc --make -O2 -threaded

and run with the options

+RTS -N5

The runtime complains that it doesn't understand the N option.

I am running 6.10.4 on Windows XP.

Cheers

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


Re: [Haskell-cafe] Using -Nx Option with GHC

2009-08-08 Thread Mark Wassell

That did it, thanks.

Neil Mitchell wrote:

Hi Mark,

  

I compile with

ghc --make -O2 -threaded



That should work - try deleting all .o/.obj files and the executable
and trying to compile again.

Thanks

Neil

  

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


Re: [Haskell-cafe] Hsmagick crash

2009-06-08 Thread Mark Wassell
Have you tried 
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/pngload ?


Mark


Ron de Bruijn wrote:

Hi,

I am trying to extract the image data from various file formats and it 
appeared that hsmagick would be the right package to use.


However, it doesn't actually work or I use it incorrectly. If you have 
installed hsmagick and change the value of some_png_file to some 
existing png file, you should see that it crashes at some random 
pixel. For the particular 256*256 image I had, it crashed on pixel_nr 
`elem` [54,56,57].


I am open to suggestions for better ways to get a Array (Int,Int) RGB 
from e.g. a png file.


import Graphics.Transform.Magick.Images
import Graphics.Transform.Magick.Types
import Foreign.Storable
import Control.Monad

image_file_name_to_2d_array file =   do
himage - readImage file
let ptr_to_image = image himage
himage_ - peekElemOff ptr_to_image 0
let bounds@(_rows, _cols) = (rows himage_,columns himage_)
number_of_pixels  = fromIntegral _rows * fromIntegral _cols
mapM (\pixel_nr - do
   putStrLn (Pixel:  ++ show pixel_nr)
   pixel_packet - liftM background_color_  $
 peekElemOff
  ptr_to_image
  pixel_nr
   let red_component = red pixel_packet
   putStrLn (Pixel packet:  ++ show red_component)
   return red_component)
  [0.. number_of_pixels - 1]

some_png_file = foo.png

t = do
  initialize_image_library
  image_file_name_to_2d_array some_png_file

initialize_image_library = initializeMagick

Best regards,
 Ron de Bruijn
___
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] Function Returning Type?

2009-05-21 Thread Mark Wassell




To the original poster: next time, just leave the function definition 
without the signature and query GHCi for the correct type:

Remember that the type checker is your friend; let it work for you :)

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


Re: [Haskell-cafe] ANNOUNCE: vacuum-cairo: a cairo frontend to vacuum for live Haskell data visualization

2009-03-31 Thread Mark Wassell
Great work. However I am have a problem running on windows - it needs 
librsvg:


Prelude System.Vacuum.Cairo view [1]
Loading package mtl-1.1.0.2 ... linking ... done.
Loading package parallel-1.1.0.0 ... linking ... done.
Loading package glib-0.10.0 ... linking ... done.
Loading package cairo-0.10.0 ... linking ... done.
Loading package svgcairo-0.10.0 ... can't load .so/.DLL for: librsvg-2-2 
(addDLL: could not load DLL)

Prelude System.Vacuum.Cairo

Anyone know where I can get this? I have googled around and whilst there 
is the librsvg development site, there is no sign of a windows DLL.  All 
I can find is some generic site which seems to provide DLLs. I don't 
trust it.


Cheers

Mark

Don Stewart wrote:

I am pleased to announce the release of vacuum-cairo, a Haskell library
for interactive rendering and display of values on the GHC heap using
Matt Morrow's vacuum library.

This library takes vacuum's output, generates dot graph format from it,
renders it to SVG with graphviz, and displays the resulting structure
using the gtk2hs Cairo vector graphics bindings ... all at the GHCi
command line.

This tool is useful for examining Haskell data structures as they are
represented directly in the heap. In particular, it makes sharing visible for
the first time, as well as unboxed values. It should be useful for
teaching Haskell, or for library authors debugging the design of their
data structures.

You can see pictures of the rendered display here:

http://code.haskell.org/~dons/images/vacuum/intmap.png

And youtube screencasts of vacuum-cairo in action:

http://www.youtube.com/watch?v=oujaqo9GAmA

Get it:

cabal install vacuum-cairo

And on Hackage:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/vacuum-cairo

-- Don
___
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] Problem with cabal-install where package requires* mutually exclusive versions of another package

2009-03-14 Thread Mark Wassell
I am trying install a package using cabal-install however the package 
requies an older version of QuickCheck and one of the required packages 
requires the latest version:


$ cabal fetch Reactive

Resolving dependencies...
cabal.exe: cannot configure Stream-0.3.1. It requires QuickCheck =2.0
For the dependency on QuickCheck =2.0 there are these packages:
QuickCheck-2.1 and QuickCheck-2.1.0.1. However none of them are available.
QuickCheck-2.1 was excluded because checkers-0.1.3 requires QuickCheck 2.0
QuickCheck-2.1 was excluded because reactive-0.10.5 requires QuickCheck 2.0
QuickCheck-2.1.0.1 was excluded because checkers-0.1.3 requires QuickCheck
2.0
QuickCheck-2.1.0.1 was excluded because reactive-0.10.5 requires QuickCheck
2.0

How can I get around this? I could work around this and install the 
packages individually. Can I have two versions of a package installed 
(ie QuickCheck) and will everything get resolved correctly?


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


[Haskell-cafe] Physics engines purely in Haskell?

2008-11-08 Thread Mark Wassell
Has anyone thought about or embarked on the task of developing a 2D or 
3D physics engine purely in Haskell?


There is Hipmunk but I'm wondering about a purely Haskell 
implementation; possibly a port of Chipmunk to Haskell.


Mark



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


Re: [Haskell-cafe] Re: ghc-6.11 + OpenGL/GLUT crashes on WinXP

2008-10-29 Thread Mark Wassell

Hi,

Works here:

Windows XP SP 3
ghc-6.10.20081007
glut32 from http://www.xmission.com/~nate/glut.html

Don't know if this will help:

DLLS loaded

glut32.dll0x10000x38000C:\WINDOWS\glut32.dll
opengl32.dll0x5ed00xcc000C:\WINDOWS\system32\opengl32.dll
glu32.dll0x68b20x2C:\WINDOWS\system32\glu32.dll
ddraw.dll0x73760x4b000C:\WINDOWS\system32\ddraw.dll
dciman32.dll0x73bc0x6000C:\WINDOWS\system32\dciman32.dll
msvcrt.dll0x77c10x58000C:\WINDOWS\system32\msvcrt.dll
advapi32.dll0x77dd0x9b000C:\WINDOWS\system32\advapi32.dll
rpcrt4.dll0x77e70x92000C:\WINDOWS\system32\rpcrt4.dll
gdi32.dll0x77f10x49000C:\WINDOWS\system32\gdi32.dll
secur32.dll0x77fe0x11000C:\WINDOWS\system32\secur32.dll
kernel32.dll0x7c800xf6000C:\WINDOWS\system32\kernel32.dll
ntdll.dll0x7c900xaf000C:\WINDOWS\system32\ntdll.dll
user32.dll0x7e410x91000C:\WINDOWS\system32\user32.dll

Some of the versions

opengl32.dll OpenGL DLL (Microsoft) Version 5.01.2600.5512
glu32.dll OpenGL Utility Library DLL (Microsoft) Version 5.01.2600.5512
ddraw.dll - DirectDraw (Microsoft) 5.03.2600.5512
dciman32.dll - DCI Manage (Microsft) 5.01.2600.5512.
glut32 had no version info.

DirectX 9.0c (always thought OpenGL and DirectX were orthogonal but 
ddraw.dll  is being used).


Mark


Conal Elliott wrote:
No display lists.  The crash happens during the GLUT call 
initialize.  I can trigger it from ghci with the following simple 
incantation:


 Prelude import Graphics.UI.GLUT
 Prelude Graphics.UI.GLUT initialize foo []

And no trouble under ghc 6.9.20080622.

Stumped.  :(

- Conal

On Tue, Oct 28, 2008 at 3:14 PM, Jefferson Heard 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:


Conal, are you using display lists at all?  I've had problems with
allocating lists, but you seem to be able to leave off the allocation
step in Windows on nVidia cards so long as you're careful not to
conflict names yourself.

On Tue, Oct 28, 2008 at 4:03 PM, Matti Niemenmaa
[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] wrote:
 Conal Elliott wrote:
 I am using glut32 rather than freeglut (and no need for
patching the darcs
 GLUT).  I wonder if glut32-vs-freeglut could account for
crash-vs-nocrash on
 6.10 and 6.11 but not 6.9.  I'd love to hear from someone on
Windows and
 glut32.

 Windows XP with SP3
 ghc-6.10.20081007
 glut32

 Works fine for me.

 Taking a look at my GL headers, I did have to mess with at least
glut.h to get
 something to work---whether it was to build HOpenGL, to make
programs linkable,
 or to make them runnable, I'm not sure. In any case, what I did
was force
 GLUTAPIENTRY to be #defined as __stdcall.

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




--
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

-- Jessica Edwards
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org mailto: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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Mark Wassell


Hugh Perkins wrote:
That works just fine as long as the only thing eval has to cope with 
is print statements (so eval has type IO ()), but I'm guessing the 
clean solution is to thread a Map.Map through that somehow?


You could do that but your code starts to become messy and you'll hit 
other limitations. The standard approach to this problem is to use a 
State monad. Since you are already using one monad, IO, you can can 
stack the monads using Monad transformers which makes them both 
available (although you will need to use liftIO, see below)


import Control.Monad
import Control.Monad.State
import Data.Map

type Env = Map String String
type InterpM = StateT Env IO 


eval :: a - InterpM t

instance Eval Print where
  eval (Print value) = liftIO $ putStrLn value

You access and store the state using get and put. For example:

eval (Variable s) = do
   s - get
   lookup the value and return it.

There is a paper on using Monads with interpreters 
(http://web.cecs.pdx.edu/~mpj/pubs/modinterp.html) and an example 
described at http://www.haskell.org/haskellwiki/Libraries_and_tools/HJS.


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


Re: [Haskell-cafe] Frag

2007-07-14 Thread Mark Wassell

Donald Bruce Stewart wrote:

jon:
  

I just stumbled upon this fast action 3D shooter written entirely in Haskell:

  http://haskell.org/haskellwiki/Frag

After 15 minutes trying to build it I find that it segfaults. Can anyone else 
get this to work?



Likely depends on your OpenGL version, and possibly even graphics card. 


It's not been updated in about a year and half, but last time I tried
it, it worked fine. Anyone with a bit more OpenGL-fu able to test it
against current HOpenGL?
  
Builds easily and works for me with GHC 6.6.1 on widows (though). You 
need to specify a level when running it and you will get a series of 
messages about loading textures before the window appears. Does it get 
this far?


Cheers

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


[Haskell-cafe] SWIG with Haskell ?

2007-05-21 Thread Mark Wassell

Hello,

Has anyone got any pointers on using SWIG with Haskell to integrate a 
C++ library? For the library there other language bindings, so I am in a 
position to leverage off these.


In general what are the particular issues with C++ and Haskell. One 
obvious one is management of object lifecycle - making sure the object 
stays around long enough but doesn't out stay its welcome. Is using 
ForeignPtr sufficient?


Cheers

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


[Haskell-cafe] Happy outputs parE - ideas on what to change in my .y file?

2007-01-27 Thread Mark Wassell
Sometimes happy outputs 'parE' when I run it on my .y file? I believe it 
is coming from a part of Grammer.lhs which has the comment line


This bit is a real mess, mainly because of the error message support.

Are there any suggestions on what to change in my .y file to get over this?

Thanks

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


[Haskell-cafe] Composing monads (sort of)

2006-12-16 Thread Mark Wassell

Hi,

I have a set of functions:

f1 :: DBRecord - Maybe Int
f2 :: Int - IO Maybe DBRecord
f3 :: DBRecord - Maybe Int

The odd numbered functions are field accessors, accessing a field that 
might hold an identifier for another record. The even numbered functions 
are record fetch functions that get records from the database. I want to 
compose these so that I can navigate structures of joined records in the 
database.


How can I concisely compose these functions without having to write a 
cascade of case statements such as:


case f1 rec1 of
Nothing - return Nothing
Just id1 - do
rec2 - f2 id2
return $ case rec2 of
Nothing - return Nothing
Just rec2' - case f3 rec2' of

I understand that if I was just dealing with Maybe I could use the fact 
that Maybe is a monad. I am also not sure if composing the IO and the 
Maybe will get me what I want (some of the functions only return Maybe Int).


Cheers

Mark

PS Heard this on the 'West Wing' and thought it was appropriate in a way:

A coach goes up to a player and asks Are you ignorant or apathetic?. 
The player replies I don't know and I don't care.

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


Re: [Haskell-cafe] I'd like start with Haskell, but...

2006-12-16 Thread Mark Wassell

Hi,

Take a look at http://www.haskell.org/haskellwiki/HGene which uses HSQL 
and Gtk2hs. I don't have any code to release yet - only parts work and 
the code is in an extreme state of flux; I am currently refactoring (see 
my post on monads).


More generally you might be interested in the other page that I have started

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

Mark


Duncan Coutts wrote:

On Sat, 2006-12-16 at 19:50 +0100, Waldemar Biernacki wrote:
  
Hello! 


I'd like to start programming in Haskell.
But as an industry programmer I have a hope to use Haskell in my every-day 
work. Big part of my every-day work are GUI applications (in MS-Windows) 
working with SQL databases (PostgreSQL on Linux servers).


My question: Is there a TRUE possibility to use Haskell for such applications? 
Is anybody there who have ANY experience in the field?
If answer would be positive what GUI+database libraries could be used in such 
a case?



I don't actually know of anyone using one of the GUI libs in combination
with one of the DB libs. It's an obvious thing to do but you'll not find
a lot of pre-existing examples or infrastructure to help you.

That's certainly one of the use cases that we're aiming for in the
Gtk2Hs project with our new api for the list/tree widget system. We can
now more easily implement the data model in Haskell so the obvious thing
to try would be a model based on a DB query. We're aiming for a Gtk2Hs
release with this new api before xmas.

For databases there are three major libs you could use, HDBC, HSQL, and
HaskellDB. HSQL and HDBC are in essentially the same niche, they provide
a common medium level api to a bunch of different db backends. They work
at the level of taking SQL strings and returning result sets. HaskellDB
is a higher level library (that can use HDBC or HSQL). It provides a
type safe way of constructing queries (and internally generates SQL).

So personally what I'd try would be Gtk2Hs+HDBC or Gtk2Hs+HDBC+HaskellDB.

  
I've seen some GUI libraries web pages, but they seem to be NOT maintenanced 
any more. 



There are several GUI libs that were started but not maintained. The
main ones that are maintained are Gtk2Hs and wxHaskell.

For platform support you're fine, all those DB libs support PostgreSQL
and both GUI libs support Windows, Linux and others.

Duncan

___
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