Re: [Haskell-cafe] New in haskell for old-timers?
John 0.8.1 is almost due to be put out, it will be the first to be 100% John haskell 2010 (and haskell 98) compliant and has a lot of other neat John features over 0.8.0. That's great ! I can't wait to put it into my toolbox. Haskell compilers are all pieces of art, bringing beauty to our daily work. Thanks a lot to everyone involved in them. -- Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New in haskell for old-timers?
On Fri, Mar 30, 2012 at 10:33, Mats Rauhala mats.rauh...@gmail.com wrote: I didn't realize asking how long it's been for him, but he mentioned about new fronts in optimizing compilers and specifically mentioned a compiler that could compile to legible C. I've been following Haskell only for a couple of years, so my intuition tells me that he means `-fvia-c`, and I mentioned to him that it's about to be deprecated and replaced with the llvm back-end. I also mentioned hackage, but he hadn't heard of it. The legible C thing is probably jhc ( http://repetae.net/computer/jhc/ ). It's GHC's *illegible* registerized C that is being phased out; the slightly-more-legible ANSI C mode used for porting is staying, though. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New in haskell for old-timers?
On 11:57 Fri 30 Mar , Brandon Allbery wrote: The legible C thing is probably jhc ( http://repetae.net/computer/jhc/ ). It's GHC's *illegible* registerized C that is being phased out; the slightly-more-legible ANSI C mode used for porting is staying, though. Oh wow, I thought jhc was discontinued, but just checked the repositories and mailing lists and it's alive and well. No idea where I got the idea that it was discontinued. Going a little bit on tangent here, but if I understood correctly, jhc is meant to do more optimization. How does this compare to for example ghc? -- Mats Rauhala MasseR pgpcc97i4vS4a.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New in haskell for old-timers?
On Fri, Mar 30, 2012 at 1:05 PM, Mats Rauhala mats.rauh...@gmail.com wrote: On 11:57 Fri 30 Mar , Brandon Allbery wrote: The legible C thing is probably jhc ( http://repetae.net/computer/jhc/ ). It's GHC's *illegible* registerized C that is being phased out; the slightly-more-legible ANSI C mode used for porting is staying, though. Oh wow, I thought jhc was discontinued, but just checked the repositories and mailing lists and it's alive and well. No idea where I got the idea that it was discontinued. Going a little bit on tangent here, but if I understood correctly, jhc is meant to do more optimization. How does this compare to for example ghc? Both are optimizing compilers, but jhc is intended (by the author) to try different things that ghc. If ghc does it one way, jhc will try to explore other aspects of the design space. The last time this came up, I think someone said that jhc uses GRIN for optimizations: http://www.cafepress.com/haskell_books.12273129 GHC tries to optimize by rewriting and also by conventional means. Both try to specialize away uses of type classes, but as I understand it jhc is far more aggressive, or maybe even has a different run-time representation? Anyway, back to the original topic, some of the big items that I would mention to your friend include: * cabal/cabal-dev * hackage (and some of the better known libraries, Data.Vector/Data.Text/Data.ByteString) * Type Families * Haskell 2010 is the current rev of the language standard Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New in haskell for old-timers?
On Fri, 30 Mar 2012 22:45:40 +0200, Jason Dagit dag...@gmail.com wrote: Anyway, back to the original topic, some of the big items that I would mention to your friend include: * cabal/cabal-dev * hackage (and some of the better known libraries, Data.Vector/Data.Text/Data.ByteString) * Type Families * Haskell 2010 is the current rev of the language standard Don't forget: - Haddock - Cabal (the standard, not the program) - Darcs - Hoogle - Hayoo - Better documentation in the base libraries - The Haskell Platform - Better performance of compiled Haskell programs - Improved Windows support - The ongoing Haskell Prime process for updating the Haskell language (See http://www.haskell.org/haskellwiki/Haskell_prime ) - IDEs: EclipseFP and Leksah - The popular xmonad ( http://www.haskell.org/haskellwiki/Xmonad ) - The debugger in GHCi - The popularity of Haskell on Reddit, Stack Overflow, IRC channels - The new site http://www.haskellers.com/ - More books, see http://members.chello.nl/hjgtuyl/tourdemonad.html - An enormous growth of e-mail on the mailing lists - An enormous growth of the number of packages - QuickCheck (this one is not very new) - The Industrial Haskell Group - The haskell.org committee (was formed a year ago to formalise the previously ad-hoc arrangements around managing the haskell.org infrastructure and money, see http://www.haskell.org/haskellwiki/Haskell.org_committee ) - New concepts for I/O: enumerators/iteratees, conduits - Many new extensions to the language, in GHC There is probably even more. For changes in the Haskell language, see http://www.haskell.org/haskellwiki/Haskell_2010 Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New in haskell for old-timers?
On Fri, Mar 30, 2012 at 1:05 PM, Mats Rauhala mats.rauh...@gmail.com wrote: Oh wow, I thought jhc was discontinued, but just checked the repositories and mailing lists and it's alive and well. No idea where I got the idea that it was discontinued. Going a little bit on tangent here, but if I understood correctly, jhc is meant to do more optimization. How does this compare to for example ghc? I occasionally take some time off for other projects, but jhc is alive and well. The C produced is quite legible and even better, portable. Everything from the Nintendo DS to the iPhone has been a target. I am always welcoming active developers. No better way to kick me into jhc mode than submitting some patches. :) 0.8.1 is almost due to be put out, it will be the first to be 100% haskell 2010 (and haskell 98) compliant and has a lot of other neat features over 0.8.0. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell - List Comprehension Question
I don't think a list comprehension is the easiest way to do it, how about upperCase :: String - String upperCase [] = [] upperCase (x:xs) = toUpper x : map toLower xs -Ross On Oct 7, 2009, at 4:48 PM, Steven1990 wrote: Hi, I'm currently learning Haskell, and I've been trying to work out a function for the following problem for a couple of days now. I want to use a list comprehension method to change the first letter of a string to upper case, and the rest of the string to lower case. Eg: heLLo - Hello As I'm trying to learn this, I would appreciate hints rather than the explicit solution if possible? I'm sure I'm close to a solution, I must be missing something though. Driving me crazy! My attempts are something similar to this: upperCase :: String - String upperCase xs = [toUpper(x):toLower(xs) | x - xs] I think 'toLower' expects a single character rather than the list which is one place I'm going wrong? Thanks in advance, Steven -- View this message in context: http://www.nabble.com/New-to-Haskell---List-Comprehension-Question-tp25794144p25794144.html 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell - List Comprehension Question
Hint: Move the boundary case outside the comprehension, and then use the comprehension to handle the normal case. Also, FYI, a comprehension feeds each value of the list xs into x, and then evaluates the expression to the left of the pipe with that single value of x. Cheers, Greg On Oct 7, 2009, at 1:48 PM, Steven1990 wrote: Hi, I'm currently learning Haskell, and I've been trying to work out a function for the following problem for a couple of days now. I want to use a list comprehension method to change the first letter of a string to upper case, and the rest of the string to lower case. Eg: heLLo - Hello As I'm trying to learn this, I would appreciate hints rather than the explicit solution if possible? I'm sure I'm close to a solution, I must be missing something though. Driving me crazy! My attempts are something similar to this: upperCase :: String - String upperCase xs = [toUpper(x):toLower(xs) | x - xs] I think 'toLower' expects a single character rather than the list which is one place I'm going wrong? Thanks in advance, Steven -- View this message in context: http://www.nabble.com/New-to-Haskell---List-Comprehension-Question-tp25794144p25794144.html 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell - List Comprehension Question
2009/10/7 Steven1990 stevenyoung1...@msn.com: Hi, I'm currently learning Haskell, and I've been trying to work out a function for the following problem for a couple of days now. I want to use a list comprehension method to change the first letter of a string to upper case, and the rest of the string to lower case. Eg: heLLo - Hello As I'm trying to learn this, I would appreciate hints rather than the explicit solution if possible? I'm sure I'm close to a solution, I must be missing something though. Driving me crazy! My attempts are something similar to this: upperCase :: String - String upperCase xs = [toUpper(x):toLower(xs) | x - xs] I think 'toLower' expects a single character rather than the list which is one place I'm going wrong? Hi, try to work little things by little things: $ ghci Prelude let f xs = [x:xs | x - xs] Prelude f hello [hhello,ehello,lhello,lhello,ohello] Prelude Prelude :m + Data.Char Prelude Data.Char :t toLower toLower :: Char - Char Prelude Data.Char :t toUpper toUpper :: Char - Char Prelude Data.Char So xs is the whole list (the hello part of each element in the resilt of f hello) and x gets the value of each character. toLower and toUpper have the same type; indeed toLower expects a single character while you feed it a list. The part on the left of the pipe is executed for each x drawn from the xs list. This means that if you want to make something specific to the first element of xs, you have to provide more information: the x alone is not enough to know it is the first one or not. The easiest way to do that is with pattern matching on the upperCase argument: upperCase (x:xs) = ... (Don't forget for the other case, the empty list: upperCase [] = ...) Cheers, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell - List Comprehension Question
Try just writing a function that will change ALL the characters to uppercase (or lower case) using list comprehension and then see if you can isolate how to factor out the special case of the first character. Michael --- On Wed, 10/7/09, minh thu not...@gmail.com wrote: From: minh thu not...@gmail.com Subject: Re: [Haskell-cafe] New to Haskell - List Comprehension Question To: Steven1990 stevenyoung1...@msn.com Cc: haskell-cafe@haskell.org Date: Wednesday, October 7, 2009, 5:20 PM 2009/10/7 Steven1990 stevenyoung1...@msn.com: Hi, I'm currently learning Haskell, and I've been trying to work out a function for the following problem for a couple of days now. I want to use a list comprehension method to change the first letter of a string to upper case, and the rest of the string to lower case. Eg: heLLo - Hello As I'm trying to learn this, I would appreciate hints rather than the explicit solution if possible? I'm sure I'm close to a solution, I must be missing something though. Driving me crazy! My attempts are something similar to this: upperCase :: String - String upperCase xs = [toUpper(x):toLower(xs) | x - xs] I think 'toLower' expects a single character rather than the list which is one place I'm going wrong? Hi, try to work little things by little things: $ ghci Prelude let f xs = [x:xs | x - xs] Prelude f hello [hhello,ehello,lhello,lhello,ohello] Prelude Prelude :m + Data.Char Prelude Data.Char :t toLower toLower :: Char - Char Prelude Data.Char :t toUpper toUpper :: Char - Char Prelude Data.Char So xs is the whole list (the hello part of each element in the resilt of f hello) and x gets the value of each character. toLower and toUpper have the same type; indeed toLower expects a single character while you feed it a list. The part on the left of the pipe is executed for each x drawn from the xs list. This means that if you want to make something specific to the first element of xs, you have to provide more information: the x alone is not enough to know it is the first one or not. The easiest way to do that is with pattern matching on the upperCase argument: upperCase (x:xs) = ... (Don't forget for the other case, the empty list: upperCase [] = ...) Cheers, Thu ___ 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] New to Haskell
On Tue, Dec 18, 2007 at 01:58:00PM +0300, Miguel Mitrofanov wrote: I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. So ? So, I don't know any compiler of any language which does it. Actually, it is a pretty fundamental feature of the lisp-derived languages that they can self modify their own source, and hence keep their own source representation all the way through runtime. Haskell didn't go that route, well, because it is not a lisp. And that is a-okay by me :) Though, it is certainly a valid and well explored choice as far as language design goes. John -- John Meacham - ⑆repetae.net⑆john⑈ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Dec 19, 2007, at 6:25 PM, John Meacham wrote: On Tue, Dec 18, 2007 at 01:58:00PM +0300, Miguel Mitrofanov wrote: I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. So ? So, I don't know any compiler of any language which does it. Actually, it is a pretty fundamental feature of the lisp-derived languages that they can self modify their own source, and hence keep their own source representation all the way through runtime. I'm not really a Lisp programmer, but don't you mean AST instead of source? I know for a fact that Io stores its source code at runtime though (although the emphasis is still on manipulating the AST). Tcl might do it too, but I don't really know Tcl and might be wrong. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Dec 20, 2007 1:23 AM, Jake McArthur [EMAIL PROTECTED] wrote: On Dec 19, 2007, at 6:25 PM, John Meacham wrote: On Tue, Dec 18, 2007 at 01:58:00PM +0300, Miguel Mitrofanov wrote: I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. So ? So, I don't know any compiler of any language which does it. Actually, it is a pretty fundamental feature of the lisp-derived languages that they can self modify their own source, and hence keep their own source representation all the way through runtime. I'm not really a Lisp programmer, but don't you mean AST instead of source? It's Lisp, they're basically the same thing! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Hallo, On Dec 19, 2007 9:25 PM, John Meacham [EMAIL PROTECTED] wrote: Actually, it is a pretty fundamental feature of the lisp-derived languages that they can self modify their own source, and hence keep their own source representation all the way through runtime. This is not actually true. You may be thinking of macros, but macro expansion time is before compile time. After compilation, not many, if any, modern Lisps keep the source around. Of course the old Lisp machines were different. Cheers, -- -alex http://www.ventonegro.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Dec 18, 2007 7:31 AM, Cristian Baboi [EMAIL PROTECTED] wrote: Here is some strange example: module Hugs where aa::Int aa=7 cc:: (Int-Int)-(Int-Int-Int)-Int-(Int-Int) cc a op b = \x- case x of { _ | x==aa - x+1 ; _- a x `op` b } f::Int-Int f(1)=1 f(2)=2 f(_)=3 g::Int-Int g(1)=13 g(2)=23 g(_)=33 h::[Int-Int] - Int -Int h [] x = x h [rr] x= let { u=Hugs.f ; v=Hugs.g } in case rr of { u - Hugs.g(x)+aa ; v - Hugs.f(x)+aa ; _ -rr (x) + aa } h (rr:ll) x = h [rr] x + h (ll) x What I don't understand is why I'm forced to use guards like x==aa in cc, when aa is clearly bounded (is 7) and why in function h, the bounded u and v become free variables in the case expression. It's a simple issue of scoping. The left side of case expressions are *patterns*, which bind new names, and don't look outside their scope for names. This is a good thing. Say you have: case Left 0 of Left x - x Right y - show y (The values are instances of the Either type, specifically Either Int) This will match the value Left 0 against an expression which either looks like Left x or Right y, for any x or y, and act accordingly. If you decided to add x :: Int x = 42 To the top level of your program, you wouldn't want the first case only to match Left 42 when it previously matched any value starting with Left, would you? It is the same as scoping in C (or whatever language your background is, they all support it); you don't want names in a larger scope to interfere with names in a smaller scope. Each case in a case expression introduces a scope, and the left side of the arrow binds new names. I hope this helps, Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
What I should have been told about upfront: - the syntax for an expression - the syntax for a block Don't see your point. - the adhoc syntax rules (how to distinguish among a tuple and a pharanthesized expression and how to find the start and end of a block for example ) Oh, that's pretty easy, parenthesized expression is not divided by a comma. - what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn Hello world ) is not performed twice There are no such guarantees. If you write a = putStrLn Hello world main = do {a; a;} then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. Here is some strange example: module Hugs where aa::Int aa=7 cc:: (Int-Int)-(Int-Int-Int)-Int-(Int-Int) cc a op b = \x- case x of { _ | x==aa - x+1 ; _- a x `op` b } f::Int-Int f(1)=1 f(2)=2 f(_)=3 g::Int-Int g(1)=13 g(2)=23 g(_)=33 h::[Int-Int] - Int -Int h [] x = x h [rr] x= let { u=Hugs.f ; v=Hugs.g } in case rr of { u - Hugs.g(x)+aa ; v - Hugs.f(x)+aa ; _ -rr (x) + aa } h (rr:ll) x = h [rr] x + h (ll) x What I don't understand is why I'm forced to use guards like x==aa in cc, when aa is clearly bounded (is 7) and why in function h, the bounded u and v become free variables in the case expression. No, pattern matching bounds variables; if you write case x of {aa - ...} then aa becomes a LOCAL variable for the case statement, and shadows the global definition. The same applies to u and v in h, except that in this case local variables shadow upper-level local variables. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Cristian Baboi [EMAIL PROTECTED] writes: Here is some strange example: module Hugs where aa::Int aa=7 Small note, it's common to use spaces around the :: and = I've never really noticed before. cc :: (Int-Int) - (Int-Int-Int) - Int - (Int-Int) cc a op b = \x- case x of { _ | x==aa - x+1 ; _- a x `op` b } What I don't understand is why I'm forced to use guards like x==aa in cc, when aa is clearly bounded (is 7) I don't quite understand what you mean. You don't have to use guards, the function could equally well have been written using if-then-else. Why not cc a op b x = if x==aa then (x+1) else a x `op` b Oh, wait, you're asking why you can't write case x of aa - x+1 _ - a x `op` b The answer is that case introduces a new binding for 'aa', so the above is equivalent to let aa = x in x+1 Case is really for deconstructing values with pattern matching, a simple variable like aa (or _) will match any pattern. f::Int-Int f(1)=1 f(2)=2 f(_)=3 You can drop the parentheses here. g::Int-Int g(1)=13 g(2)=23 g(_)=33 h :: [Int-Int] - Int - Int h [] x = x h [rr] x = let { u=Hugs.f ; v=Hugs.g } in case rr of { u - Hugs.g(x)+aa ; v - Hugs.f(x)+aa ; _ -rr (x) + aa } h (rr:ll) x = h [rr] x + h (ll) x Same here, if I understand you correctly. The case introduces new bindings for u and v. Note that you can't (directly) compare functions for equality either, the only way to do that properly would be to compare results over the entire domain. (f == g iff f x == g x forall x) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 18 Dec 2007 10:29:43 +0200, Miguel Mitrofanov [EMAIL PROTECTED] wrote: What I should have been told about upfront: - the syntax for an expression - the syntax for a block Don't see your point. The point is the syntax is introduced as transformation of layout form to non layout form. As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules. - the adhoc syntax rules (how to distinguish among a tuple and a pharanthesized expression and how to find the start and end of a block for example ) Oh, that's pretty easy, parenthesized expression is not divided by a comma. Thanks! What is the end of a block ? What introduce new blocks ? Is this legal (`plus`) x y ? It's this a tuple ? ([a,b,c,d ]) ? etc. - what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn Hello world ) is not performed twice There are no such guarantees. If you write a = putStrLn Hello world main = do {a; a;} then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. What guarantees that by running the main, the string Hello world will be printed exactly twice ? - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot. No, pattern matching bounds variables; if you write case x of {aa - ...} then aa becomes a LOCAL variable for the case statement, and shadows the global definition. The same applies to u and v in h, except that in this case local variables shadow upper-level local variables. Ok. Information from NOD32 This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Hi Cristian, On Dec 18, 2007 10:53 AM, Cristian Baboi [EMAIL PROTECTED] wrote: - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot. It's a trade-off. Haskell has as a design goal that you can use equational reasoning everywhere -- that if you have two ways of writing the same function, you can substitute one for the other in any expression, without changing the result of that expression. For example, since you can prove sum = foldl (+) 0 = foldr (+) 0 = last . scanl (+) 0 you can, in any place you use 'sum,' substitute any of these expressions without changing the result. You couldn't do this if you could write (show sum) and (show $ foldl (+) 0) and they would return different values. You could design the language differently, of course, but the Haskell designers want you -- and the compiler -- to be able to use equational reasoning everywhere -- so they disallow printing functions. - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Cristian Baboi wrote: On Tue, 18 Dec 2007 10:29:43 +0200, Miguel Mitrofanov [EMAIL PROTECTED] wrote: What I should have been told about upfront: - the syntax for an expression - the syntax for a block Don't see your point. The point is the syntax is introduced as transformation of layout form to non layout form. As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules. Well, a block isn't really a unified syntactic unit. The layout rule is used for do {} expressions, which context they are expression syntax, but also in module, let, and where declarations in which context they are declaration syntax, and case expressions in which case they are, well, case alternatives; a little like declarations, I suppose. Since layout is optional, it's often defined simply by the translation into explicit {} and ;. On the other hand, if there are specific areas of ambiguity which have confused you let us know, and we'll clarify. - the adhoc syntax rules (how to distinguish among a tuple and a pharanthesized expression and how to find the start and end of a block for example ) Oh, that's pretty easy, parenthesized expression is not divided by a comma. Thanks! What is the end of a block ? What introduce new blocks ? I'm not sure what you mean by a block here, so I find it hard to answer that. The end of a layout block is when a line is indented less than the first line of the layout. Is this legal (`plus`) x y ? No. It's this a tuple ? ([a,b,c,d ]) ? No, that's a list of four elements, in some parentheses which, in this context, make no semantic difference. An expression in parentheses is one of two things: (a) a tuple, if it is of the form (X,Y,Z,...) where the , are understood to be at the top level syntactically (b) a simple expression which has been parenthesised just to aid clarity or achieve correct precedence. - what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn Hello world ) is not performed twice There are no such guarantees. If you write a = putStrLn Hello world main = do {a; a;} then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. What guarantees that by running the main, the string Hello world will be printed exactly twice ? The semantics of IO, and the guarantees of the runtime. IO specifies that () means compose two actions to make a larger action which does the first actions, then the second action. [do {a; a;} is notation for a a] The RTS specifies that the main action is performed exactly once. - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot. Haskell doesn't contain a code representation natively. It is not a homoiconic language. Just like C, C++, Java, Python, Perl, and Ruby, the compiler/interpreter is free to transform code into some more efficient form for running (including transformation all the way to native code, which is what ghc does) and once it has done so, it retains no information about the shape of the source code which yielded the function. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
- the syntax for an expression - the syntax for a block Don't see your point. The point is the syntax is introduced as transformation of layout form to non layout form. As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules. Well, most users are. Oh, that's pretty easy, parenthesized expression is not divided by a comma. Thanks! What is the end of a block ? What introduce new blocks ? Not sure what you mean by block here. Is this legal (`plus`) x y ? Never tried to write this myself, it looks stupid. It's this a tuple ? ([a,b,c,d ]) ? No, since all commas are in the subexpression. then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. What guarantees that by running the main, the string Hello world will be printed exactly twice ? What kind of guarantees do you want? I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 18 Dec 2007 12:25:18 +0200, Miguel Mitrofanov [EMAIL PROTECTED] wrote: - the syntax for an expression - the syntax for a block Don't see your point. The point is the syntax is introduced as transformation of layout form to non layout form. As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules. Well, most users are. Are what ? Able to spot or thinking about ... Have you asked them all ? Is this legal (`plus`) x y ? Never tried to write this myself, it looks stupid. What else haven't you tried to write by know ? It's a kind of mirror, you know . then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. What guarantees that by running the main, the string Hello world will be printed exactly twice ? What kind of guarantees do you want? Written in blood. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. So ? Information from NOD32 This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Thank you very much! On Tue, 18 Dec 2007 12:17:54 +0200, Jules Bean [EMAIL PROTECTED] wrote: Cristian Baboi wrote: On Tue, 18 Dec 2007 10:29:43 +0200, Miguel Mitrofanov [EMAIL PROTECTED] wrote: - what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn Hello world ) is not performed twice There are no such guarantees. If you write a = putStrLn Hello world main = do {a; a;} then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug. What guarantees that by running the main, the string Hello world will be printed exactly twice ? The semantics of IO, and the guarantees of the runtime. IO specifies that () means compose two actions to make a larger action which does the first actions, then the second action. [do {a; a;} is notation for a a] The RTS specifies that the main action is performed exactly once. Is this dependent on the implementation (if I use GHC or Hugs) or is something that the language say ? Aside: I tried something like this in WinHugs: do { xxx-getLine ; putStrLn xxx } and pressed two keys at once for the getLine action. The result I've got was an infinite loop !!! - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot. Haskell doesn't contain a code representation natively. It is not a homoiconic language. Just like C, C++, Java, Python, Perl, and Ruby, the compiler/interpreter is free to transform code into some more efficient form for running (including transformation all the way to native code, which is what ghc does) and once it has done so, it retains no information about the shape of the source code which yielded the function. Thank you. Information from NOD32 This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules. Well, most users are. Are what ? Sorry if I've confused you. English isn't my native language. Are able, of course. Have you asked them all ? If you're unsure, we can vote here or somewhere else. Is this legal (`plus`) x y ? Never tried to write this myself, it looks stupid. What else haven't you tried to write by know ? Well, I hope, I haven't tried to write the most of stupid-looking things. What kind of guarantees do you want? Written in blood. Write it yourself, I don't have too much blood. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? Yes, 'cause it means you want to embed almost all source code into the compiled program. So ? So, I don't know any compiler of any language which does it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Cristian Baboi wrote: What guarantees that by running the main, the string Hello world will be printed exactly twice ? The semantics of IO, and the guarantees of the runtime. IO specifies that () means compose two actions to make a larger action which does the first actions, then the second action. [do {a; a;} is notation for a a] The RTS specifies that the main action is performed exactly once. Is this dependent on the implementation (if I use GHC or Hugs) or is something that the language say ? It's something the language says. IO is part of the runtime, its semantics are defined. Aside: I tried something like this in WinHugs: do { xxx-getLine ; putStrLn xxx } and pressed two keys at once for the getLine action. The result I've got was an infinite loop !!! If that code loops you have a bug (in hugs?) it certainly shouldn't. It will wait until you press return before it prints anything, though. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 2007-12-18 at 12:53 +0200, Cristian Baboi wrote: The semantics of IO, and the guarantees of the runtime. IO specifies that () means compose two actions to make a larger action which does the first actions, then the second action. [do {a; a;} is notation for a a] The RTS specifies that the main action is performed exactly once. Is this dependent on the implementation (if I use GHC or Hugs) or is something that the language say ? Part of the language. You do get your guarantee written in blood. -Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tuesday 18 December 2007 01:31:59 Cristian Baboi wrote: A few days ago, for various reasons, I've started to look at Haskell. At first I was quite impressed, after reading some FAQ, and some tutorials. Evrything was nice and easy ... until I've started writing some code on my own. What I should have been told about upfront: - the syntax for an expression - the syntax for a block - the adhoc syntax rules (how to distinguish among a tuple and a pharanthesized expression and how to find the start and end of a block for example ) - the fact that lambda expressions are not the same thing as algebraic data values - what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn Hello world ) is not performed twice - the lambda expressions can be written (input) but cannot be printed (output) The biggest problem for me, so far, is the last one. Here is some strange example: module Hugs where aa::Int aa=7 cc:: (Int-Int)-(Int-Int-Int)-Int-(Int-Int) cc a op b = \x- case x of { _ | x==aa - x+1 ; _- a x `op` b } f::Int-Int f(1)=1 f(2)=2 f(_)=3 g::Int-Int g(1)=13 g(2)=23 g(_)=33 h::[Int-Int] - Int -Int h [] x = x h [rr] x= let { u=Hugs.f ; v=Hugs.g } in case rr of { u - Hugs.g(x)+aa ; v - Hugs.f(x)+aa ; _ -rr (x) + aa } h (rr:ll) x = h [rr] x + h (ll) x What I don't understand is why I'm forced to use guards like x==aa in cc, when aa is clearly bounded (is 7) and why in function h, the bounded u and v become free variables in the case expression. I don't think anyone has mentioned it yet, so I'll go ahead. Many of the questions you ask are well covered by the Haskell Report: http://haskell.org/onlinereport/ The report is terse, but quite usable as a reference. Moreover, it is The Final Word on all these semantic and syntactic questions. Cheers, Spencer Janssen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
Cristian Baboi wrote: Haskell strengts as I see them: - it is lazy with class - it is strongly typed - it has automatic memory management - it has a standard library - it has a compiler - it is available on several platforms - it has a community - it is free Is there anything you would like to add ? That list describes Java right on (apart from the lazy with class, which sounds Larry-Wall-ish though and might as well mean Perl :-)). Higher-order functions, purity, pattern-matching, no-nonsense syntax, algebraic data types, ... Reinier ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
Hallo, Cristian Baboi escreveu: From your list, I agree to add some pattern matching abilities to mine, but that it all. Keep using Haskell and resend your list in six months. -alex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
Cristian Baboi wrote: Haskell strengts as I see them: - it is lazy with class - it is strongly typed - it has automatic memory management - it has a standard library - it has a compiler - it is available on several platforms - it has a community - it is free Is there anything you would like to add ? Purity/referential transparency is the most important point you're missing. The other point is really an extension on the strong typing: other languages are strongly-typed too, but few of them have such an expressive type system as haskell, and the expressive type system helps with code design, helps code work right first time, and reduces bugs. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
On Tue, 18 Dec 2007 15:33:55 +0200, Reinier Lamers [EMAIL PROTECTED] wrote: Cristian Baboi wrote: Haskell strengts as I see them: - it is lazy with class - it is strongly typed - it has automatic memory management - it has a standard library - it has a compiler - it is available on several platforms - it has a community - it is free Is there anything you would like to add ? That list describes Java right on (apart from the lazy with class, which sounds Larry-Wall-ish though and might as well mean Perl :-)). Higher-order functions, purity, pattern-matching, no-nonsense syntax, algebraic data types, ... From your list, I agree to add some pattern matching abilities to mine, but that it all. Information from NOD32 This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
On Tue, 18 Dec 2007, Cristian Baboi wrote: Haskell strengts as I see them: - it is lazy with class - it is strongly typed - it has automatic memory management - it has a standard library - it has a compiler - it is available on several platforms - it has a community - it is free Is there anything you would like to add ? Haskell slogan discussion can start again. :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 18 Dec 2007, Benja Fallenstein wrote: Hi Cristian, On Dec 18, 2007 10:53 AM, Cristian Baboi [EMAIL PROTECTED] wrote: - the lambda expressions can be written (input) but cannot be printed (output) Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions ! Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot. It's a trade-off. Haskell has as a design goal that you can use equational reasoning everywhere -- that if you have two ways of writing the same function, you can substitute one for the other in any expression, without changing the result of that expression. For example, since you can prove sum = foldl (+) 0 = foldr (+) 0 = last . scanl (+) 0 Since this was discussed already here, I summed it up in: http://www.haskell.org/haskellwiki/Show_instance_for_functions ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
Concerning the subject: The End of WHAT? Cristian Baboi writes: Reinier Lamers wrote: Cristian Baboi wrote: Haskell strengts as I see them: ... - it has a compiler ... Is there anything you would like to add ? Higher-order functions, purity, pattern-matching, no-nonsense syntax, algebraic data types, ... From your list, I agree to add some pattern matching abilities to mine, but that it all. Oh, it is anyway very generous of you. But tell me: do you *understand* the remaining issues, notably the purity? Jerzy Karczmarczuk PS. For Henning T.: Don't worry, the slogan battle won't start again. The discussion level is not appropriate. Although we can, of course, add to this damned page the ad: people, use Haskell! It has a compiler! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Hi Henning, On Dec 18, 2007 3:53 PM, Henning Thielemann [EMAIL PROTECTED] wrote: Since this was discussed already here, I summed it up in: http://www.haskell.org/haskellwiki/Show_instance_for_functions I find the discussion under theoretical answer unsatisfying. The property that a Show instance for functions would break is extensionality, and while extensionality is a desirable trait and matches the common mathematical intuitions, a system with intensional functions certainly isn't unmathematical or impure. Further, even with extensionality, we can (with compiler support) in principle have Show instances other than enumerating the graph. At least for simple non-recursive functions, showing the Böhm tree of the function could be useful (except that you loop forever if you encounter bottom somewhere, of course, instead of printing bottom as you would if you could print the actual Böhm tree). For example, id would be shown as \a - a, maybe would be shown as \a b c - case c of { Just d - b d; Nothing - a }, and all would be shown as \a - case a of { (b:c) - case b of { False - False; True - case c of { (d:e) - case d of { False - False et cetera ad infinitum. Of course, for functions on ints this would indeed reduce to enumerating the graph, printed as an infinite case expression. - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Dec 18, 2007 4:50 PM, Benja Fallenstein [EMAIL PROTECTED] wrote: Further, even with extensionality, we can (with compiler support) in principle have Show instances other than enumerating the graph. Now that I said it, I'm starting to doubt we even need compiler support beyond what we have already. :-) I'm starting to think that a smattering of unsafePerformIO might be able to do the trick. I shall have to think on this :-) - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 18 Dec 2007, Benja Fallenstein wrote: Hi Henning, On Dec 18, 2007 3:53 PM, Henning Thielemann [EMAIL PROTECTED] wrote: Since this was discussed already here, I summed it up in: http://www.haskell.org/haskellwiki/Show_instance_for_functions I find the discussion under theoretical answer unsatisfying. The property that a Show instance for functions would break is extensionality, and while extensionality is a desirable trait and matches the common mathematical intuitions, a system with intensional functions certainly isn't unmathematical or impure. The mathematical definition of function I know of, says that functions are special relations, and relations are sets of pairs. Their is nothing about intension. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
If the semantics of a language says that a function f is equivalent to a function g, but there is a function h such that h(f) is not equivalent to h(g), then h cannot be a function. Therefore that language cannot be a (purely) functional language. That is the pure and simple reason why functions are not Showable in Haskell. This doesn't mean that it isn't possible to show functions -- even compiled code can usually be reverse-engineered to yield some printable version of an equivalent function -- but if the language is to remain pure, such facilities should be relegated to the development tools (debugger, etc.). -Paul Benja Fallenstein wrote: Hi Henning, On Dec 18, 2007 3:53 PM, Henning Thielemann [EMAIL PROTECTED] wrote: Since this was discussed already here, I summed it up in: http://www.haskell.org/haskellwiki/Show_instance_for_functions I find the discussion under "theoretical answer" unsatisfying. The property that a Show instance for functions would break is extensionality, and while extensionality is a desirable trait and matches the common mathematical intuitions, a system with intensional functions certainly isn't "unmathematical" or impure. Further, even with extensionality, we can (with compiler support) in principle have Show instances other than enumerating the graph. At least for simple non-recursive functions, showing the Bhm tree of the function could be useful (except that you loop forever if you encounter bottom somewhere, of course, instead of printing "bottom" as you would if you could print the actual Bhm tree). For example, id would be shown as "\a - a," maybe would be shown as "\a b c - case c of { Just d - b d; Nothing - a }," and all would be shown as "\a - case a of { (b:c) - case b of { False - False; True - case c of { (d:e) - case d of { False - False" et cetera ad infinitum. Of course, for functions on ints this would indeed reduce to enumerating the graph, printed as an infinite case _expression_. - Benja ___ 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] New to Haskell
Hi Henning, On Dec 18, 2007 5:17 PM, Henning Thielemann [EMAIL PROTECTED] wrote: The mathematical definition of function I know of, says that functions are special relations, and relations are sets of pairs. Their is nothing about intension. That's the standard definition in set theory, but it's not the only mathematical definition of function. It also doesn't suffice for defining all Haskell functions-- consider data T = T (T - Int) fn :: T - Int fn _ = 7 We have (fn (T fn) == 7), so in the graph of 'fn' we must have a pair (T fn, 7). But if 'fn' is the same mathematical object as its graph, that would mean that the graph of 'fn' would have to contain a pair whose first element indirectly contains... the graph of fn! This sort of circularity is not allowed in standard ZFC set theory, so if we're going to be precise, we will have to choose a different representation for functions than their graphs. - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Hi Paul, On Dec 18, 2007 5:18 PM, Paul Hudak [EMAIL PROTECTED] wrote: If the semantics of a language says that a function f is equivalent to a function g, but there is a function h such that h(f) is not equivalent to h(g), then h cannot be a function. Sure. Therefore that language cannot be a (purely) functional language. That is the pure and simple reason why functions are not Showable in Haskell. Not so fast :-) Caveat one, there may be useful ways to for functions to implement Show that don't conflict with extensionality (i.e., the property that two functions are equal if they yield the same results for all inputs). Caveat two, we generally assume extensionality when reasoning about Haskell, but it's entirely possible to give a semantics for Haskell that doesn't assume extensionality. IMHO, a good answer to the question why functions aren't showable in Haskell needs to explain why we prefer our semantics to be extensional, not say that by god-given fiat, Haskell is extensional, so we can't show functions. - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Benja Fallenstein wrote: Not so fast :-) Caveat one, there may be useful ways to for functions to implement Show that don't conflict with extensionality (i.e., the property that two functions are equal if they yield the same results for all inputs). Sure, and I suppose one way to do this is to put the show function for functions into the IO monad -- then you can't inspect the results. But if you want to inspect the result, then I have no idea how to do this. Caveat two, we generally assume extensionality when reasoning about Haskell, but it's entirely possible to give a semantics for Haskell that doesn't assume extensionality. IMHO, a good answer to the question why functions aren't showable in Haskell needs to explain why we prefer our semantics to be extensional, not say that by god-given fiat, Haskell is extensional, so we can't show functions. Well, my caveat was that the Haskell designers wanted it this way. So you are essentially rejecting my caveat, rather than creating a new one. :-) -Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Dec 18, 2007 6:01 PM, Paul Hudak [EMAIL PROTECTED] wrote: Well, my caveat was that the Haskell designers wanted it this way. So you are essentially rejecting my caveat, rather than creating a new one. :-) I mean, I reject the answer They wanted it this way because I think the answer should be, They wanted it this way because They looked at substituting equals under a lambda, and They saw it was good ;-) Caveat one, there may be useful ways to for functions to implement Show that don't conflict with extensionality (i.e., the property that two functions are equal if they yield the same results for all inputs). Sure, and I suppose one way to do this is to put the show function for functions into the IO monad -- then you can't inspect the results. But if you want to inspect the result, then I have no idea how to do this. If you can show and enumerate the argument type and show the result type of a function, one way is to enumerate the graph of the function. The wiki page gives the example, Prelude \x - x+x functionFromGraph [(0,0), (1,2), (2,4), (3,6), Interrupted. If you have special compiler support, and consider a fragment of Haskell that contains only functions -- i.e., no algebraic data types, no Ints etc. (it's kind of a boring fragment!, but you can have Church numbers) --, you can reduce the function to head normal form. Head normal form looks like this: \VAR1 VAR2 ... VARm - VARi EXPR1 ... EXPRn and there is a reduction strategy that finds the head normal form of an arbitrary expression if there is one; a proof that if there isn't one, the expression denotes bottom; and a proof that if you have two HNFs, and they differ in the part before EXPR1 or differ in the number of EXPRjs, these HNFs denote different values. Therefore, when you have reduced the function to HNF, you can print \VAR1 VAR2 ... VARm - VARi (or more precisely, you can write a lazy 'show' that yields the above characters as soon as it has computed the HNF). Then, you go on to recursively compute the HNF of EXPR1, and you show that inside parantheses. Some examples: show (\x - x) == \a - a show (.) == \a b c - a (b c) (let fix f = f (fix f) in show fix) == \a - a (a (a (a (a. [Unless I'm making some stupid mistake] It's well-established that this is computable and doesn't break extensionality (i.e., that applying this show to two functions with the same extension will give the same result -- or conversely, if show gives different results for two functions, there are arguments for which these functions yield different results). By itself, this isn't very interesting, but I *think* you should be able to add algebraic data types and case expressions to this fragment of Haskell and still do essentially the same thing. Then, you could show, for example, show either == \a b c - case c of { Left d - a d; Right e - b e } - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
On Tue, 18 Dec 2007, Benja Fallenstein wrote: Hi Henning, On Dec 18, 2007 5:17 PM, Henning Thielemann [EMAIL PROTECTED] wrote: The mathematical definition of function I know of, says that functions are special relations, and relations are sets of pairs. Their is nothing about intension. That's the standard definition in set theory, but it's not the only mathematical definition of function. It also doesn't suffice for defining all Haskell functions-- consider data T = T (T - Int) fn :: T - Int fn _ = 7 We have (fn (T fn) == 7), so in the graph of 'fn' we must have a pair (T fn, 7). But if 'fn' is the same mathematical object as its graph, that would mean that the graph of 'fn' would have to contain a pair whose first element indirectly contains... the graph of fn! This sort of circularity is not allowed in standard ZFC set theory, so if we're going to be precise, we will have to choose a different representation for functions than their graphs. I see. I'm also wondering what 'total function' and 'partial function' might mean in Haskell, since values can be partially defined. Is Just undefined defined or undefined and is const (Just undefined) a total or a partial function? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell: The End
On 18 Dec 2007, at 7:28 AM, [EMAIL PROTECTED] wrote: Concerning the subject: The End of WHAT? Cristian Baboi writes: Reinier Lamers wrote: Cristian Baboi wrote: Haskell strengts as I see them: ... - it has a compiler ... Is there anything you would like to add ? Higher-order functions, purity, pattern-matching, no-nonsense syntax, algebraic data types, ... From your list, I agree to add some pattern matching abilities to mine, but that it all. Oh, it is anyway very generous of you. But tell me: do you *understand* the remaining issues, notably the purity? Jerzy Karczmarczuk PS. For Henning T.: Don't worry, the slogan battle won't start again. The discussion level is not appropriate. Although we can, of course, add to this damned page the ad: people, use Haskell! It has a compiler! Not a bad advantage --- Haskell is much faster than any mainstream language with a tenth its feature set. Of course, so is any other language with a tenth its feature set, but I don't see how anyone using Scheme or ML is anymore a bad thing for Haskell... jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Benja Fallenstein wrote: I mean, I reject the answer "They wanted it this way" because I think the answer should be, "They wanted it this way because They looked at substituting equals under a lambda, and They saw it was good" ;-) Your version of the answer is in fact correct, but is just an elaboration of the original one. So, I don't see what your point is... Sure, and I suppose one way to do this is to put the show function for functions into the IO monad -- then you can't inspect the results. But if you want to inspect the result, then I have no idea how to do this. If you can show and enumerate the argument type and show the result type of a function, one way is to enumerate the graph of the function. Yes, but this requires a STANDARD way to do this -- meaning that the underlying domains are enumerable in a standard way. I don't think that is always possible. And of course you may have an infinite graph, whereas the function itself is finite. Regarding the rest of your message: I don't see how this helps, since some terms do not have head-normal forms. Even in the pure lambda calculus there are terms that denote the same value but that are not convertible to one another. It seems that at best this approach would yield only partial success. -Paul The wiki page gives the example, Prelude \x - x+x functionFromGraph [(0,0), (1,2), (2,4), (3,6), Interrupted. If you have special compiler support, and consider a fragment of Haskell that contains only functions -- i.e., no algebraic data types, no Ints etc. (it's kind of a boring fragment!, but you can have Church numbers) --, you can reduce the function to head normal form. Head normal form looks like this: \VAR1 VAR2 ... VARm - VARi EXPR1 ... EXPRn and there is a reduction strategy that finds the head normal form of an arbitrary _expression_ if there is one; a proof that if there isn't one, the _expression_ denotes bottom; and a proof that if you have two HNFs, and they differ in the part before EXPR1 or differ in the number of EXPRjs, these HNFs denote different values. Therefore, when you have reduced the function to HNF, you can print "\VAR1 VAR2 ... VARm - VARi " (or more precisely, you can write a lazy 'show' that yields the above characters as soon as it has computed the HNF). Then, you go on to recursively compute the HNF of EXPR1, and you show that inside parantheses. Some examples: show (\x - x) == "\a - a" show (.) == "\a b c - a (b c)" (let fix f = f (fix f) in show fix) == "\a - a (a (a (a (a. [Unless I'm making some stupid mistake] It's well-established that this is computable and doesn't break extensionality (i.e., that applying this show to two functions with the same extension will give the same result -- or conversely, if show gives different results for two functions, there are arguments for which these functions yield different results). By itself, this isn't very interesting, but I *think* you should be able to add algebraic data types and case expressions to this fragment of Haskell and still do "essentially" the same thing. Then, you could show, for example, show either == "\a b c - case c of { Left d - a d; Right e - b e }" - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell
Hi Paul, On Dec 19, 2007 6:54 AM, Paul Hudak [EMAIL PROTECTED] wrote: Your version of the answer is in fact correct, but is just an elaboration of the original one. So, I don't see what your point is... Ok, sorry, I'll try again... I'm trying to say that in my opinion, it's important to include the elaboration if you want to give a *useful* answer to why can't I print functions. :) If you can show and enumerate the argument type and show the result type of a function, one way is to enumerate the graph of the function. Yes, but this requires a STANDARD way to do this -- meaning that the underlying domains are enumerable in a standard way. I don't think that is always possible. It isn't always, no; in Haskell, there's no way to enumerate the instances of (IO Int), for example. But of course, you can't show (IO Int) in the first place, so I guess there's no expectation that you should be able to show functions with (IO Int) arguments, either. Function domains also aren't enumerable in general, although you could simply enumerate all functions writable in Haskell, and not care about duplicates. But it seems very unlikely anyway that printing higher-order functions in this way would be *practical*. And of course you may have an infinite graph, whereas the function itself is finite. (you mean that the function term is finite, I suppose) Yes, but you can show infinite lists, too -- resulting in an infinite String being returned by 'show.' Regarding the rest of your message: I don't see how this helps, since some terms do not have head-normal forms. But these terms denote bottom. Compare (show (1:2:_|_)); the behavior would be similar. Even in the pure lambda calculus there are terms that denote the same value but that are not convertible to one another. Such terms would return the same *infinite* String in this approach. You couldn't write a program to test whether they're equal; but you can't write a program that tests whether two arbitrary infinite lists are equal, either. It seems that at best this approach would yield only partial success. Oh, that's certainly true, in the sense that showing functions in this way would often not be as practical as one might hope for -- the worst problem being that recursive functions will often have infinite representations. Still, in my opinion, there is a difference between the theory says you can't show functions and from the theoretical perspective, there is an elegant way to show functions, but it would be a lot of work to implement and the result wouldn't be as practical as you're hoping for. Although I admit it's more of a theoretical difference than a practical one. :-) - Benja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell - Question about hugsIORun from old Prelude
On Mon, 11 Dec 2006, Rahul Naik wrote: Hello, I am trying to rewrite some older (2001) haskell : myReadFile :: String - String myReadFile f = case hugsIORun (readFile f) of Right s - s Left _ - Can someone provide me with a up to date version of the above bit of code without using code from the old Prelude? http://www.haskell.org/hawiki/ThatAnnoyingIoType ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] New to Haskell, suggestions on code
Flavio Botelho wrote: At many places i have put a Char type instead of an abstract one because some funcations were not working properly before and i wanted to be able to output things and so be able to see what was the problem. (Haskell doesnt seem a 'magic' function to output arbitrary structures? That would be quite helpful for debugging) The show method in the Show class generates a string representation of an instance. The print function can be used to print the string representation of any instance of Show to stdout. All standard types except for functions are instances of Show, and Haskell can automatically derive Show instances for user defined types, provided that all of the constituent types are instances of Show. -- Glynn Clements [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe