[Haskell-cafe] Fuse functions given to map and filter without RULES pragma
I've found a funny way to fuse functions given to map and filter without RULES pragma: toSelect = (,) Just fromSelect = uncurry mapMaybe transformFirst f (x, y) = (f x, y) maybe f = transformFirst (\g x -> g x >>= f) map f = maybe (Just . f) filter f = maybe (\x -> if f x then Just x else Nothing) test :: [Int] test = fromSelect (map (*2) (filter (<10) (map (+3) (toSelect [1,3,4,6,8] Everything looks like obvious application of filter and map, but GHC inline (*2), (<10), (+3) (with -O flag) :^). -- Best regards, RB. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HaskellWiki and Wikipedia
Hi all. There are some notions which are not described in HaskellWiki but described in Wikipedia, e.g. "catamorphism". When clicking on a link [[catamorphism]] that leads to "create a new page" it would be nice to show link to a corresponding Wikipedia page. Also "search in Wikipedia" on the search results page. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
I mean that a link [[X]] leads to HaskellWiki if X exists in HaskellWiki and to Wikipedia otherwise. Interwiki links requires to change all occurrences of [[X]] when X is created. |[[wikipedia:|{{PAGENAME}}|]]| may be handy on existing pages, it provides a link to additional material. On 17.06.10 03:11, Jason Dagit wrote: Both use the mediawiki engine. I know at one point mediawiki supported a notion of "interwiki" links. Perhaps this feature still exists and would give a way for us to more naturally link to wikipedia articles? http://www.mediawiki.org/wiki/Help:Links#Interwiki_links -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
I do not agree. They are not confused by other languages, they treat all languages as born equal. Do not forget, mathematics is the common source of knowledge for all programmers, creating our separate source of knowledge leads to isolationism and narrow-minded vision. If my words are too vague — "catamorphism" and "F-algebra" belong to mathematics, not to Haskell. Maybe Wikipedia articles are bad because they are provided by community — then HaskellWiki will suffer likewise. :( On 16.06.10 23:19, Ketil Malde wrote: Edward Kmett writes: I realize that this is addressing the symptom, not the cause I'm not so sure Wikipedia is a good source of information for this. I've tried to read some of their articles on e.g. type systems or generic programming, but they tend to be confused by other languages and their communities using these terms to mean different things. So I think it is better to build on the HaskellWiki where the words can mean what we want them to. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
On 17.06.10 12:40, Roman Cheplyaka wrote: > From reading core I got the impression that everything is strict& unboxed. Perhaps this is related to creating some closures? How to get rid of those allocations? Yes, "distance" creates a closure of type @Double -> Double# -> Double@ which is obviously not necessary. I do not know why. 2. Again from reading the core I learned that although 'l' and other constants are inlined, their type is boxed Double. This makes sense since CAFs are evaluated on demand, but obviously in this particular case it does not make sense, so can I somehow make them unboxed Hmm, I learned from "-ddump-core" that "distance" function uses constant "25.0". There is another way to optimize — make GHC use floating point "abs" processor instruction. Now it uses {{{ abs x | x >= 0.0 = x | otherwise = negateDouble x }}} http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-Float.html -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
map (\function -> function argument) functions map ($ argument) functions map (\firstArgument -> function firstArgument secondArgument thirdArgument) xs On 17.06.10 22:02, Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
On 17.06.10 19:12, Roman Beslik wrote: On 17.06.10 12:40, Roman Cheplyaka wrote: > From reading core I got the impression that everything is strict& unboxed. Perhaps this is related to creating some closures? How to get rid of those allocations? Yes, "distance" creates a closure of type @Double -> Double# -> Double@ which is obviously not necessary. I do not know why. "-funfolding-use-threshold=7" removes that closure. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
On 18.06.10 07:41, Jason Dagit wrote: On Thu, Jun 17, 2010 at 6:36 AM, Roman Beslik <mailto:ber...@ukr.net>> wrote: I mean that a link [[X]] leads to HaskellWiki if X exists in HaskellWiki and to Wikipedia otherwise. I think this is probably a bad idea. Imagine trying to create a new page on the haskellwiki when wikipedia already has an article by the same name. O'kay, [[X]] leads to a page with links "Create the page X" and "Go to Wikipedia". -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
On 17.06.10 23:44, Ketil Malde wrote: Roman Beslik writes: I do not agree. They are not confused by other languages, they treat all languages as born equal. Are you saying this is a good thing? Yes. There is more than Haskell. E.g the article on generic programming mainly talks about parametric polymorphism. "Generic programming" is a bad term so I do not care if it is used in the Haskell sense or in the Wikipedia sense. It should not be used at all. The article on type systems starts off with some definitions by Cardelli, but goes on to discuss so-called dynamic type systems, which are an entirely different thing. Do we read different Wikipedia-s? Wikipedia article "Type system" discussed all kinds of type system, including dependent, linear, intersection. Yes, dynamic typing is a type system. Sorry, dear, I forgot you did not like it. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHCi and State
On 25.06.10 12:07, corentin.dup...@ext.mpsa.com wrote: 2. For now, the game is more or less playable in GHCi. But my concern is: When you use GHCi, you are in the IO monad, right? How to had state to this monad? I would like that the player can compose his rule in GHCi, and when he is done, he can submit it in GHCi with something like: *Nomic> submitRule You can store a set of rules in IORef or another IO-mutable type. I think "you are in the IO monad" is pretty vague. Obviously, GHCi runs pure computations also. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 25.06.10 20:09, Jason Dagit wrote: you got everything right here. So, as you said, there is a mismatch between representation in Haskell (list of code points) and representation in the operating system (list of bytes), so we need to know the encoding. Encoding is supplied by the user via locale (https://secure.wikimedia.org/wikipedia/en/wiki/Locale), particularly LC_CTYPE variable. The problem with encodings is not new -- it was already solved e.g. for input/output. This is the part where I don't understand the problem well. I thought that with IO the program assumes the locale of the environment but that with filepaths you don't know what locale (more specifically which encoding) they were created with. So if you try to treat them as having the locale of the current environment you run the risk of misunderstanding their encoding. Incorrect encoding of filepaths is common in e.g. Cyrillic Linux (because of multiple possible encodings --- CP1251, KOI8-R, UTF-8) and is solved by fiddling with the current locale and media mount options. No need to change a program, or to tell character encoding to a program. It is not a programming language issue. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 26.06.10 16:34, Alexey Khudyakov wrote: On Sat, 26 Jun 2010 10:14:50 -0300 Felipe Lessa wrote: On Sat, Jun 26, 2010 at 05:01:06PM +0400, Bulat Ziganshin wrote: but what you propose cannot be used in Windows at all! while current FilePath still works on Unix, with manual filenames en/decoding Now we got back on topic! :) The FilePath datatype is OS-dependent and making it abstract should be at least a first step. If you got it from somewhere else where it is already encoded, then fine. If you need to construct it, then you need to use a smart constructor. If you need to show/print it, then you need to convert it to String. And so on. It should solve most of problems I believe. But such change will break a lot of programs maybe most of them. How could one introduce such a change? One variant is to create new hierarchy and gradually deprecate old. I fail to see how it will brake programs. Current programs do not use Unicode because it is implemented incorrectly. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 26.06.10 15:44, Felipe Lessa wrote: On Sat, Jun 26, 2010 at 09:29:29AM +0300, Roman Beslik wrote: Incorrect encoding of filepaths is common in e.g. Cyrillic Linux (because of multiple possible encodings --- CP1251, KOI8-R, UTF-8) and is solved by fiddling with the current locale and media mount options. No need to change a program, or to tell character encoding to a program. It is not a programming language issue. If your program saves files using filepaths given by the user or created programatically from another filepath, then you don't need to decode/encode anything and the problem isn't in the programming language. However, suppose your program needs to create a file with a name based on a database information. Your database is UTF-8. How do you translate that UTF-8 data into a filepath? This is the problem we got in Haskell. We have a nice coding-agnostic String datatype, but we don't know how to create a file with this very name. It is simple — you recode from (database | "network server" | file) encoding to the current locale. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 27.06.10 04:07, Brandon S Allbery KF8NH wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 6/26/10 19:52 , Roman Beslik wrote: I fail to see how it will brake programs. Current programs do not use Unicode because it is implemented incorrectly. Currently, FilePath is an alias for String. Changing FilePath to a real type Just do not change FilePath, what may be simpler? -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 27.06.10 03:58, Felipe Lessa wrote: On Sun, Jun 27, 2010 at 02:55:33AM +0300, Roman Beslik wrote: On 26.06.10 15:44, Felipe Lessa wrote: However, suppose your program needs to create a file with a name based on a database information. Your database is UTF-8. How do you translate that UTF-8 data into a filepath? This is the problem we got in Haskell. We have a nice coding-agnostic String datatype, but we don't know how to create a file with this very name. It is simple — you recode from (database | "network server" | file) encoding to the current locale. Recoding is indeed very simple. You know the source coding (e.g. your database is in UTF-8). But how do you discover the target coding? How can you find out that this system uses ISO8859-1, while this other one uses UTF-16, while...? See the problem now? :) No! The target encoding is the current locale. It is a no-brainer to find it. Use your Unix. $ man setlocale $ locale -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 27.06.10 09:38, Bulat Ziganshin wrote: Sunday, June 27, 2010, 3:52:54 AM, you wrote: I fail to see how it will brake programs. Current programs do not use Unicode because it is implemented incorrectly. i use it. current Linux implementation treats String as sequence of bytes, and with manual recoding it allows to use filesystems with any encoding O'kay, but IMHO few people want to have a headache with recoding. You knew that the implementation was incorrect, why you relied on it? -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 27.06.10 10:17, Bulat Ziganshin wrote: Sunday, June 27, 2010, 11:07:47 AM, you wrote: Currently, FilePath is an alias for String. Changing FilePath to a real type Just do not change FilePath, what may be simpler? if FilePath will become abstract type, it will break all programs that use it since they use it as String Hello, do you read me? I said: "do not change FilePath". -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Core packages and locale support
On 27.06.10 10:18, Bulat Ziganshin wrote: Hello Roman, Sunday, June 27, 2010, 11:11:59 AM, you wrote: No! The target encoding is the current locale. It is a no-brainer to not necessarily. current locale, encoding of current terminal and encoding of every filesystem mounted are all different things And we should stick to the current locale. Problem solved. "6.3 CString The module CString provides routines marshalling Haskell into C strings and vice versa. The marshalling converts each Haskell character, representing a Unicode code point, to one or more bytes in a manner that, by default, is determined by the *current locale*." "The Haskell 98 Foreign Function Interface." -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] whine and solution about programmers not respecting documentations
In the case of 'deleteBy' we can improve an API. deleteBy eq x xs == deletePred (eq x) xs @deletePred pred xs@ removes the first element of @xs@ which satisfies a predicate @p...@. Your solution is more general. :) On 28.06.10 22:44, Albert Y.C.Lai wrote: And then some programmers are in a miserable state of not respecting docs when the docs are complete. Why should anyone expect deleteBy (>=) 5 [0..10] -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] whine and solution about programmers not respecting documentations
On 29.06.10 08:37, Ketil Malde wrote: Albert Y.C.Lai writes: The doc of deleteBy states: "The deleteBy function behaves like delete, but takes a user-supplied equality predicate." A precondition is that the user-supplied predicate is an equality predicate. (>=) is not an equality predicate, be it in the layperson sense of "it isn't analogous to (==)" or the mathematical sense of "it isn't an equivalence relation". One could argue that this is a bad specification. The type is deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] but there are further limitations on the arguments, and worse, the function doesn't check this and produce an error if the arguments don't conform, but just silently produces a meaningless result. How can 'deleteBy' check that an argument is an equivalence relation? (Putting aside that this harms performance.) -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Equivalence of two expressions
Hi. On 10.07.10 21:40, Grigory Sarnitskiy wrote: I'm not very familiar with algebra and I have a question. Imagine we have ring K. We also have two expressions formed by elements from K and binary operations (+) (*) from K. In what follows I assume "elements from K" ==> "variables" Can we decide weather these two expressions are equivalent? If there is such an algorithm, where can I find something in Haskell about it? Using distributivity of ring you convert an expression to a normal form. "A normal form" is "a sum of products". If normal forms are equal (up to associativity and commutativity of ring), expressions are equivalent. I am not aware whether Haskell has a library. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Handling absent maintainers
I patch broken packages in my local repository. I increment a version so the local repository get a precedence over the Hackage. On 16.07.10 03:54, Mark Wotton wrote: 2. run my own hackage server and tell my users to use that instead. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] a patch for base.Foreign.C.String, the current locale
Hi. I have composed a patch that implements Foreign.C.String according to Foreign Function Interface Addendum, i.e. C strings are treated as they are encoded with the current locale. Search "Locale.hs" in the patch for further directions. Ask if you do not know how to build a patched version of the "base" library. http://www.beroal.in.ua/prg/haskell/locale.patch -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Forum
Hi. I personally find web-forum a more convenient and structured way of communication. I will help if the forum exports posts or topics as a feed. Are you strictly devoted to phpBB? I think that fluxBB is a decent choice. Just suggesting. On 26.07.10 16:30, Daniel Díaz wrote: I want to open a Haskell forum based on phpBB, but I need some collaborators for organize its content, and moderate its use. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] delete http://www.haskell.org/haskellwiki/Haskell_IDE
Hi. There is more verbose page http://www.haskell.org/haskellwiki/IDEs . I registered on http://www.haskell.org/haskellwiki/ , but have not found the "Delete Page" command, wiki software help pages, or feedback channel, so I'm writing here. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] delete http://www.haskell.org/haskellwiki/Haskell_IDE
A humble link "What links here" to the right will help you find those pages. On 28.11.12 21:53, Brent Yorgey wrote: is probably not a good idea anyway -- what if there are other pages that link to it? On Wed, Nov 28, 2012 at 07:08:16PM +0200, Roman Beslik wrote: Hi. There is more verbose page http://www.haskell.org/haskellwiki/IDEs . I registered on http://www.haskell.org/haskellwiki/ , but have not found the "Delete Page" command, wiki software help pages, or feedback channel, so I'm writing here. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] delete http://www.haskell.org/haskellwiki/Haskell_IDE
Good point. Done. On 29.11.12 06:16, Conrad Parker wrote: #REDIRECT [[IDEs]] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] module -> package
Hello. How can I find which installed package a specified module belongs to? ghci or cabal or ghc-pkg? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] categories in Haskell and module names
Hello. IMHO there are 2 ways to define categories in Haskell: W0) the category of types and functions ("base.Data.Functor" and company belongs to it); W1) the class "base.Control.Category.Category". (Defining a category where the class of objects is a type seems impossible in Haskell.) But these ways are mingled in "base". E.g. "Control.Applicative" (W0) and "Control.Category" (W1) are neighbors. Oddly, "Data.Functor" (W0) is under "Data". I believe that the whole library "category-extras" belongs to W1. I suggest to split these ways under distinct names, e.g.: W0) Category.Function (@hom == (->)@); W1) Category.Hom ("hom" is an abstract type constructor). Maybe both should be under "Mathematics". ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Best bit LIST data structure
I am not aware of such a library, but IMHO this code will be very simple. > data Bits b => BitList b = BitList Int {- number of used bits in the next component -} b [b] Write an isomorphism between @BitList b@ and @ListStep (BitList b)@ where > data ListStep e rc = Nil | Cons e rc On 07.10.11 17:52, Ryan Newton wrote: Hi Cafe, We are lucky to have a plethora of data structures out there. But it does make choosing one off hackage difficult at times. In this case I'm *not* looking for a O(1) access bit vector (Data.Vector.Unboxed seems to be the choice there), but an efficient representation for a list of bits (cons,head,tail). Let's say that you want to represent tree indices as you walk down a binary tree. [Bool] is a simple choice, you only add to the front of the list (0/1 = Left/Right), sharing the tails. But [Bool] is quite space inefficient. Something like [Int] would allow packing the bits more efficiently. A Lazy ByteString could amortize the space overhead even more... but in both cases there's a tiny bit of work to do in wrapping those structures for per-bit access. That's probably the right thing but I wanted to check to see if there's something else recommended, perhaps more off-the-shelf. What about just using the Data.Bits instance of Integer? Well, presently, the setBit instance for very large integers creates a whole new integer, shifts, and xors: http://haskell.org/ghc/docs/latest/html/libraries/base/src/Data-Bits.html#setBit (I don't know if it's possible to do better. From quick googling GMP seems to use an array of "limbs" rather than a chunked list, so maybe there's no way to treat large Integers as a list and update only the front...) Advice appreciated! Thanks, -Ryan ___ 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] Best bit LIST data structure
Yes, if you do not use high-level concepts and optimize everything by hand, it requires a lot of testing. :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe