Re: [Haskell-cafe] Static linking for machines that don't have Haskell
Roshan James rpja...@umail.iu.edu writes: This gives me several warnings of the form: */usr/lib/haskell-packages/ghc6/lib/network-2.2.1.7/ghc-6.12.3/libHSnetwork-2.2.1.7.a(BSD.o): In function `sw4B_info':* *(.text+0x584c): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking* Yes, the Linux libc doesn't really support static linking, and in fact actively subverts it by dynamically loading other libraries from hardwired paths. I'm sure there's a good reason for it. Some things can be worked around by setting environment variables etc, but generally, try to compile on the oldest system you can find (since backwards compatibility is better supported than forward), and use the same distribution. Use strace to see what dynamic libraries your executable tries to load, and Google to see what can be done about them. The best solution would be to use a different libc. -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] Really Simple explanation of Continuations Needed
Ozgur Akgun wrote: On 1 October 2011 11:55, Yves Parès limestr...@gmail.com wrote: BTW Heinrich, the evalState (sequence . repeat . State $ \s - (s,s+1)) 0 at the end doesn't work anymore. It should be replaced by : evalState (sequence . repeat . StateT $ \s - Identity (s,s+1)) 0 Or equivalently: evalState (sequence . repeat . state $ \s - (s,s+1)) 0 Thanks, I've changed it. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Peggy 0.2.1
I love the concise syntax and useful examples. Thank you! On Wed, Sep 28, 2011 at 12:53 PM, Hideyuki Tanaka tan...@preferred.jpwrote: Hello, all. I have released 'Peggy' a new parser generator . It is based on Parsing Expression Grammer (PEG) [1], and generates efficient packrat parsers. # Where to get it * Hackage page (http://hackage.haskell.org/package/peggy) * github repository (https://github.com/tanakh/peggy). * Some documents are at (http://tanakh.github.com/Peggy/). # Advantage * Simple and Powerful syntax * No shift/reduce conflict * Unlimited look-ahead * You don't need to prepare separated Scanner * Linear time complexity * Based on modern Haskell ecosystem (bytestring, text, ListLike, Monads, etc...) * Support to use and generate Quasi Quoters # Examples Here are few example of parsers: * http://tanakh.github.com/Peggy/example.html * https://github.com/tanakh/Peggy/blob/master/example/Json.hs There is a self defined parser of peggy syntax, used for bootstrapping: * https://github.com/tanakh/Peggy/blob/master/bootstrap/peggy.peggy Please try it and give me feedbacks! Thanks, [1]: http://en.wikipedia.org/wiki/Parsing_expression_grammar -- Hideyuki Tanaka ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Is it possible to represent such polymorphism?
--I tried to write such polymorphic function: expand (x,y,z) = (x,y,z) expand (x,y) = (x,y,1) --And it didn't compile. Then I added a type signature: expand::a-b expand (x,y,z) = (x,y,z) expand (x,y) = (x,y,1) --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x --Is it possible to get around this and write the expand function? Of course, x and y may be of different types ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
2-tuple and 3-tuple *are not the same type*. So to do this you must use typeclasses. Plus you have to deal with the type parameters class To3Tuple a where expand :: a - (Int, Int, Int) instance To3Tuple (Int, Int, Int) where expand = id instance To3Tuple (Int, Int) where expand (x,y) = (x,y,1) Here I had to force my tuples to be tuples of integers. It's more complicated if you want polymorphism. 2011/10/2 Du Xi sdiy...@sjtu.edu.cn --I tried to write such polymorphic function: expand (x,y,z) = (x,y,z) expand (x,y) = (x,y,1) --And it didn't compile. Then I added a type signature: expand::a-b expand (x,y,z) = (x,y,z) expand (x,y) = (x,y,1) --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x --Is it possible to get around this and write the expand function? Of course, x and y may be of different types __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] Is it possible to represent such polymorphism?
On 02/10/2011 02:04 PM, Du Xi wrote: --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x The type a - b doesn't mean what you think it does. It does /not/ mean that f is allowed to return any type it wants to. It means that f must be prepaired to return any type that /the caller/ wants it to. So, given ANY POSSIBLE INPUT, the function must be able to construct a value of ANY POSSIBLE TYPE. This is, of course, impossible. The only way you can implement a function with this type signature is to cheat. Also, you can't just take x, which has type a, and then pretend that it has type b instead. Haskell doesn't work like that. Your type signature says that the result type can be different than the input type, but your function definition forces the result to always be /the same/ type as the input. Hence, it is rejected. That aside, the fundamental problem here is that each tuple type is a different, completely unrelated type, as far as the type system is concerned. (x,y) and (x,y,z) might look similar to you, but to the type system they're as similar as, say, Either x y and StateT x y z. In Haskell, the only way to get a function to work for several unrelated types (but not /every/ possible type) is to use classes. Depending on exactly what you're trying to do, you might be better using lists, or perhaps some custom data type. It depends what you want to do. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On Sun, Oct 2, 2011 at 6:04 AM, Du Xi sdiy...@sjtu.edu.cn wrote: --Is it possible to get around this and write the expand function? Of course, x and y may be of different types Not as written, but try HList. http://hackage.haskell.org/package/HList ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
Quoting Andrew Coppin andrewcop...@btinternet.com: On 02/10/2011 02:04 PM, Du Xi wrote: --It still didn't compile. I think the reason is that the following is disallowed: f::a-b f x = x The type a - b doesn't mean what you think it does. It does /not/ mean that f is allowed to return any type it wants to. It means that f must be prepaired to return any type that /the caller/ wants it to. So, given ANY POSSIBLE INPUT, the function must be able to construct a value of ANY POSSIBLE TYPE. This is, of course, impossible. The only way you can implement a function with this type signature is to cheat. Also, you can't just take x, which has type a, and then pretend that it has type b instead. Haskell doesn't work like that. Your type signature says that the result type can be different than the input type, but your function definition forces the result to always be /the same/ type as the input. Hence, it is rejected. That aside, the fundamental problem here is that each tuple type is a different, completely unrelated type, as far as the type system is concerned. (x,y) and (x,y,z) might look similar to you, but to the type system they're as similar as, say, Either x y and StateT x y z. In Haskell, the only way to get a function to work for several unrelated types (but not /every/ possible type) is to use classes. Depending on exactly what you're trying to do, you might be better using lists, or perhaps some custom data type. It depends what you want to do. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Then again , in typeclass definition how can I express the type a-b where a is the type parameter of the class and b is a type deduced from the rules defined in each instance of the class, which varies on a per-instance basis? e.g. instance ExampleClass a where f :: a-SomeTypeWhichIsDifferentInEachInstance What I want is some thing like this in C++: float f(char x){ return 0.1f; } int f(double x){ return 1; } ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On Sun, Oct 2, 2011 at 8:45 AM, Du Xi sdiy...@sjtu.edu.cn wrote: Then again , in typeclass definition how can I express the type a-b where a is the type parameter of the class and b is a type deduced from the rules defined in each instance of the class, which varies on a per-instance basis? e.g. instance ExampleClass a where f :: a-**SomeTypeWhichIsDifferentInEach**Instance What I want is some thing like this in C++: float f(char x){ return 0.1f; } int f(double x){ return 1; } Use TypeFamilies. {-# LANGUAGE TypeFamilies #} ... type family FType a :: * type instance FType Char = Float type instance FType Double = Int class ExampleClass a where f :: a - FType a ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Installing hledger-web
I have reopened http://code.google.com/p/hledger/issues/detail?id=63 . Sorry for the breakage. I thought I had this working once but I'm not sure how! -Simon On 10/1/11 10:36 PM, Arnaud Bailly wrote: Thanks Simon. Unfortunately, I got the same error. On Sun, Oct 2, 2011 at 2:50 AM, Simon Michael si...@joyful.com mailto:si...@joyful.com wrote: Thanks for the report Arnaud. Can you try again with cabal install hledger-web -fproduction ? That flag is supposed to be default but it sounds like I messed up. -Simon On 10/1/11 1:42 PM, Arnaud Bailly wrote: Hello, I installed hledger and tried installing hledger-web but got the following error: [2 of 8] Compiling Hledger.Web.Settings.__StaticFiles ( Hledger/Web/Settings/__StaticFiles.hs, dist/build/hledger-web/__hledger-web-tmp/Hledger/Web/__Settings/StaticFiles.o ) Hledger/Web/Settings/__StaticFiles.hs:1:1: Exception when trying to run compile-time code: ./static: getDirectoryContents: does not exist (No such file or directory) Code: staticFiles staticDir cabal: Error: some packages failed to install: hledger-web-0.16 failed during the building phase. The exception was: ExitFailure 1 I install on xubuntu 11.04 with ghc 7.0.3 and latest haskell platform. The installation is quite new without much other libs. Thanks for helping, Arnaud _ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/__mailman/listinfo/haskell-cafe http://www.haskell.org/mailman/listinfo/haskell-cafe _ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/__mailman/listinfo/haskell-cafe http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
02.10.2011 19:55, David Barbour пишет: Use TypeFamilies. {-# LANGUAGE TypeFamilies #} ... type family FType a :: * type instance FType Char = Float type instance FType Double = Int class ExampleClass a where f :: a - FType a Better to include type in class. class ExampleClass a where type FType a f :: a - FType a instance ExampleClass Char where type FType Char = Float f char = ... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Installing hledger-web
No problem ! BTW, have you ever thought of coupling hledger with git for saving a ledger ? There is ongoing work to provide a native git interface. Regards Arnaud On Sun, Oct 2, 2011 at 6:32 PM, Simon Michael si...@joyful.com wrote: I have reopened http://code.google.com/p/**hledger/issues/detail?id=63http://code.google.com/p/hledger/issues/detail?id=63. Sorry for the breakage. I thought I had this working once but I'm not sure how! -Simon On 10/1/11 10:36 PM, Arnaud Bailly wrote: Thanks Simon. Unfortunately, I got the same error. On Sun, Oct 2, 2011 at 2:50 AM, Simon Michael si...@joyful.com mailto: si...@joyful.com wrote: Thanks for the report Arnaud. Can you try again with cabal install hledger-web -fproduction ? That flag is supposed to be default but it sounds like I messed up. -Simon On 10/1/11 1:42 PM, Arnaud Bailly wrote: Hello, I installed hledger and tried installing hledger-web but got the following error: [2 of 8] Compiling Hledger.Web.Settings.__**StaticFiles ( Hledger/Web/Settings/__**StaticFiles.hs, dist/build/hledger-web/__**hledger-web-tmp/Hledger/Web/__**Settings/StaticFiles.o ) Hledger/Web/Settings/__**StaticFiles.hs:1:1: Exception when trying to run compile-time code: ./static: getDirectoryContents: does not exist (No such file or directory) Code: staticFiles staticDir cabal: Error: some packages failed to install: hledger-web-0.16 failed during the building phase. The exception was: ExitFailure 1 I install on xubuntu 11.04 with ghc 7.0.3 and latest haskell platform. The installation is quite new without much other libs. Thanks for helping, Arnaud __**___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.**orgHaskell-Cafe@haskell.org http://www.haskell.org/__**mailman/listinfo/haskell-cafehttp://www.haskell.org/__mailman/listinfo/haskell-cafe http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe __**___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.**orgHaskell-Cafe@haskell.org http://www.haskell.org/__**mailman/listinfo/haskell-cafehttp://www.haskell.org/__mailman/listinfo/haskell-cafe http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] Is it possible to represent such polymorphism?
Quoting Victor Gorokgov m...@rkit.pp.ru: 02.10.2011 19:55, David Barbour пишет: Use TypeFamilies. {-# LANGUAGE TypeFamilies #} ... type family FType a :: * type instance FType Char = Float type instance FType Double = Int class ExampleClass a where f :: a - FType a Better to include type in class. class ExampleClass a where type FType a f :: a - FType a instance ExampleClass Char where type FType Char = Float f char = ... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
Finally I got what I meant: class ExpandTuple t where type Result t expand :: t-Result t instance (Integral a)=ExpandTuple (a,a) where type Result (a,a) = (a,a,a) expand (x,y) = (x,y,1) instance (Integral a)=ExpandTuple (a,a,a) where type Result (a,a,a) = (a,a,a) expand = id But it's so verbose (even more so than similar C++ template code I guess), introduces an additional name (the typeclass) into the current scope, and requires 2 extensions: TypeFamilies and FlexibleInstances.Is there a cleaner way to do this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
What are you actually trying to do? This seems like a rather unusual function. Edward Excerpts from sdiyazg's message of Sun Oct 02 15:17:07 -0400 2011: Finally I got what I meant: class ExpandTuple t where type Result t expand :: t-Result t instance (Integral a)=ExpandTuple (a,a) where type Result (a,a) = (a,a,a) expand (x,y) = (x,y,1) instance (Integral a)=ExpandTuple (a,a,a) where type Result (a,a,a) = (a,a,a) expand = id But it's so verbose (even more so than similar C++ template code I guess), introduces an additional name (the typeclass) into the current scope, and requires 2 extensions: TypeFamilies and FlexibleInstances.Is there a cleaner way to do this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On Sun, Oct 2, 2011 at 4:26 PM, Edward Z. Yang ezy...@mit.edu wrote: What are you actually trying to do? This seems like a rather unusual function. If you're new to the language, most likely you're doing something wrong if you need this kind of function. =) -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On Sun, Oct 2, 2011 at 15:17, sdiy...@sjtu.edu.cn wrote: But it's so verbose (even more so than similar C++ template code I guess), introduces an additional name (the typeclass) into the current scope, and requires 2 extensions: TypeFamilies and FlexibleInstances.Is there a cleaner way to do this? Not for your meaning of clean. C++ is an object-oriented programming language; given a method call, it tries really hard to shoehorn the arguments to the call into some declared method somewhere along the inheritance chain. Haskell is a functional programming language; it is strongly typed, and typeclasses are a mechanism to allow that typing to be weakened in a strictly controlled fashion. In some sense, it's not *supposed* to be convenient, because the whole point is you're not supposed to throw arbitrarily-typed expressions at arbitrary functions. Instead, a properly designed program is characterized by its types; if the types are well designed for the problem being solved, they very nearly write the program by themselves. This doesn't mean that use of typeclasses / ad-hoc polymorphism is automatically a sign of a poor design, but it *does* mean you should think about what you're trying to do whenever you find yourself considering them. Nor does it mean that C++ is in some sense wrong; it means the languages are fundamentally different, and the appropriate design of a program is therefore also usually different between the two. -- 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] Is it possible to represent such polymorphism?
On Sun, Oct 2, 2011 at 2:17 PM, sdiy...@sjtu.edu.cn wrote: Finally I got what I meant: class ExpandTuple t where type Result t expand :: t-Result t instance (Integral a)=ExpandTuple (a,a) where type Result (a,a) = (a,a,a) expand (x,y) = (x,y,1) instance (Integral a)=ExpandTuple (a,a,a) where type Result (a,a,a) = (a,a,a) expand = id If I were writing this sort of function, I would simply write: expand (x, y) = (x, y, 1) and I would leave it at that. Since your 'expand' doesn't do anything the three-tuples, I don't see why I would want to call the function with a three-tuple argument. But I don't know your full use case. Antoine But it's so verbose (even more so than similar C++ template code I guess), introduces an additional name (the typeclass) into the current scope, and requires 2 extensions: TypeFamilies and FlexibleInstances.Is there a cleaner way to do this? ___ 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] Is it possible to represent such polymorphism?
Assuming that z :: Int, you can declare an algebraic datatype data TwoOrThree a b = Three (a, b, Int) | Two (a, b) deriving(Show, Eq) -- so you can experiment And then define expand as expand :: TwoOrThree a b - (a, b, Int) expand (Three tuple) = tuple expand (Two (a, b)) = (a, b, 1) Tom (amindfv) On Oct 2, 2011 6:04 AM, Du Xi sdiy...@sjtu.edu.cn wrote: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On 02/10/2011 07:15 PM, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? In C++, the code is inferred from the types. (I.e., if a function is overloaded, the correct implementation is selected depending on the types of the arguments.) In Haskell, the types are inferred from the code. (Which is why type signatures are optional.) Really, it's just approaching the same problem from a different direction. Also, as others have said, you're probably just approaching the problem from the wrong angle. You don't design an object-oriented program the same way you'd design a procedural program; if you do, you end up with a horrible design. Similarly, you don't design a functional program the same way you would design an object-oriented one. It takes time (and experience) to figure out how to approach FP - or any other radically different paradigm, I suppose... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
On 2011-10-02 14:15, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? Simple overloading is known as ad-hoc polymorphism, while Haskell's type system is based on parametric polymorphism. As Wikipedia says, Parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety. For example, functional programming gets a lot of power out of passing functions as arguments. Compare what this gives you in C++ versus Haskell. In C++ an overloaded function has multiple types, and when a function appears as an argument one of those types is selected. In Haskell, a polymorphic function can be passed as an argument, and it still can be used polymorphically within the function that receives it. When each name in the program has just one type, as in Haskell, type inference can be much more effective. Type declarations are not required. Most of the type declarations in my own Haskell code are there either for documentation, or to ensure that the compiler will catch type errors within a function definition. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it possible to represent such polymorphism?
Yes, do you have a Python background? Because I've often see misunderstanding about the utility of tuples with persons who were used to Python, because Python tutorials usually induce * BAD* practices in this respect (considering tuples and lists equivalent, for instance). Add to this the dynamic typing which allows you to have whatever type you want in your tuples' cells, and when coming to Haskell, it's somewhat uneasy to see that there is not a tuple type, but *an infinity*. My advice (which is only my opinion) is that you should restrict you use of tuples. For instance do not use them to make vectors (is it what you were trying to do? Because it looked like you were trying to handle 2D and 3D vectors), do something more type-explicit, by making a new datatype Vector, or 2 new datatypes Vector2 and Vector3. You shouldn't use tuples as a way to structure data (i.e. in replacement of real types), only for convenience when a function has to return several values. 2011/10/2 Felipe Almeida Lessa felipe.le...@gmail.com On Sun, Oct 2, 2011 at 4:26 PM, Edward Z. Yang ezy...@mit.edu wrote: What are you actually trying to do? This seems like a rather unusual function. If you're new to the language, most likely you're doing something wrong if you need this kind of function. =) -- Felipe. ___ 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] Is it possible to represent such polymorphism?
On 3/10/2011, at 7:15 AM, Du Xi wrote: I guess this is what I want, thank you all. Although I still wonder why something so simple in C++ is actually more verbose and requires less known features in Haskell...What was the design intent to disallow simple overloading? It's not SIMPLE overloading you are asking for, but AD HOC overloading, which may look simple, but really isn't. Taking your C++ f() example, in what sense are the two functions _the same function_? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parameters and patterns
On 2/10/2011, at 3:27 AM, José Romildo Malaquias wrote: Hello. When studing programming languages I have learned that parameter is a variable (name) that appears in a function definition and denotes the value to which the function is applied when the function is called. Who told you that? Variables are one thing and names are another. I think you are talking about what the definition of Algol 60 called a formal parameter. It's worth noting that formal parameters in Algol 60 could be labels, switches, and procedures, while there were no label variables, switch variables, or procedure variables. Names and variables are *really* different things. For what it's worth, the Haskell 2010 report appears to use parameter informally to mean - a formal parameter of a function - a formal parameter position of a type constructor - a constant characterising a numeric type but I don't see a precise definition anywhere. Argument is the value to which the function is applied. I think you are talking about what the definition of Algol 60 called an actual parameter. The word argument is very often used for formal parameters too. For what it's worth, the Haskell 2010 report appears to use argument informally to mean - an actual parameter of a function - an actual parameter of a type constructor but I don't see a precise definition anywhere. Now I am not sure how to apply these concepts to Haskell, as Haskell uses pattern matching to deal with argument passing to functions. Realise that what you thought you knew was a half truth: all formal parameters are patterns, and all (new) identifiers are patterns, but not all patterns are identifiers. (And of course that is a half truth too.) For instance, in the definition f x = 2 * x + 1 x is a parameter, and in the application a parameter, or an argument, or a formal parameter, or a formal argument, or what you please. f 34 34 is an argument an argument, or a parameter, or an actual parameter, or an actual argument, or what you please. But in the definition g (_:xs) = xs what is the parameter of the function g? Is it the pattern (_:xs)? If so then a parameter is not necessarily a variable anymore, and that seems very strange. Why? Patterns are a generalisation of variables. Practically all functional languages since lisp use pattern matching, and even Lisp these days has destructuring-bind. And what is xs? Is it a parameter, although it does not denote the value to which the function is aplied, but just part of it? This is the point where some people would say this is just semantics. The problem is that it is precisely NOT semantics. You clearly understand the *semantics* here; what's bothering you is the lexical level, what to call something. The first occurrence of xs is a binding occurrence of an identifier inside a formal parameter and the second occurrence is an applied occurence of an identifier. The Haskell 2010 report often uses parameter to refer to a formal parameter _place_ of a function rather than to the text that fills that place in a function definition. On that reading, (_:xs) is *not* a parameter, it's a pattern that appears in the first parameter *position* of g, and parameters as such do not have names. I am writing some slides to use in my functional programming classes, but I am not sure how to deal with these terms. Consistently with the text-book. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ghc 7.2.1 and super simple DPH
Hi - I'm trying to compile DotP.hs from http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell#A_simple_example (see below) The compiler complains and says (twice in fact): DotP.hs:17:33: Not in scope: `fromPArrayP' Could someone help me out please? Thanks a lot! Peter {-# LANGUAGE ParallelArrays #-}{-# OPTIONS_GHC -fvectorise #-} module DotP (dotp_wrapper)where import qualified Preludeimport Data.Array.Parallel.Preludeimport Data.Array.Parallel.Prelude.Double dotp_double :: [:Double:] - [:Double:] - Double dotp_double xs ys = sumP [:x * y | x - xs | y - ys:] dotp_wrapper :: PArray Double - PArray Double - Double{-# NOINLINE dotp_wrapper #-} dotp_wrapper v w = dotp_double (fromPArrayP v) (fromPArrayP w) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem on using template haskell.
Hi, I am trying to use data-flags library. And failed on compiling the test code. The code is like following, and the compiling error is test.hs:4:24: parse error on input `{' {-# LANGUAGE TemplateHaskell #-} import Data.Flags.TH $(bitmaskWrapper Severity ''Int [] False [ (NotClassified, #{const (2 ^ 0)}) , (Information, #{const (2 ^ 1)}) , (Warning, #{const (2 ^ 2)}) , (Average, #{const (2 ^ 3)}) , (High, #{const (2 ^ 4)}) , (Disaster, #{const (2 ^ 5)}) What should I do? -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem on using template haskell.
On Mon, Oct 3, 2011 at 1:44 PM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Hi, I am trying to use data-flags library. And failed on compiling the test code. The code is like following, and the compiling error is test.hs:4:24: parse error on input `{' {-# LANGUAGE TemplateHaskell #-} import Data.Flags.TH $(bitmaskWrapper Severity ''Int [] False [ (NotClassified, #{const (2 ^ 0)}) , (Information, #{const (2 ^ 1)}) , (Warning, #{const (2 ^ 2)}) , (Average, #{const (2 ^ 3)}) , (High, #{const (2 ^ 4)}) , (Disaster, #{const (2 ^ 5)}) What should I do? -- 竹密岂妨流水过 山高哪阻野云飞 Sorry, please ignore this mail. I forgot the TH syntax. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to compile this example code?
Hi, I am learning to use data-flags, and got this example code: import Data.Flags newtype MyFlags = MyFlags CInt deriving (Eq, Flags) #{enum MyFlags, MyFlags , myFlag1 = C_FLAG1 , myFlag2 = C_FLAG2 , myFlag3 = C_FLAG3 } I modified it trying to compile it. Well, I got illegal syntax at #{e. In fact, I am not quite know the syntax here. Any clue? -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe