[Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
Hi, In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen It looks like 'writeFile' can not write unicode characters. Any workarounds? Thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
Correct url of a bad string: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote: Hi, In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen It looks like 'writeFile' can not write unicode characters. Any workarounds? Thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Anonymous, Unique Types, maybe
On 12/04/2011 06:53 AM, Scott Lawrence wrote: [...] Some operators might take more than one list/stream as an argument, combining them in some way or another. Obviously, if the lists were different lengths, the operator would fail. I don't want that to happen at run time, so I want to check for it statically, presumably via the type system. I could do this manually: type AList = [Event] type BList = [Event] type CList = [Event] myMapish :: AList - AList mySelect :: AList - (Event - Bool) - BList myOtherSelect :: BList - CList [...] Just as a small side note, with the 'type' keyword, AList, BList, CList will /not/ be seen as separate types (but they're all the same type, namely [Event]). If you want separate types, you would use a newtype wrapper like newtype AList = AList [Event] deriving (some instances you want to derive from [Event]) -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Anonymous, Unique Types, maybe
On 12/04/11 02:25, Stephen Tetley wrote: Umm, an obvious point is that if you really are using lists as streams they should appear infinite to the processing code, so you shouldn't encounter operations that fail due to incompatible lengths. Didn't explain myself quite right, I guess. The lists are infinite; however, when a function (which doesn't call `filter`) produces more than one list, the two lists are related in that the nth elements of each list came from the same source. Pairing every nth element is meaningfull for two such lists/streams. In contrast, a list coming out of `filter` isn't related to the list going in in this way, and shouldn't be re-paired with that list (or a direct derivative). My goal, again, is to represent that distinction in the type system. -- Scott Lawrence ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get a file path to the program invoked?
Quoth wren ng thornton w...@freegeek.org, There was a discussion about this recently over on libraries@, IIRC. The short answer is that, at present, there is no function to give you $0. We'd like to add such a function, but it's not been done yet. Part of the problem is that, as Alexey says, the first element of argv is just whatever is passed to exec, which is not guaranteed to be a complete path, a canonical path, or any other specific thing we'd desire. It's not at all straightforward to determine the actual location of the executable, especially not in a platform-independent manner. argv[0] can't be trusted, scanning through $PATH isn't guaranteed to find it (and even if you find something of the right name, it's not guaranteed to be the correct executable), etc etc. This isn't your problem, though. I mean, if the proposed function is to return the path to the executable file, then indeed you have a big problem with argv[0]. argv[0] can be anything - or nothing (it can be a null string.) But if we've turned to the question of whether to return argv[0], that's much simpler: you don't need to consider why a programmer might want it. It's appalling to think that library developers would withhold access to standard POSIX 1003.1 features while they decide whether they approve of them. Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Anonymous, Unique Types, maybe
On Sun, Dec 4, 2011 at 3:53 AM, Scott Lawrence byt...@gmail.com wrote: type AList = [Event] type BList = [Event] type CList = [Event] myMapish :: AList - AList mySelect :: AList - (Event - Bool) - BList myOtherSelect :: BList - CList A suggestion: data Exists f = forall a. Exists f a data List a = List [Event] -- your list type myMapish :: List a - List a myDoSomething :: List a - (List a, List a) myPair :: (Event - Event - Event) - List a - List a - List a mySelect :: List a - Exists List So the anonymous, unique type would be enclosed on the existential. Its real type doesn't really matter, it may be always (), but code that uses mySelect can't use this fact. It's not able to do even something simple like let Exists b = mySelect a Exists c = mySelect a in myPair f b c even though we know that in this case this is valid =). But you can always make unsafeCastList :: List a - List b unsafeCastList (List a) = List a Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
What is the value of your LANG environment variable? Does it still give the error if you set it to e.g. en_US.UTF-8? Erik On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote: Correct url of a bad string: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote: Hi, In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen It looks like 'writeFile' can not write unicode characters. Any workarounds? Thanks! Dmitri ___ 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] Anonymous, Unique Types, maybe
Hi Scott, a good idea. Why not use an existential to encode your types like myMap :: (a - b) - a-list of length n - b-list of length n myFilter :: (a - Bool) - a-list of length n - exists m. a-list of length m , where the first case is modeled using a type annotation and the second using an existential: {-# LANGUAGE ExistentialQuantification #-} -- just for @data S@ at the very end. {-# LANGUAGE EmptyDataDecls #-} -- don't export the LList constructor! data LList n a = LList [a] llist2List :: LList n a - [a] llist2List (LList xs) = xs unsafeList2LList :: [a] - LList n a unsafeList2LList = LList unsafeWrapLList :: ([a] - [b]) - LList n a - LList m b unsafeWrapLList f = unsafeList2LList . f . llist2List unsafeCoerceLList :: LList n a - LList m a unsafeCoerceLList = unsafeWrapLList id mapLList :: (a - b) - LList n a - LList n b mapLList f = unsafeList2LList . map f . llist2List -- should be exported. data SomeLList a = forall n. SomeLList (LList n a) -- this is safe again! (SomeLList a) is a lot like [a]. list2SomeLList :: [a] - SomeLList a list2SomeLList = SomeLList . unsafeList2LList wrapSomeLList :: ([a] - [b]) - SomeLList a - SomeLList b wrapSomeLList f (SomeLList ll) = list2SomeLList . f . llist2List $ ll myFilter :: (a - Bool) - LList n a - SomeLList a myFilter p = list2SomeLList . filter p . llist2List -- NOTE that we're being extremely imprecise about the length of -- lists. We don't say one less, but just potentially different. myTail :: LList n a - SomeLList a myTail lst = case llist2List lst of [] - error myTail: empty list (_:xs) - list2SomeLList xs myMap :: (a - b) - LList n a - LList n b myMap = mapLList myMatchingZip :: LList n a - LList n b - LList n (a, b) myMatchingZip xs ys = unsafeList2LList $ zip (llist2List xs) (llist2List ys) -- test: test_input :: (Num a, Enum a) = [a] test_input = [1..10] test_works :: (Num a, Enum a) = SomeLList (a, a) test_works = SomeLList $ case list2SomeLList test_input of (SomeLList il) - myMatchingZip il (myMap (*2) il) -- ^ It's important to have the input bound to /one/ variable -- of type LList n a ('il' here). -- Otherwise, we don't get enough type equality. {- -- @myMatchingZip il (myFilter isEven il)@ plus type safety. -- Gives a Couldn't match type `n1' with `n' type error, which is correct. test_illegal = SomeLList $ case list2SomeLList test_input of (SomeLList il)- case myFilter isEven il of (SomeLList evens) - myMatchingZip il evens where isEven x = x `mod` 2 == 0 -} So 'n' here corresponds to what your 'a' is below, and 'a' here is always 'Event' below. Note that you don't have to actually encode the length of lists in the type system using this approach. I hit a similar problem some months ago when trying to model financial contracts: Prices are only comparable when they are given at the same time and in the same currency, but I wasn't going to encode currencies or times in the type system. I just wanted the compiler to check if it could prove two prices are compatible and if not, I would convert them (which was cheap). Using more sophisticated types for 'n', we can express richer properties. For example: data S n myBetterTail :: LList (S n) a - LList n a myBetterTail l = case myTail l of (SomeLList ll) - unsafeCoerceLList ll myBetterCons :: a - LList n a - LList (S n) a myBetterCons x = unsafeWrapLList (x:) test_do_nothing :: a - LList n a - LList n a test_do_nothing x = myBetterTail . myBetterCons x Cheers, Steffen On 12/04/2011 06:53 AM, Scott Lawrence wrote: (Sorry if this email is rather unclear - I know my desired end result, but neither how to acheive nor explain it well. Here goes.) I'm processing lists, using them sortof as streams. (Whether that's a good idea isn't the issue here - but let me know if it isn't!) Fundamentally, there are two types of operations (at least, that are relevant here) - those that change the length of the list and those that don't. Some operators might take more than one list/stream as an argument, combining them in some way or another. Obviously, if the lists were different lengths, the operator would fail. I don't want that to happen at run time, so I want to check for it statically, presumably via the type system. I could do this manually: type AList = [Event] type BList = [Event] type CList = [Event] myMapish :: AList - AList mySelect :: AList - (Event - Bool) - BList myOtherSelect :: BList - CList but I'd rather not have to manually define a new type for every new list length: myMapish :: List a - List a mySelect :: List a - List ? The '?' would be an anonymous, unique type - unless there's a better way to accomplish this. Hope that was clear, and thanks (as always) for the help (and being awesome). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org
Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
Is there any other way to solve this problem without changing LANG environment variable? On Sun, Dec 4, 2011 at 8:27 PM, Erik Hesselink hessel...@gmail.com wrote: What is the value of your LANG environment variable? Does it still give the error if you set it to e.g. en_US.UTF-8? Erik On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote: Correct url of a bad string: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote: Hi, In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen It looks like 'writeFile' can not write unicode characters. Any workarounds? Thanks! Dmitri ___ 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] Anonymous, Unique Types, maybe
Thanks all; I haven't quite gotten it to work, but I imagine I'll be able to now (after reading up on ExistentialQuantification). -- Scott Lawrence ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
On 11-12-04 07:08 AM, dokondr wrote: In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen http://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen \55357 and \56384 would be surrogates D83D and DC40 for use in UTF-16 only. Haskell's Char is not a UTF-16 code unit (unlike early versions of Java and probably current ones). GHC is correct in rejecting them. Haskell's Char is a Unicode character directly. If you want the character U+1F440 EYES, write \128064 directly (or \x1f440, or \x1F440). Use http://www.unicode.org/charts/ to find out what you are getting into. You can enter a hexadecimal number or choose a category. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)
Yes, you can set the text encoding on the handle you're reading this text from [1]. The default text encoding is determined by the environment, which is why I asked about LANG. If you're entering literal strings, see Albert Lai's answer. Erik [1] http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#g:23 On Sun, Dec 4, 2011 at 19:13, dokondr doko...@gmail.com wrote: Is there any other way to solve this problem without changing LANG environment variable? On Sun, Dec 4, 2011 at 8:27 PM, Erik Hesselink hessel...@gmail.com wrote: What is the value of your LANG environment variable? Does it still give the error if you set it to e.g. en_US.UTF-8? Erik On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote: Correct url of a bad string: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote: Hi, In GHC 7.0.3 / Mac OS X when trying to: writeFile someFile (Hoping You Have A iPhone When I Do This) Lol Sleep Is When You Close These ---gt; \55357\56384 I get: commitBuffer: invalid argument (Illegal byte sequence) The string I am trying to write can also be seen here: http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen It looks like 'writeFile' can not write unicode characters. Any workarounds? Thanks! Dmitri ___ 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] Haskell at University in Munich
Hello Haskell Cafe, I would be grateful for any information regarding Haskell (or at least Functional Programming) lectures at Universities near to Munich, Germany (Master or Bachelor). Unconfirmed information I've got regarding LMU and TUM are not promising. If Munich and 200 km circle do not provide with any offer, perhaps you may know what is available in Europe, limiting language of study to [German, English, Polish]? Best regards, Bartek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get a file path to the program invoked?
dokondr On the contrary, standard shell variable $0 - contains a full dokondr path to the program location in the directory structure, no dokondr matter from what directory the program was called. I don't think the comparison makes sense, as shell script invocation and executable run are very different mechanisms. Whenever you invoke a shell script, what really happens is that a program in your path (sh, bash ...) gets started with an argument that is the path to the script to load (your script actually). In this situation, you understand that it is easy to provide the path to the script (the $0) : it is just the file that the interpreter is loading. I don't know if it is possible at all to get this information in the context of binary execution. And I'm not sure it is a good practice anyway :) -- Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get a file path to the program invoked?
On 4/12/2011, at 7:32 PM, wren ng thornton wrote: Part of the problem is that, as Alexey says, the first element of argv is just whatever is passed to exec, which is not guaranteed to be a complete path, a canonical path, or any other specific thing we'd desire. It's not at all straightforward to determine the actual location of the executable, especially not in a platform-independent manner. argv[0] can't be trusted, scanning through $PATH isn't guaranteed to find it (and even if you find something of the right name, it's not guaranteed to be the correct executable), etc etc. In particular, with posix_spawnp(), the $PATH that is used to find the executable and the $PATH in the environment that the executable starts with can be two different things. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to get a file path to the program invoked?
It's not a poor practice at all. Example: gcc, which uses the executable's path as the base directory from which other files are located. MacOS also does something similar. -Original message- From: Paul R paul.r...@gmail.com To: dokondr doko...@gmail.com Cc: Simon Hengel simon.hen...@wiktory.org, haskell-cafe haskell-cafe@haskell.org Sent: Sun, Dec 4, 2011 15:26:28 PST Subject: Re: [Haskell-cafe] How to get a file path to the program invoked? dokondr On the contrary, standard shell variable $0 - contains a full dokondr path to the program location in the directory structure, no dokondr matter from what directory the program was called. I don't think the comparison makes sense, as shell script invocation and executable run are very different mechanisms. Whenever you invoke a shell script, what really happens is that a program in your path (sh, bash ...) gets started with an argument that is the path to the script to load (your script actually). In this situation, you understand that it is easy to provide the path to the script (the $0) : it is just the file that the interpreter is loading. I don't know if it is possible at all to get this information in the context of binary execution. And I'm not sure it is a good practice anyway :) -- Paul ___ 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] How to get a file path to the program invoked?
That's true even for regular fork/exec. -Original message- From: Richard O'Keefe o...@cs.otago.ac.nz To: wren ng thornton w...@freegeek.org Cc: haskell-cafe haskell-cafe@haskell.org Sent: Sun, Dec 4, 2011 15:54:15 PST Subject: Re: [Haskell-cafe] How to get a file path to the program invoked? On 4/12/2011, at 7:32 PM, wren ng thornton wrote: Part of the problem is that, as Alexey says, the first element of argv is just whatever is passed to exec, which is not guaranteed to be a complete path, a canonical path, or any other specific thing we'd desire. It's not at all straightforward to determine the actual location of the executable, especially not in a platform-independent manner. argv[0] can't be trusted, scanning through $PATH isn't guaranteed to find it (and even if you find something of the right name, it's not guaranteed to be the correct executable), etc etc. In particular, with posix_spawnp(), the $PATH that is used to find the executable and the $PATH in the environment that the executable starts with can be two different things. ___ 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