Re: [Haskell-cafe] state and exception or types again...
Il Tue, Aug 29, 2006 at 10:02:38AM +0100, Brian Hulley ebbe a scrivere: Hi! Ím getting back so late because it took me a while to understand monadic transformation... data Result a = Good a State Output | Bad State Output deriving Show ... case runSOIE m x of Good a y o1 - case runSOIE (f a) y of Good b z o2 - Good b z (o1 ++ o2) Bad z o2 - Bad z (o1 ++ o2) Bad z o2 - Bad z o2 -- (*) This is brilliant and highly instructive (for me at least)!! Thank you very much. Regards, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] data structures question
Hi, Having read some tutorials, I would like to start using Haskell for real, but I have some questions about data structures. The mathematical description of the problem is the following: assume there is a function V(a,b,theta), where a and b can have two values, High or Low, and theta is a number between zero and n (n is given). The range of V is the real numbers. Then there is an algorithm (called value iteration, but that's not important) that takes V and produces a function of the same type, called V'. The algorithm uses a mapping that is not elementwise, ie more than the corresponding values of V are needed to compute a particular V'(a,b,theta) -- things like V(other a,b,theta) and V(a,b,theta+1), where data State = Low | High other :: State - State other High = Low other Low = High Question 1: V can be represented as a 3-dimensional array, where the first two indices are of type State, the third is Int (= n). What data structure do you suggest in Haskell to store V? Is there a multidimensional array or something like this? Let's call this structure TypeV. Question 2: I would like to write valueit :: TypeV - TypeV valueit V = mapondescartesproduct [Low,High] [Low,High] [0..n] mapV where -- mapV would calculate the new V' using V -- mapV :: State - State - Int - Double to fill the new data structure. How to do this sensibly? Thanks, Tamas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] data structures question
Tamas K Papp wrote: Hi, Having read some tutorials, I would like to start using Haskell for real, but I have some questions about data structures. The mathematical description of the problem is the following: assume there is a function V(a,b,theta), where a and b can have two values, High or Low, and theta is a number between zero and n (n is given). The range of V is the real numbers. Then there is an algorithm (called value iteration, but that's not important) that takes V and produces a function of the same type, called V'. The algorithm uses a mapping that is not elementwise, ie more than the corresponding values of V are needed to compute a particular V'(a,b,theta) -- things like V(other a,b,theta) and V(a,b,theta+1), where data State = Low | High other :: State - State other High = Low other Low = High Question 1: V can be represented as a 3-dimensional array, where the first two indices are of type State, the third is Int (= n). What data structure do you suggest in Haskell to store V? Is there a multidimensional array or something like this? Read http://haskell.org/haskellwiki/Modern_array_libraries It sounds like you need Data.Array (lazy) or Data.Array.Unboxed (strict) Let's call this structure TypeV. Question 2: I would like to write valueit :: TypeV - TypeV valueit V = mapondescartesproduct [Low,High] [Low,High] [0..n] mapV where -- mapV would calculate the new V' using V -- mapV :: State - State - Int - Double to fill the new data structure. How to do this sensibly? Your definition is almost clear. mapV takes the i :: (State,State,Int) index of an entry in V' and takes the whole old array V and computes the value at location i in V'. data State = Low | High deriving (Eq,Ord,Ix) -- assuming Ix is derivable... type TypeV = Array (State,State,Int) Double -- or UArray instead of Array mapV :: TypeV - (State,State,Int) - Double mapV = undefined valueit :: TypeV - TypeV valueit oldV = listArray (minI,maxI) [ mapV oldV i | i - range (minI,maxI) ] where minI = (Low,Low,0) maxI = (High,High,n) -- or move mapV to where clause; it can still use oldV valueit :: TypeV - TypeV valueit oldV = listArray (minI,maxI) [ mapV i | i - range (minI,maxI) ] where minI = (Low,Low,0) maxI = (High,High,n) mapV :: (State,State,Int) - Double mapV = undefined Thanks, Tamas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to force HTML (rather than XML) output from Haskell XML Toolbox?
which is close but not exactly as wanted. The meta (and I expect other tags like br will have the same) tag has closing slash as it would have in XML (XHTML), but not in HTML. Also the DOCTYPE has been lost. I've had similar problems outputting XHTML. For example, naive output (correct according to the definition of XML and (X)HTML) breaks in IE because IE doesn't like link ... / or script ... / tags, instead it wants link .../link and script .../ script. Pages with correct XHTML, but with these unhappy tags in the HTML head, load in IE as a blank page! To make pages that will load in 90% of browsers, I've always generated my own (X)HTML with special pretty printers that know these caveats and a few others. Jared. On 8/30/06, Dimitry Golubovsky [EMAIL PROTECTED] wrote: Hi, I am developing a code that reads a HTML page (template), modifies it (adds some stuff) and then writes the output file which is to be HTML, not XML. I use hxt-5.3 (but I may upgrade if necessary). It is desired to preserve the original HTML template pieces maximally close to the original. But output appears to be closer to XML rather than HTML. The code I use: let attrs = [(a_parse_html, 1), (a_output_xml, 0), (a_encoding, utf8)] (res, err, rc) - getXmlDocument attrs (fromJust $ tmplPath dopt) putXmlDocument attrs (fromJust $ outPath dopt) res = for this input HTML file: = !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head titleEmpty Page Template for Haskell Applications/title meta http-equiv=content-type content=text/html; charset=UTF-8 /head body /body /html = outputs: = html head titleEmpty Page Template for Haskell Applications/title meta http-equiv=content-type content=text/html; charset=UTF-8/ /head body /body /html = which is close but not exactly as wanted. The meta (and I expect other tags like br will have the same) tag has closing slash as it would have in XML (XHTML), but not in HTML. Also the DOCTYPE has been lost. Is this something hxt is not able to provide, or just a bug fixed since 5.3? Or should I write my own output code (because I am guessing, hxt functionality regarding manipulation over XML trees is sufficient for what I need)? Or should I use another package? -- Dimitry Golubovsky Anywhere on the Web ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.updike.org/~jared/ reverse )-: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to force HTML (rather than XML) output from Haskell XML Toolbox?
Hi which is close but not exactly as wanted. The meta (and I expect other tags like br will have the same) tag has closing slash as it Just a bit of info on the br, IE treats br/ as a line break, but br/br as 2 line breaks. Just in case you go for the obvious solution of always expanding out a/ to a/a, br won't work. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to force HTML (rather than XML) output from Haskell XML Toolbox?
Just a bit of info on the br, IE treats br/ as a line break, but br/br as 2 line breaks. Just in case you go for the obvious solution of always expanding out a/ to a/a, br won't work. but br / with a space works. And this applies to most tags with this behavior---the space helps, and it validates with W3C XHTML Validator. Jared. -- http://www.updike.org/~jared/ reverse )-: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ReadP question
Udo Stenzel wrote: Chris Kuklewicz wrote: Again, Parsec requires you to put try where you need it I'm pretty sure it does, although this Udo Stenzel wrote: countBetween 0 n p = p : countBetween 0 (n-1) p | return [] is a place where it's not needed in general. You should know what you're doing, though. And I like ReadP better in general, exactly because 'try' is a bit trippy. Udo. I just tried to mimic regular expression matching with ReadP and got what seems like a non-terminating program. Is there another way to use ReadP to do this? import Control.Monad import Text.ParserCombinators.ReadP type R = ReadP Int -- Consume a specific character, return length 1 c :: Char - R c x = char x return 1 -- Consume like x? x+ x* and return the length quest,plus,star :: R - R quest x = option 0 x plus x = liftM sum (many1 x) star x = liftM sum (many x) -- Concatenate two with sum of lengths infixr 5 + (+) :: R - R - R (+) x y = liftM2 (+) x y -- Concatenate list with running total of length match xs = match' xs 0 where match' [] t = return t match' (x:xs) t = do v - x match' xs $! t+v -- Simulate (a?|b+|c*)*d regular expression test = star (choice [quest (c 'a') ,plus (c 'b') ,star (c 'c')]) + c 'd' go foo = readP_to_S test foo 'go' works if I remove the leading 'star' operation from 'test' But 'go' seems to not terminate with the leading 'star' My regex-dfa package has a failure which seems similar, and I have been adding the ability to internally rewrite the pattern to avoid the problem. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: data structures question
Benjamin Franksen wrote: Matthias Fischmann wrote: The trick is that Int is not the only index data type, but tuples of index data types are, too. Do this: | type Point = (State, State, Int) | type TypeV = Array State Double | | matrix :: TypeV | matrix = array bounds values |where |... Surely you meant to say | type TypeV = Array Point Double Cheers, Ben And type Value = Double newtype PointNat = PointNat Int deriving (...Ix) type Point = (State,State,PointNat) Or even type TypeVof a = Array PointNat a type TypeV = TypeVof Value I did not even run the code I wrote through ghci, I was just showing what it could look like. And stop calling me Shirley. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] monadplus as monoid, safe?
I'm using the following code in some of my projects: newtype MonadPlusAsMonoid a = MPM { unMPM :: a } instance MonadPlus m = Monoid (MonadPlusAsMonoid (m a)) where mempty = MPM mzero MPM l `mappend` MPM r = MPM (l `mplus` r) Is there some sort of pitfall I'm not considering? It seems fine to me, but I ask because I couldn't find this instance in the darcs repo for the next base library package. I expected to find it there because it has similar instances for numbers as monoids (e.g. Sum and Product from Data.Monoid). Thanks, Nick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: monadplus as monoid, safe?
Of course I find it two minutes after I send the question. Sorry for the two noop emails. Nick On 8/30/06, Nicolas Frisby [EMAIL PROTECTED] wrote: I'm using the following code in some of my projects: newtype MonadPlusAsMonoid a = MPM { unMPM :: a } instance MonadPlus m = Monoid (MonadPlusAsMonoid (m a)) where mempty = MPM mzero MPM l `mappend` MPM r = MPM (l `mplus` r) Is there some sort of pitfall I'm not considering? It seems fine to me, but I ask because I couldn't find this instance in the darcs repo for the next base library package. I expected to find it there because it has similar instances for numbers as monoids (e.g. Sum and Product from Data.Monoid). Thanks, Nick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] haskell - fpga
Hi, Does anybody know of any compilers that can compile portions of a haskell program to an FPGA? I have found a few domain-specific languages implemented in haskell for FPGAs, but so far no back-ends for compilers like ghc. Thanks, Matthew ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] haskell - fpga
General Haskell constructs map really poorly to FPGAs. You could define a subset that maps nicely, though. But as far as I know noone has made such a compiler. It's a rather big undertaking. You could look at Cryptol and Bluespec, they are languages with similarities to Haskell better suited for hardware. -- Lennart On Aug 30, 2006, at 17:30 , Matthew Pocock wrote: Hi, Does anybody know of any compilers that can compile portions of a haskell program to an FPGA? I have found a few domain-specific languages implemented in haskell for FPGAs, but so far no back-ends for compilers like ghc. Thanks, Matthew ___ 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] ReadP question
On 8/30/06, Chris Kuklewicz [EMAIL PROTECTED] wrote: -- Simulate (a?|b+|c*)*d regular expression But 'go' seems to not terminate with the leading 'star' Unless I'm missing something... The part of the pattern inside the parentheses should successfully match at least the empty string at the beginning of the string. Since it's regulated by the second (outer) 'star', it will keep matching as long as it keeps succeeding; since it keeps matching the empty string, it keeps matching forever in the same spot. To solve this problem, your implementation of 'star' could perhaps be changed to answer no more matches rather than infinitely many matches once the body fails to consume any characters. Hope this helps! --Tom Phoenix ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Galois Connections seeking a developer
Galois is seeking a full-time candidate for software development and systems integration in the field of high assurance computing. A successful candidate should have a good understanding of the inner workings of databases, good development skills in a number of languages, including at least one functional language (preferably Haskell), and web development. The candidate should have excellent Linux and Unix skills. If the candidate does not know Haskell, they should be good at learning new programming languages, and can reasonably expect to be fluent in Haskell within a few months. Tasks: * Database analysis * Python and PHP web development * Learning and adapting Linux-related technologies including Xen, SELinux, and Knoppix * Creating or modifying Debian packages * Haskell development Knowledge: * Databases implementation internals * Web development, Services-Oriented Architectures * Fluent in Haskell or other functional languages * Grounding in computer security * XML * Linux and Unix Nice-to-have: * Extreme Programming (XP) development experience * Experience deploying software products * Open source software development experience * Ability to get US security clearance Education: * Masters degree or equivilent experience Please respond with a resume and a cover letter explaining your fit to [EMAIL PROTECTED] Feel free to forward to interested parties. peace, isaac ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe