Re: [Haskell-cafe] Explaining monads
Hello, There is clearly a problem with the Haskell/monad tutorials out there... The tutorials seriously need to step back and start with something like, To enforce order of evaluation we evaluate closures* returning a defined type. The first closure will feed its result to the second which will in turn feed it's result to the third. Since the third closure can't be evaluated without having the results from the second and first (and thus they had to be evaluated earlier in time) we get a defined evaluation sequence. Here are some examples... The style of this description is nice; however the description itself is wrong. Monads DO NOT determine order of evaluation. Previous posts on this thread give several examples. In lazy languages, data dependencies determine the order of evaluation. X must be evaluated before Y if Y depends upon the result of X. You can force the order of evaluation without using a monad just as you can have a monad which does not determine the order in which things get evaluated. From the point of view of a programmer, a monad is simply a useful (higher-order) combinator pattern. All monadic code can be flattened by replacing occurrences of bind (=) with it's definition. One general intuition about monads is that they represent computations rather than simple (already computed) values: x :: Int -- x is an Int x :: Monad m = m Int -- x is a computation of an Int x :: [Int] -- x is a computation of an Int which can return multiplie values x :: Maybe Int -- x is a computation of an Int which might fail (return Nothing) x :: State s Int -- x is a computation of an Int which relies on, and returns (possibly modified) -- a value of type s. Note: State s Int is isomorphic to: s - (Int,s) x :: IO Int-- x is a computation of an Int which can interact with the outside world. Return explains how to make a simple computation which returns a specified value. Bind explains how to use the result of a computation to compute something else. -Jeff --- 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] Explaining monads
Hello, Look! You are doing it again! :) Does that paragraph even contain the word Monad? :) Sorry. Your first paragraph led me to believe you were writing about monads. I'm aware a monad is an abstraction and as such it doesn't *do* anything. My point was along the lines that you don't need to know that your working in a field to be able to learn that 3/2 = 1.5 I agree. I think one of the problem with understanding monads comes from people mistakenly believing monads force an order of evaluation. This is a shortcoming of general Haskell tutorials which fail to convey that the order of evaluation is determined by data dependencies. If new programmers know that monads have nothing to do with forcing the order of evaluation when they start learning about monads, then maybe they will be less confused as they sort out what monads are actually used for. -Jeff --- 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] Explaining monads
Hello, On 8/14/07, Jeff Polakow [EMAIL PROTECTED] wrote: One general intuition about monads is that they represent computations rather than simple (already computed) values: x :: Int -- x is an Int x :: Monad m = m Int -- x is a computation of an Int What's a computation? It seems to me that in a lazy language, x::Int represents a computation of an int, not an already computed value. This intuition for monads as computations is independent of operational semantics. x::[Int] is a computation that returns multiple values. x::(Int,Int) is a computation that returns a pair of values. x::() is a computation that returns nothing. x::Map a b is a computation that gives a way to associate values of type a with values of type b. Some of these are monads, some are not. What's the difference between them? Why are you calling certain values computations? Of course, the type [Int] denotes a value which is a list of Ints; additionally [Int] can be viewed as a value representing the nondeterministic computation of a single Int. Generally, the type Monad m = m Int can be viewed as a value representing the computation of an Int. However, I do not mean to imply that everything which can be viewed as a computation of something is a monad. In any case, this is only meant to be a general (i.e. high-level) intuition. BTW, this intuition was, more or less, the one used by Moggi when describing how monads can be used to describe denotational models for languages. -Jeff --- 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] Explaining monads
Hello, On 14/08/07, Jeff Polakow [EMAIL PROTECTED] wrote: Of course, the type [Int] denotes a value which is a list of Ints; additionally [Int] can be viewed as a value representing the nondeterministic computation of a single Int. Generally, the type Monad m = m Int can be viewed as a value representing the computation of an Int. But thats not really right. What exactly m Int does /depends/ on m. It might represent 0 or more computations of Int, or computations of Int carrying some extra stuff around, or complex control logic about what the computation does when. Perhaps the confusion is in the word computation. I'm using the word in an abstract sense. I do not mean the actual execution of Haskell code to produce a value. Thus, under this intuition: The type Int represents a value which denotes an Int. The type m Int denotes a value which is a single computation (for an unspecified notion of computation) of an Int. A specific computation of an Int might result in several, or zero, actual Ints (the list monad); a String or an Int (the Either String monad); the constant () (the trivial monad); ... The type Monad m = m Int cannot represent multiple computations of an Int. The type Monad m = [m Int] represents multiple computations of an Int (of course, any container type can be used in place of list). -Jeff --- 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] Re:Explaining monads
Hello, Hence the need to perform a run operation like runIdentity, evalState or runParser (for Parsec) to get something useful to happen. Except for lists we don't seem to do this. I suppose lists are so simple that the operators :, ++ and the [] constructor do all we ever need with them. Finally there is no runIO because main is essentially that function in every real program? - Greg For lists, head is probably the simplest run operation. As Brian noted earlier unsafePerformIO is a way to run IO computations within your code; but doing so breaks the abstraction of IO as being the outside world. -Jeff --- 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] Re: Is take behaving correctly?
Hello, There are 4 variants of tail: tail :: [a] - [a] -- normal tailDef :: [a] - [a] - [a] -- returns the first argument on [] tailMay :: [a] - Maybe [a] -- returns a Nothing tailNote :: String - [a] - [a] -- crashes, but with a helpful message tailSafe :: [a] - [a] -- returns [] on [] Is there a reason for not having tailM :: Monad m = [a] - m [a] which, at least for me, is much more useful? -Jeff --- 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] agda v. haskell
Hello, Agda is essentially an implementation of a type checker for Martin-Lof type theory (i.e. dependent types). It is designed to be used as a proof assistant. Roughly speaking propositions are represented as types and a proof of a proposition is a well-typed, total and terminating function. Agda has machinery to help you fill in cases and generally make proof construction easier. Agda is different from Haskell in that Agda has dependent types and machinery for interactively constructing the definition of a function at a given type. Agda is also different from Haskell in that the focus is on the user interface and writing the proof/program itself, rather than on executing the resulting code (i.e. little work has gone into compiling Agda code). I think there have been several projects scattered around on generating Haskell from Agda and on importing Haskell code into Agda for formal verification. -Jeff [EMAIL PROTECTED] wrote on 09/28/2007 11:41:41 AM: dons has been posting some links regarding agda on reddit. fairly interesting, a quick glance and you think you are reading haskell code. does anyone have any insights on the major differences in these languages? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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] Strictness leak
Hello, countIO :: String - String - Int - [a] - IO [a] countIO msg post step xs = sequence $ map unsafeInterleaveIO ((blank outmsg (0::Int) c):cs) where (c:cs) = ct 0 xs output = hPutStr stderr blank= output ('\r':take 70 (repeat ' ')) outmsg x = output ('\r':msg++show x) hFlush stderr ct s ys = let (a,b) = splitAt (step-1) ys next = s+step in case b of [b1] - map return a ++ [outmsg (s+step) hPutStr stderr post return b1] [] - map return (init a) ++ [outmsg (s+length a) hPutStr stderr post return (last a)] _ - map return a ++ [outmsg s return (head b)] ++ ct next (tail b) It wraps a list with IO operations, so that progress can be reported while evaluating the list elements. Unfortunately, there seems to be a stricness leak here - and consequently, it does not work on an infinite list. Besides anything else, sequence will diverge on an infinite list. This can be seen directly from the type: sequence :: Monad m = [m a] - m [a] It is necessary to compute all of the computations in the list before returning any of the pure resulting list. -Jeff --- 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] Strictness leak
I forgot to send this reponse to haskell-cafe earlier... Hello, You mean for the IO monad, right? Sorry. I meant divergence is unavoidable for any strict Monad, such as IO. However, sequence will always compute over the entire list; if the resulting computation itself is lazy then the result can be inspected lazily. take 10 $ execWriter $ sequence $ repeat $ tell ([3]::[Int]) This is a good example. Note that the computation of sequence itself is infinite. snd $ runWriter $ sequence (repeat $ tell [3]) = return . take 10 will result in an infinite list, but fst $ runWriter $ sequence (repeat $ tell [3]) = return . take 10 will return a 10 element list. -Jeff --- 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] Re: Semantics of uniqueness types for IO (Was: Why can't Haskell be faster?)
Hello, Just a bit of minor academic nitpicking... Yeah. After all, the uniqueness constraint has a theory with an excellent pedigree (IIUC linear logic, whose proof theory Clean uses here, goes back at least to the 60s, and Wadler proposed linear types for IO before anybody had heard of monads). Linear logic/typing does not quite capture uniqueness types since a term with a unique type can always be copied to become non-unique, but a linear type cannot become unrestricted. As a historical note, the first paper on linear logic was published by Girard in 1987; but the purely linear core of linear logic has (non-commutative) antecedents in a system introduced by Lambek in a 1958 paper titled The Mathematics of Sentence Structure. -Jeff --- 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] Re: Semantics of uniqueness types for IO
Hello, Just to continue the academic nitpicking.. :-) Linear logic/typing does not quite capture uniqueness types since a term with a unique type can always be copied to become non-unique, but a linear type cannot become unrestricted. Actually, that isn't quite accurate. In linear logic, a term with a non-linear type can always be regarded as having a linear type, i.e. U -o !U is a theorem (my favourite reading of this theorem is if you have an unlimited supply of bank notes, then you also have a single one). The implication in the opposite direction is a falsity (from the fact that we have a single bank note, we cannot decude that we have an unlimited supply). I think you mean !U -o U is a theorem. The converse is not provable. In any case, I think we are saying the same thing. -Jeff --- 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] Re: Semantics of uniqueness types for IO
Hello, I think you mean !U -o U is a theorem. The converse is not provable. Oops... I should read more carefully before hitting send. This is of course completely wrong. Sorry for the noise, Jeff --- 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] Re: Semantics of uniqueness types for IO
Hello, I think you mean !U -o U is a theorem. The converse is not provable. Oops... I should read more carefully before hitting send. This is of course completely wrong. This is embarrassing... I was right the first time. !U -o U is a theorem in linear logic. It can be read as given infinitely many U, I can get one U. U -o !U is not a theorem in linear logic. It can be read as given one U, I can get infintely many U. Sorry about the continued noise. -Jeff --- 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] type/class question: toString
Hello, Have you tried using -fglasgow-exts? That should enable all ghc extensions. -Jeff [EMAIL PROTECTED] wrote on 11/06/2007 02:02:11 PM: On Nov 6, 2007 12:15 PM, David Benbennick [EMAIL PROTECTED] wrote: In ghc 6.8.1, the error messages are more helpful: foo.hs:5:0: Illegal instance declaration for `MyShow String' (All instance types must be of the form (T t1 ... tn) where T is not a synonym. Use -XTypeSynonymInstances if you want to disable this.) In the instance declaration for `MyShow String' Thanks for the tip. I might give 6.8.1 a try; I still cannot get it to work in 6.6.1. The problem may exist between the keyboard and the chair. G ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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] fundeps and overlapping/undecidable instances
Hello, You should be able to use fundeps to do exactly what you describe below. Can you make a relatively small self-contained example which exemplifies the ugliness you see? -Jeff [EMAIL PROTECTED] wrote on 12/07/2007 11:24:35 AM: I have some type-level sets using fundeps working whereby equality and membership etc are predicate functions. This seems to leads to an explosion of ugly code, with `If' class constraints etc getting out of hand -- I want to treat these as relations instead so providing the definition describes everything that is 'in' and nothing that is 'out'. I've been using Oleg's paper on lightweight static resources [1] as a template for this. I want to do something like this (supposing I have an EQ relation, (:::) for consing): class Member x y instance EQ x y = Member x (y:::ys) instance Member x ys = Member x (y:::ys) But I can certainly see why this isn't possible (It's the equivalent of pattern-matching on the constraints I suppose). Do type families provide a way to do this kind of thing or do I need a different strategy altogether, involving GADTs or whatever? Thanks, [1] http://okmij.org/ftp/Computation/resource-aware-prog/tfp.pdf -- View this message in context: http://www.nabble.com/fundeps-and- overlapping-undecidable-instances-tf4962996.html#a14215583 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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] fundeps and overlapping/undecidable instances
Hello, Does the following code work for you? -Jeff --- {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances #-} data Nil = Nil data x ::: xs = x ::: xs infixr 5 ::: data HTrue = HTrue deriving Show data HFalse = HFalse deriving Show class Member x xs b | x xs - b where member :: x - xs - b instance Member x Nil HFalse where member _ _ = HFalse instance Member x xs b = Member x (x ::: xs) HTrue where member _ _ = HTrue instance Member x xs b = Member x (y ::: xs) b where member x (_ ::: xs) = member x xs {- member 'a' (() ::: a ::: '1' ::: Nil) == HTrue member 'a' (() ::: a ::: Nil) == HFalse -} --- 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] How to make Prelude.read: no parse more verbose ...
Hello, You can also just use reads which returns a list of (partial) parses. -Jeff [EMAIL PROTECTED] wrote on 12/19/2007 03:17:39 PM: Hi Well, how do I compile a Haskell program in such a way, that I get a useful error message from read? I mean, like the filename/linenumber of the calling expression for starters. I use the Safe library to do this sort of stuff: http://www-users.cs.york.ac.uk/~ndm/safe/ You can call readMay to get a maybe result, or readNote which gives an augmented error message on a crash. You can of course combine this with the CPP trick: #define read readNote (__FILE__++:++show __LINE__) Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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
[Haskell-cafe] ghc-pkg on Windows XP
Hello, I have installed ghc-6.4.2 on a windows XP machine. However, the machine refuses to execute ghc-pkg (thus preventing me from using Cabal) and complains that C:\ghc\ghc-6.4.2\bin\ghc-pkg.exe is not a valid Win32 application. Is there something obvious I might have overlooked while installing? Also, I am new to using ghc on windows and was wondering what are the trade-offs of using cygwin or minsys versus just living in a emacs shell? thanks, Jeff -- 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] Haskell performance in heavy numerical computations
honest, the documentation for Arrows blows my mind. I think a few examples would go a long way. John Hughes' original paper on arrows is full of examples. Additionally, Hughes wrote a tutorial on programming with arrows, for the 2004 AFP summer school in Tartu, which is very accessible. Both papers are available from Hughes' publication page. Also Ross Paterson wrote a piece called Arrows and Computation, available on the arrows homepage, which contains many illuminating examples. -Jeff -- 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
[Haskell-cafe] heap issues
Hello, Why would ghci run out of heap space (and crash) the second time I run a computation? More specifically, I have a ghci session which goes something like this: *Analysisrun [ ... print out of a very long list ...] *Analysisrun [ ... partial print out GHC's heap exhausted: current limit is 268435456 bytes; Use the `-Msize' option to increase the total heap size. Shouldn't the garbage collector free up everything in between my top-level function executions? Also, there doesn't appear to be a '-Msize' flag for ghc (I'm using 6.4.2 on windows xp). thanks, Jeff -- 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
[Haskell-cafe] ghc profiling
Hello, When I compile my program without profiling: bash-3.1$ ghc --make -auto-all -prof -O -o analysis analysis.hs Chasing modules from: analysis.hs Compiling Main ( analysis.hs, analysis.o ) Linking ... everything works fine. However when I compile with profiling: bash-3.1$ ghc --make -auto-all -prof -O -o analysis analysis.hs Chasing modules from: analysis.hs Could not find module `Data.ByteString.Lazy.Char8': use -v to see a list of the files searched for (imported from analysis.hs) ghc complains about not finding the ByteString library. Is this supposed to hapen, and if so, is there a way to get profiling to work? thanks, Jeff -- 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
[Haskell-cafe] hdbc linking errors
Hello, When trying to compile a standalone program using hdbc in cygwin, I get many linker errors. I have no problems using my code interactively with ghci. I am using the command line: ghc --make -package HDBC -package HDBC-odbc -O -o testExecute testExecute.hs Am I missing something? thanks Jeff -- 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] hdbc linking errors
Hello, I think my problem is a faulty ghc installation and not HDBC. sorry for the noise, Jeff [EMAIL PROTECTED] wrote on 10/31/2006 02:31:27 PM: Hello, When trying to compile a standalone program using hdbc in cygwin, I get many linker errors. I have no problems using my code interactively with ghci. I am using the command line: ghc --make -package HDBC -package HDBC-odbc -O -o testExecute testExecute.hs Am I missing something? thanks Jeff -- 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 -- 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] Designing an object model in Haskell
Have you looked at OOHaskell (http://homepages.cwi.nl/~ralf/OOHaskell/)? -Jeff [EMAIL PROTECTED] wrote on 12/07/2006 07:07:46 AM: Hi, I've got an object model that I have a difficult time conceptualising how it might look like in Haskell: class Element { } class Inline : Element { } class ParentInline : Inline { ListInline children; } class Bold : ParentInline { } class Underline : ParentInline { } class Link : ParentInline { String link; } class Text : Inline { String text; } class Block : Element { } class Paragraph : Block { ListInline paragraph; } class Heading : Block { ListInline heading; } class Document : Element { ListBlock blocks; } How best to represent this OO data model in Haskell? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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] Re: A suggestion for the next high profile Haskell project
Hello, PS: Talking about smart programs: Is there a library anywhere that could be used to implement expert systems in Haskell or to evaluate Horn clauses in Prolog style? Here is one possible starting point is the backtracking monad transformer by Oleg et al: http://okmij.org/ftp/Computation/monads.html#LogicT --Jeff --- 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
[Haskell-cafe] hsffig build problem
Hello, I am trying to install hsffig and I get the following error: bash$ make : : Linking cabal-setup.exe ... Distribution/Simple/Configure.o:fake:(.text+0x74fd): undefined reference to [EMAIL PROTECTED]' collect2: ld returned 1 exit status make: *** [cabal-setup] Error 1 I am using ghc6.6 in cygwin on windows XP. Has anyone else encountered and/or overcome this? thanks, Jeff --- 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] Mission: To take args from an n-tuple ... generally
Hello, I wondered, why not take an n-tuple of arguments s.t. multApply' :: (a1-a2-...-an-o) - (a1,(a2,(...(an,o)...))) - o I'm not sure what you're trying to do here. Why is there an o in the argument? Also, do you really mean the number of arguments expected to match the number of arguments given? Also you might want to check out Olegon polyvariadic functions: http://okmij.org/ftp/Haskell/vararg-fn.lhs -Jeff --- 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] Re: Re: Reflective capabilities of Haskell (cont'd)
Hello, Thanks a lot, this helps a bit, but access to function bodies is exactly what I need. Or being more precise, I need the functionality of ghci's command ':t'. So functions that behave as follows, where everything is of course meta-represented in some way as ADT: Prelude Data.Typeable typeOf (\a - (Just (a:))) (\a - (Just (a:))) :: Char - Maybe [Char] Prelude Data.Typeable getDomain $ typeOf (\a - (Just (a:))) [Char] Prelude Data.TypeablegetCodomain $ typeOf (\a - (Just (a:))) (Maybe [Char]) Data.Typeable should allow for all of the previous. Prelude Data.TypeablegetTypeConstructors (Maybe [Char]) [ (Just) :: [Char] - Maybe [Char] , (Nothing) :: Maybe [Char] ] Prelude Data.TypeablegetTypeConstructors [Char] [ (:) :: Char - [Char] - [Char] , ([]) :: [Char] ] Data.Generics allows you to do this (to a certain extent), i.e. there is a function dataTypeConstrs :: DataType - [Constr] -Jeff --- 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] Re: Re: Reflective capabilities of Haskell (cont'd)
Hello, Prelude Data.Typeable typeOf (\a - (Just (a:))) (\a - (Just (a:))) :: Char - Maybe [Char] Prelude Data.Typeable getDomain $ typeOf (\a - (Just (a:))) [Char] Prelude Data.TypeablegetCodomain $ typeOf (\a - (Just (a:))) (Maybe [Char]) Data.Typeable should allow for all of the previous. Prelude Data.TypeablegetTypeConstructors (Maybe [Char]) [ (Just) :: [Char] - Maybe [Char] , (Nothing) :: Maybe [Char] ] Prelude Data.TypeablegetTypeConstructors [Char] [ (:) :: Char - [Char] - [Char] , ([]) :: [Char] ] Data.Generics allows you to do this (to a certain extent), i.e. there is a function dataTypeConstrs :: DataType - [Constr] It might be hard, or even impossible, to get Data.Typeable and Data.Generics to play with each other. There seems to be no good way of converting a Data.Typeable.TypeRep to a Data.Generics.Basics.DataType. Another option might be to use Language.Haskell.Parser and Language.Haskell.Syntax, but I have little experience with this and am not sure if you'll be able to do what you want. -Jeff --- 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] List concat
Hello, The function (++) :: [x] - [x] - [x] has O(n) complexity. If somebody were to invent some type that looks like [x] but actually uses some sort of tree rather than a linked list, you should be able to get O(1) concatenation. Has anybody ever implemented such a thing? You can also do this with a functional representation of lists (i.e. lists are functions); this idea is usually called difference lists. There is a nice dlist library on hackage. -Jeff --- 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
[Haskell-cafe] GHC predictability
Hello, One frequent criticism of Haskell (and by extension GHC) is that it has unpredictable performance and memory consumption. I personally do not find this to be the case. I suspect that most programmer confusion is rooted in shaky knowledge of lazy evaluation; and I have been able to fix, with relative ease, the various performance problems I've run into. However I am not doing any sort of performance critical computing (I care about minutes or seconds, but not about milliseconds). I would like to know what others think about this. Is GHC predictable? Is a thorough knowledge of lazy evaluation good enough to write efficient (whatever that means to you) code? Or is intimate knowledge of GHC's innards necessary? thanks, Jeff PS I am conflating Haskell and GHC because I use GHC (with its extensions) and it produces (to my knowledge) the fastest code. --- 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] GHC predictability
Hello, For example, the natural and naive way to write Andrew's mean function doesn't involve tuples at all: simply tail recurse with two accumulator parameters, and compute the mean at the end. GHC's strictness analyser does the right thing with this, so there's no need for seq, $!, or the like. It's about 3 lines of code. Is this the code you mean? meanNat = go 0 0 where go s n [] = s / n go s n (x:xs) = go (s+x) (n+1) xs If so, bang patterns are still required bang patterns in ghc-6.8.2 to run in constant memory: meanNat = go 0 0 where go s n [] = s / n go !s !n (x:xs) = go (s+x) (n+1) xs Is there some other way to write it so that ghc will essentially insert the bangs for me? -Jeff --- 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] getting output from shell commands
Hello, I would like to be able to run a shell command like curl and process the output in my Haskell program, but I couldn't find anything helpful about it. Try looking in System.Process. runInteractiveProcess should work for you. -Jeff --- 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
[Haskell-cafe] Announce: Fortress talk in New York City
Hello, There will be a talk on Fortress ( a new OO/Functional language from Sun) on Wednesday June 25 at 6:30pm in Manhattan. Abstract: The Java Programming Language revolutionized programming with two simple concepts: Write once run anywhere, and Garbage Collection. This led to a big step up in programmer productivity. Project Fortress does it again.This time we give you multiprocessor performance without having to code threads, locks, or load balancing. Can you say Implicit Parallelism and Transactional Memory? We also give you a growable language (small fixed core), strong static typing (more errors caught at compile time), and mathematical notation. This talk will focus on the strengths of Fortress as a programming language, as well as a deep dive into implementation issues. More information is available at http://lisp.meetup.com/59 -Jeff --- 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] Type level sets with GADTs, fundeps etc
Hello, data LSet t where Nil :: LSet Nil --either add the new element or do nothing Ins :: (Member a t b , If b (LSet t) (LSet (a ::: t)) r) = L a - LSet t - r The constructor Ins needs to return an LSet. Maybe try replacing occurrences of r with (LSet r). -Jeff --- 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] Type level sets with GADTs, fundeps etc
Hello, data LSet t where Nil :: LSet Nil --either add the new element or do nothing Ins :: (Member a t b , If b (LSet t) (LSet (a ::: t)) r) = L a - LSet t - r The constructor Ins needs to return an LSet. Maybe try replacing occurrences of r with (LSet r). I expected that r would be an LSet, as its the output of If which returns its 2nd or 3rd argument: class If p x y z | p x y - z where if' :: p - x - y - z instance If T x y x instance If F x y y Type classes are open so there is nothing to prevent you from adding another instance for If, perhaps in a different module, which returns some arbitrary type. -Jeff --- 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] Type level sets with GADTs, fundeps etc
Hello, data LSet t where Nil :: LSet Nil Ins :: (Member a t b , If b t (a ::: t) r) = L a - LSet t - LSet r Try replacing both original occurrences of r, i.e. (untested) Ins :: (Member a t b, If b t (a ::: t) (LSet r)) = L a - LSet t - LSet r -Jeff --- 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] Type level sets with GADTs, fundeps etc
Hello, Thanks. This sort of works, but shifts the problem to another context. Now it seems that I can't hide the extra type information in the existential types, which is what I want to do. I think that you can't abstract over a type context, i.e. you can't expect type inference to instantiate a type variable to a constrained polymorphic type. I get the impression that GADTs are a bit of a distraction for what you are aiming to do. I'm not sure exactly what you mean by :t insert (undefined::A) (undefined:: A ::: Nil) insert (undefined::A) (undefined:: A ::: Nil) :: A ::: Nil But what I really want to do is wrap this up so that it can be used at runtime, not just in the type-checker, so that (just a sketch) I could have insert 'A' empty :: Set (A ::: Nil) where the runtime value of the set is fully determined by its type. but it looks like it should be a realtively easy bit of machinery to add to what you already had. Also, in case you haven't already seen these, other good sources of type level programming are the HList paper ( http://homepages.cwi.nl/~ralf/HList/) and the OOHaskell paper ( http://homepages.cwi.nl/~ralf/OOHaskell/) -Jeff --- 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] Usage of . and $
[EMAIL PROTECTED] wrote on 03/06/2007 02:43:03 PM: Usually, I can do this, but today, my brain is weak, and I'm just trying to get this piece of code out the door. My code looks like this: weight = sum (IntMap.elems (IntMap.intersectionWith (\x y - x*y) queryVector rationalProjection)) I know that this will work (ignoring indentation): sum $ IntMap.elems $ IntMap.intersectionWith (\x y - x*y) queryVector rationalProjection But why won't this?: sum . IntMap.elems . IntMap.IntersectionWith ... Is there a difference between the elegance of function composition versus application? I assume your really asking why something like: (*) $ 2 $ 3 won't work? If so, the reason is that $ associates to the right. So you should write: ((*) $ 2) $ 3 If not, could you give the full expression which doesn't work? -Jeff --- 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] Usage of . and $
Jefferson Heard [EMAIL PROTECTED] wrote on 03/06/2007 03:18:40 PM: Nope, I'm asking why um . IntMap.elems . IntMap.IntersectionWith (\x y - x*y) queryVector rationalProjection won't work. We have (simplifying away some typeclass details): sum . elems :: IntMap a - a and: intersectionWith (*) :: IntMap a - IntMap a - IntMap a but: ((sum . elems) .) :: (IntMap a - IntMap a) - IntMap a - a so you need something like: sum . elems . uncurry (intersectionWith (*)) $ (queryVector, rationalProjection) -Jeff --- 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] Search monad
Hello, You might want to look at the scrap your boilerplate papers and/or their implementation in GHC in Data.Generics. -Jeff [EMAIL PROTECTED] wrote on 03/19/2007 01:11:19 PM: Hey, I have a structure containing Xs in various places, like so data X data Structure = Structure .. [X] .. [X] .. And I defined mapStructure mapStructure :: (X - X) - (Structure - Structure) I then wanted to use mapStructure to define queries as well as transformations on structures. I generalized mapStructure to mapStructureM: mapStructure :: Monad m = (X - m X) - (Structure - m Structure) and then defined the following search monad: data Search f a b = Found (f a) b class Monad (m a) = SearchMonad m a where found :: a - m a a fromSearch :: Search f a b - f a fromSearch (Found a _) = a search :: (SearchMonad m a) = (a - Bool) - a - m a a search f a | f a = found a | otherwise = return a Instances of the monad for finding one and for finding all elements: instance SearchMonad (Search Maybe) a where found a = Found (Just a) a instance SearchMonad (Search []) a where found a = Found [a] a instance Monad (Search Maybe a) where return b = Found Nothing b Found (Just a) a' = f = case f a' of Found _ b - Found (Just a) b Found Nothing a' = f = f a' instance Monad (Search [] a) where return b = Found [] b Found as a' = f = case f a' of Found as' b - Found (as ++ as') b Here is a simple sample session with ghci *Util fromSearch $ mapM (search even) [1,3,5] :: Maybe Int Nothing *Util fromSearch $ mapM (search even) [1,2,3,4,5] :: Maybe Int Just 2 *Util fromSearch $ mapM (search even) [1,2,3,4,5] :: [Int] [2,4] What I'm wondering about is if this monad is an instance of a more general monad(if so, which one?), and generally if people have any comments about these definitions. Thanks! Edsko ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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
[Haskell-cafe] toClockTime
Hello, On my system, GHC 6.6 running on windows xp, System.Time.toClockTime fails on calendar times later than (by days, I didn't check hours, minutes, etc.) January 18, 2038. Is this a bug? thanks, Jeff --- 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] Partial Evaluation
Hello, Partial evaluation in this context (programming languages research) usually refers to compile time optimization techniques such as statically evaluating as much of a function as possible (e.g. going into the function body and evaluating as much as possible that doesn't depend on the function arguments) and various syntactic transformations to improve run-time efficiency. You can find lots of information about this topic at: http://partial-eval.org. -Jeff [EMAIL PROTECTED] wrote on 03/21/2007 02:47:28 PM: I am reading Hudak's paper Modular Domain Specific Languages and Tools [1] and am confused by his use of the term `Partial Evaluation'. I understand it to mean supplying some but not all arguments to a function, e.g. (+3) but it seems to mean something else too. This is in the context of optimising performance: We have used existing partial evaluation techniques to do this...Unfortunately, there does not currently exist a suitable, easy-to-use partial evaluator for Haskell. Our approach was to convert the Haskell program to Scheme, partially evaluate the Scheme program, and then translate back into Haskell. What does P.E, mean here? Thanks, [1] Available http://wiki.ittc.ku.edu/lambda/Image:Hudak- Modular_Domain_Specific_Languages_and_Tools.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe --- 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] Is ([] - []) an arrow?
Hello, In John Hughes's Programming With Arrows (http://www.cs.chalmers.se/~rjmh/afp-arrows.pdf), he discusses a stream function type newtype SF a b = SF {runSF :: [a] - [b]} and gives instance Arrow SF where He gives some examples using this, and everything seems to go just fine. I believe Hughes also states that it isn't really an arrow. But in Ross Patterson's Arrows and Computation (http://www.soi.city.ac.uk/~ross/papers/fop.html), he says that newtype ListMap i o = LM ([i] - [o]) is ALMOST an arrow. Now, I've heard (but never verified) that IO fails to satisfy some monad laws, yet here we are, using it as a monad. Is a similar kind of thing going on here? Has anyone hit any snags in using this instance? It really isn't an arrow (hint to see why: nothing forces the length of the input list to match that of the output list) and thus the arrow laws are not sound for this type. This will be a problem for you if your compiler attempts to optimize arrow expressions using the arrow laws (I think, but I'm not sure, that GHC tries to do this when using arrow notation). -Jeff --- 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] [IO Int] - IO [Int]
Hello, I'm trying to learn haskell, so here's is my first newbie question. I hope this list is appropriate for such help requests. Yes. I'm trying to write a function with the signature [IO Int] - IO [Int] As other people have mentioned, the library function sequence has this type (actually a type which generalizes this type). conv2 :: [IO Int] - IO [Int] conv2 l = do val - (head l) rest - (conv2 (tail l)) return (val : rest) That works, This doesn't quite work since you don't cover the case for empty lists. You need to add another clause: conv2 [] = return [] but it won't work for infinite lists. How could I achieve the desired result ? I don't think a function of this type makes sense for infinite lists. Even the library function sequence will diverge on an infinite list. The issue is that you must evaluate all of the input [IO Int] to get the pure [Int] output. In other words, the type IO [Int] means an IO action which results in a (pure) list of ints. Thus, you cannot start returning the result [Int] while there are still IO actions to perform to compute the rest of the result. -Jeff --- 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] Question about HList possibilities
Hello, Hello all, Given an HList (http://homepages.cwi.nl/~ralf/HList/) would it be possible to do the following: Create a class/function/magicks that would essentially do what hOccursMany does, except it would not return a list of elements, but a new HList. For example, would this allow us to be able to write more lax typing constraints and say extract only things that are in lists. ie) HCons hi (HCons [2.2,3.3] (HCons 'a' hNil)) - HCons hi (HCons [2.2,3.3] hNil) (removing the Char element). I tried to write something like this but I did not get very far, is it even possible? I'm new to this type-level programming :) One approach is to write a HList filter function. You need to use type-level bools, type-level apply, and break up the filter function into two parts; you need a second typeclass to discriminate on the HBool which results from applying your predicate to each element of the HList. Below is some code that works for me. -Jeff - {-# OPTIONS -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances #-} module MyHList where class TypeCast a b | a - b, b-a where typeCast :: a - b class TypeCast' t a b | t a - b, t b - a where typeCast' :: t-a-b class TypeCast'' t a b | t a - b, t b - a where typeCast'' :: t-a-b instance TypeCast' () a b = TypeCast a b where typeCast x = typeCast' () x instance TypeCast'' t a b = TypeCast' t a b where typeCast' = typeCast'' instance TypeCast'' () a a where typeCast'' _ x = x data HNil = HNil deriving (Show, Read, Eq) data HCons e l = HCons e l deriving (Show, Read, Eq) data HTrue = HTrue deriving (Eq, Show) data HFalse = HFalse deriving (Eq, Show) class HApply f e v | f e - v where hApply :: f - e - v -- This HFilter uses an accumulator to avoid using typecast. -- class HFilter acc p l l' | acc p l - l' where hFilter :: acc - p - l - l' instance HFilter acc p HNil acc where hFilter acc _ _ = acc instance (HApply p x b, HFilter1 b x acc p xs xs') = HFilter acc p (HCons x xs) xs' where hFilter acc p (HCons x xs) = hFilter1 (hApply p x) x acc p xs class HFilter1 b x acc p xs xs' | b x acc p xs - xs' where hFilter1 :: b - x - acc - p - xs - xs' instance HFilter acc p xs xs' = HFilter1 HFalse x acc p xs xs' where hFilter1 _ _ acc p xs = hFilter acc p xs instance HFilter (HCons x acc) p xs xs' = HFilter1 HTrue x acc p xs xs' where hFilter1 _ x acc p xs = hFilter (HCons x acc) p xs -- Here is a specific type-level function to check if something is a list. -- Can't avoid the typeCast here because of functional dependencies on HApply -- data IsList = IsList instance HApply IsList [a] HTrue where hApply _ _ = undefined instance TypeCast HFalse b = HApply (IsList) a b where hApply _ _ = undefined test = hFilter HNil IsList $ HCons hi (HCons [2.2,3.3] (HCons 'a' HNil)) --- 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] Propositional logic question
Hello, But here I am only entitled to discharge (A /\ B) in the preceding proof and not A and B on their own. What proof which would allow me to discharge my assumptions A and B? I can see in my head how it makes perfect sense, but can't jiggle a way to do it using only the given derivations. You have (A /\ B) to work with. Remember that intuitionistic/classical logic places no restrictions on how many times you use each hypothesis. hth, Jeff --- 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: FW: RE [Haskell-cafe] Monad Description For Imperative Programmer
Hello, On 8/1/07, Andrew Wagner [EMAIL PROTECTED] wrote: For me, I think the key to monads is to really understand 2 things about them: ... 2.) Monads are about sequencing Now I disagree on 2. Monads are no more about sequencing than binary operators are about sequencing. Sure, if you want to, you can define an operator like (*) to be non-commutative, so that a*b is different to b*a, but that doesn't really get to the essence of what a binary operator is. And in everyday usage we use (*) to mean ordinary commutative multiplication where there is no sense of sequencing. The same holds for monads. If you want to use them for sequencing the option is there, but there are plenty of commutative monads out there, for which the order of operations doesn't matter, and the fact that they are commutative doesn't make them any less monads. So while you can use monads to sequence, I don't think sequencing gets to the essence of what monads are. I suspect I hold a minority view here... :-) You are entirely correct. Data dependencies enforce/specify sequencing. -Jeff --- 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: FW: RE [Haskell-cafe] Monad Description For Imperative Programmer
Hello, 'Monad' is a type class. So what's 'IO'? Is the correct terminology 'instance' as in 'IO is an instance of Monad'. I consider 'IO' to be 'a monad' as that fits with mathematical terminology. I agree with this. But what about an actual object of type 'IO Int', say? I usually describe the type resulting from applying a monad a computation. Then 'IO Int' would be something like an IO computation of an Int. This terminology also jibes well with, or rather comes from, Moggi's computational lambda calculus (one of the early papers showing uses of Monads to computer science). -Jeff --- 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] Re: Using haskell with emacs
Hello, :r is also *much* faster in general; :l reloads all modules from scratch, while :r only reloads the modules that have changed. :r also doesn't seem check the import declarations for changes. For example, if I add a new import statement to my file, without adding code which uses the new import, :r will not cause the newly imported things to be in scope, but :l will. BTW this is for GHCi 6.6.1, though I think older versions had the same behavior. -Jeff --- 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