Re: [Haskell-cafe] Lifting IO actions into Applicatives
What about (Compose Form IO) Blog type? Form is Applicative, IO — the same, their composition should be Applicative as well (one good thing about Applicatives — they really compose). Take a look at Control.Compose module. Отправлено с iPad 01 окт. 2013 г., в 10:58, Michael Snoyman mich...@snoyman.com написал(а): I'm wondering if anyone's run into this problem before, and if there's a common solution. In Yesod, we have applicative forms (based originally on formlets). These forms are instances of Applicative, but not of Monad. Let's consider a situation where we want to get some user input to fill out a blog post datatype, which includes the current time: data Blog = Blog Title UTCTime Contents myBlogForm :: Form Blog myBlogForm = Blog $ titleForm * something * contentsForm The question is: what goes in something? Its type has to be: something :: Form UTCTime Ideally, I'd call getCurrentTime. The question is: how do I lift that into a Form? Since Form is only an Applicative, not a Monad, I can't create a MonadIO instance. However, Form is in fact built on top of IO[1]. And it's possible to create a MonadTrans instance for Form, since it's entirely possible to lift actions from the underlying functor/monad into Form. So something can be written as: something = lift $ liftIO getCurrentTime This works, but is unintuitive. One solution would be to have an ApplicativeIO typeclass and then use liftIOA. My questions here are: 1. Has anyone else run into this issue? 2. Is there an existing solution out there? Michael [1] Full crazy definition is at: http://haddocks.fpcomplete.com/fp/7.4.2/20130922-179/yesod-form/Yesod-Form-Types.html#t:AForm ___ 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] Looking for numbers to support using haskell
The classical reference is, I think, the paper “Haskell vs. Ada vs. C++ vs. Awk vs. ... An Experiment in Software Prototyping Productivity” On Sep 23, 2013, at 9:20 PM, Mike Meyer m...@mired.org wrote: Hi all, I'm looking for articles that provide some technical support for why Haskell rocks. Not just cheerleading, but something with a bit of real information in it - a comparison of code snippets in multiple languages, or the results of a study on programmer productivity (given all the noise and heat on the topic of type checking, surely there's a study somewhere that actually provides light as well), etc. Basically, I'd love things that would turn into an elevator pitch of I can show you how to be X times more productive than you are using Y, and then the article provides the evidence to support that claim. Thanks, Mike ___ 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] World's First Commercial Haskell IDE and Deployment Platform, FP Haskell Center Launches Today
Confirm the issue. I have Firefox on Mac as well, and it does show for me, but says the same thing as Tommy's Safari On Sep 3, 2013, at 11:25 PM, Tommy Thorn tt1...@yahoo.com wrote: This is interesting and I wish them luck, but it seems surprising that the below link doesn't have as much as a screenshot (for an IDE, you kind of expect to see what it looks like). After much browsing around on their website I finally found the Video Demo: https://www.fpcomplete.com/business/haskell-center/video-walk-through/ but the there's no video for me on Firefox (Mac OS X). In Safari shows, but when I try to play it, it reports An error occurred, please try again later. Tommy On Sep 3, 2013, at 11:16 , Natalia Muska nata...@fpcomplete.com wrote: FP Complete Has Officially Launched the World's First Commercial Haskell IDE! http://www.i-newswire.com/fp-complete-launches-fp-haskell/237230 We greatly appreciate the support we've received from the Haskell community. Natalia Muska Marketing Manager FP Complete, Inc. nata...@fpcomplete.com 865-506-6513 skype: natalia.s.muska -- Natalia Muska Marketing Manager FP Complete, Inc. nata...@fpcomplete.com 865-506-6513 skype: natalia.s.muska Official Launch PR.docx___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] World's First Commercial Haskell IDE and Deployment Platform, FP Haskell Center Launches Today
OK, now video on http://www.i-newswire.com/fp-complete-launches-fp-haskell/237230 works. Seems like a youtube glitch On Sep 3, 2013, at 11:37 PM, MigMit miguelim...@yandex.ru wrote: Confirm the issue. I have Firefox on Mac as well, and it does show for me, but says the same thing as Tommy's Safari On Sep 3, 2013, at 11:25 PM, Tommy Thorn tt1...@yahoo.com wrote: This is interesting and I wish them luck, but it seems surprising that the below link doesn't have as much as a screenshot (for an IDE, you kind of expect to see what it looks like). After much browsing around on their website I finally found the Video Demo: https://www.fpcomplete.com/business/haskell-center/video-walk-through/ but the there's no video for me on Firefox (Mac OS X). In Safari shows, but when I try to play it, it reports An error occurred, please try again later. Tommy On Sep 3, 2013, at 11:16 , Natalia Muska nata...@fpcomplete.com wrote: FP Complete Has Officially Launched the World's First Commercial Haskell IDE! http://www.i-newswire.com/fp-complete-launches-fp-haskell/237230 We greatly appreciate the support we've received from the Haskell community. Natalia Muska Marketing Manager FP Complete, Inc. nata...@fpcomplete.com 865-506-6513 skype: natalia.s.muska -- Natalia Muska Marketing Manager FP Complete, Inc. nata...@fpcomplete.com 865-506-6513 skype: natalia.s.muska Official Launch PR.docx___ 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 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] ANN: Angel 0.4.4
On Jul 31, 2013, at 2:41 PM, Никитин Лев leon.v.niki...@pravmail.ru wrote: 31.07.2013, 05:03, Michael Xavier mich...@michaelxavier.net: angel is a daemon angel is a background process sounds better. You're killing the joke. Sorry for offtopic ___ 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] Proposal: Non-recursive let
On Jul 22, 2013, at 12:27 PM, Andreas Abel andreas.a...@ifi.lmu.de wrote: On 20.07.13 9:36 PM, Evan Laforge wrote: However, I'm also not agitating for a non-recursive let, I think that ship has sailed. Besides, if it were added people would start wondering about non-recursive where, and it would introduce an exception to haskell's pretty consistently order-independent declaration style. For functions, recursive-by-default let makes sense. But for *values*, intended recursion is rather the exception. It is useful for infinite lists and the like. For values of atomic type like Int or Bool, recursive let is a bug. It seems hard to distinguish between them. What about values that contain functions, like data T = T Int (Int - Int)? What about polymorphic values, that could be functions and could be not? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (no subject)
It really sounds rude, to demand promises from somebody who just gave you a big present. Отправлено с iPhone 10.06.2013, в 16:11, Zed Becker zed.bec...@gmail.com написал(а): Hi all, Haskell, is arguably the best example of a design-by-committee language. The syntax is clean and most importantly, consistent. The essence of a purely functional programming is maintained, without disturbing its real world capacity. To all the people who revise the Haskell standard, and implement the language, Promise to me, and the rest of the community, that you will keep up the good effort :) Promise to me, and the rest of the community, that Haskell will always spiritually remain the same clean, consistent programming language as it is now! Regards, Zed Becker ___ 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] HTML framework for web-ui
Doing HTML UI with Happstack was a pleasant experience. Отправлено с iPhone 21.05.2013, в 12:47, Vlatko Basic vlatko.ba...@gmail.com написал(а): Hi, I'd like to start using web pages as the UI for apps. I found out for yesod, snapp and happstack as the candidates. Would you recommend any of them as better for app ui (not classical web pages)? Or maybe another one? thanks, vlatko ___ 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] Non-deterministic behaviour of aeson's parser
My result: 2000 lines of Right () ghc-pkg list aeson says aeson-0.6.1.0 On May 18, 2013, at 8:25 PM, Roman Cheplyaka r...@ro-che.info wrote: I am observing a non-deterministic behaviour of aeson's parser. I'm writing here in addition to filing a bug report [1] to draw attention to this (pretty scary) problem. To try to reproduce this problem, do this: git clone https://gist.github.com/5604887.git aeson cd aeson ghc aeson.hs ./aeson | sort | uniq -c This is my result: 32 Left key \module\ not present 55 Left When parsing the record SymValue of type Main.SymValueInfo the key fixity was not present. 1913 Right () Can others reproduce this in their environments? Does anyone have ideas about where the bug may lie? Many aeson's dependencies do unsafe IO stuff that could lead to such consequences. Roman [1]: https://github.com/bos/aeson/issues/125 ___ 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] Propositions in Haskell
You can stop suspecting: in Haskell, equations ARE definitions. On May 15, 2013, at 9:15 PM, Patrick Browne patrick.bro...@dit.ie wrote: The relation to theorem proving is the main motivation for my question. In am trying to understand why some equations are ok and others not. I suspect that in Haskell equations are definitions rather than assertions. If approach 2 is a non-starter in Haskell, then can approach 1, using if-then-else, achieve the same results for propositions? Thanks Pat On 15/05/13, Dan Mead d.w.m...@gmail.com wrote: i don't understand what you're trying to do with that code, however you seem to be asking about theorem proving in general check out http://www.haskell.org/haskellwiki/Libraries_and_tools/Theorem_provers and http://en.wikipedia.org/wiki/Automated_theorem_proving hope it helps On Wed, May 15, 2013 at 11:34 AM, Patrick Browne patrick.bro...@dit.ie patrick.bro...@dit.ie wrote: -- Hi -- I am trying to show that a set of propositions and a conclusion the form a valid argument. -- I used two approaches; 1) using if-then-else, 2) using pattern matching. -- The version using if-then-else seems to be consistent with my knowledge of Haskell and logic (either of which could be wrong). -- Can the second approach be improved to better reflect the propositions and conclusion? Maybe type level reasoning could be used? -- -- Valid argument? -- 1. I work hard or I play piano -- 2. If I work hard then I will get a bonus -- 3. But I did not get a bonus -- Therefore I played piano -- Variables: p = Piano, w = worked hard, b = got a bonus --(w \/ p) /\ (w = b) /\ ¬(b) -- --- --p -- First approach using language control structure if-then-else w, p, b::Bool -- Two equivalences for (w \/ p) as an implication. -- 1. (w \/ p) =equivalent-to= (not p) = w -- 2. (w \/ p) =equivalent-to= (not w) = p -- Picked 2 p = if (not w) then True else False -- Contrapositive: (w = b) =equivalent-to= ~b = ~w w = if (not b) then False else True b = False -- gives p is true and w is false -- Second approach using pattern matching -- I think the rewriting goes from left to right but the logical inference goes in the opposite direction. w1, p1, b1::Bool p1 = (not w1) w1 = b1 -- Not consistent with statements, but I do not know how to write ~b1 = ~w1 in Haskell b1 = False -- Again gives p1 is true and w1 is false Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie ___ 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] A use case for *real* existential types
Maybe I understand the problem incorrectly, but it seems to me that you're overcomplicating things. With that kind of interface you don't actually need existential types. Or phantom types. You can just keep Inotify inside the Watch, like this: import Prelude hiding (init, map) import Data.IORef data Inotify = Inotify {nextWatchRef :: IORef Int, currentWatchesRef :: IORef [(Int,String)]} data Watch = Watch Int Inotify init ::IO Inotify init = do nextWatchRef_ - newIORef 0 currentWatchesRef_ - newIORef [] return Inotify { nextWatchRef = nextWatchRef_ , currentWatchesRef = currentWatchesRef_ } addWatch :: Inotify - String - IO Watch addWatch nd filepath = do wd - readIORef (nextWatchRef nd) writeIORef (nextWatchRef nd) (wd + 1) map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) ((wd,filepath):map) return (Watch wd nd) rmWatch :: Watch - IO () rmWatch (Watch wd nd) = do map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) (filter ((/= wd) . fst) map) printInotifyDesc :: Inotify - IO () printInotifyDesc nd = print = readIORef (currentWatchesRef nd) main :: IO () main = do nd0 - init wd0 - addWatch nd0 foo _ - addWatch nd0 bar nd1 - init wd3 - addWatch nd1 baz printInotifyDesc nd0 printInotifyDesc nd1 rmWatch wd0 rmWatch wd3 printInotifyDesc nd0 printInotifyDesc nd1 OK, I understand that it might be not what you want. For example, it could be that you can combine two different Watches if and only if they refer to the same Inotify. Well, then you need existential types. But you almost did it right, all you have to do now is to wrap Inotify in another type like that: {-# LANGUAGE ExistentialQuantification #-} import Prelude hiding (init, map) import Data.IORef data Inotify a = Inotify { nextWatchRef :: IORef Int , currentWatchesRef :: IORef [(Int,String)] } newtype Watch a = Watch Int data PolyInotify = forall a. PolyInotify (Inotify a) init :: IO PolyInotify init = do nextWatchRef_ - newIORef 0 currentWatchesRef_ - newIORef [] return $ PolyInotify Inotify { nextWatchRef = nextWatchRef_ , currentWatchesRef = currentWatchesRef_ } addWatch :: Inotify a - String - IO (Watch a) addWatch nd filepath = do wd - readIORef (nextWatchRef nd) writeIORef (nextWatchRef nd) (wd + 1) map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) ((wd,filepath):map) return (Watch wd) rmWatch :: Inotify a - Watch a - IO () rmWatch nd (Watch wd) = do map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) (filter ((/= wd) . fst) map) printInotifyDesc :: Inotify a - IO () printInotifyDesc nd = print = readIORef (currentWatchesRef nd) main :: IO () main = do pnd0 - init case pnd0 of PolyInotify nd0 - do wd0 - addWatch nd0 foo _ - addWatch nd0 bar pnd1 - init case pnd1 of PolyInotify nd1 - do wd3 - addWatch nd1 baz printInotifyDesc nd0 printInotifyDesc nd1 rmWatch nd0 wd0 rmWatch nd1 wd3 -- These lines cause type errors: -- rmWatch nd1 wd0 -- rmWatch nd0 wd3 printInotifyDesc nd0 printInotifyDesc nd1 You may also choose to employ Rank2Types, which would make this more ST-like, with init playing the part of runST: {-# LANGUAGE Rank2Types #-} import Prelude hiding (init, map) import Data.IORef data Inotify a = Inotify { nextWatchRef :: IORef Int , currentWatchesRef :: IORef [(Int,String)] } newtype Watch a = Watch Int init :: (forall a. Inotify a - IO b) - IO b init action = do nextWatchRef_ - newIORef 0 currentWatchesRef_ - newIORef [] action Inotify { nextWatchRef = nextWatchRef_ , currentWatchesRef = currentWatchesRef_ } addWatch :: Inotify a - String - IO (Watch a) addWatch nd filepath = do wd - readIORef (nextWatchRef nd) writeIORef (nextWatchRef nd) (wd + 1) map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) ((wd,filepath):map) return (Watch wd) rmWatch :: Inotify a - Watch a - IO () rmWatch nd (Watch wd) = do map - readIORef (currentWatchesRef nd) writeIORef (currentWatchesRef nd) (filter ((/= wd) . fst) map) printInotifyDesc :: Inotify a - IO () printInotifyDesc nd = print = readIORef (currentWatchesRef nd) main :: IO () main = init $ \nd0 - do wd0 - addWatch nd0 foo _ - addWatch nd0 bar init $ \nd1 - do wd3 - addWatch nd1 baz printInotifyDesc nd0 printInotifyDesc nd1 rmWatch nd0 wd0 rmWatch nd1 wd3 -- These lines cause type errors: -- rmWatch nd1 wd0 -- rmWatch nd0 wd3 printInotifyDesc nd0 printInotifyDesc nd1 On May 10, 2013, at 2:17 PM, Leon
Re: [Haskell-cafe] GSoC Project Proposal: Markdown support for Haddock
Отправлено с iPad 08.04.2013, в 21:44, Evan Laforge qdun...@gmail.com написал(а): Can't we just add some features to haddock? No, we can't. At the very least we should FIX haddock before adding features. There are a lot of ways to improve haddock a lot, and no one is doing them, so my impression is that haddock doesn't really have active maintainers. Adding a whole new backend seems risky, unless it results in new maintainers joining. For my personal bikeshed contribution, I would like to see haddock move in the way of fewer markup characters and rules, not more. Since haddock is not statically checked, the only way to find out if I put in an error is to run haddock and then visually inspect the output, unless of course it was a syntax error, in which case the error message is often not very good. I can easily haddock individual files since I have a custom build system, but I imagine cabal users would have to haddock the entire project every time. I regularly see haddock errors in released packages so I'm not the only one. There are lots of ways to improve haddock a lot. For example, better parse error messages. Make s smarter so they don't try to link things that are obviously not modules. Or complain if it's not a module. Or better, get rid of them entirely and use single quotes for that. And make single quotes work for non-imported symbols. Incremental support for cabal. Perhaps even deprecate @ and use ' for that too. One thing I think HTML got right is that there are only two characters that need to be quoted. Of course that's at the cost of all the markup being wordy, but the more you move in the markup-style DWIM the more little rules you have to remember. On Thu, Apr 4, 2013 at 6:00 PM, Johan Tibell johan.tib...@gmail.com wrote: Would it be too much to ask that a notation be used which has a formal syntax and a formal semantics? We will document our superset, sure. That's what others did as well. The point is using Markdown as the shared base. ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Compiled code
Suppose I compiled some module and kept it's .hi and .o files. Is it possible to use this module in my program if the source code was deleted for some reason? Seems like the answer is yes — by creating a fake .hs file (with no real content) and touch-in .hi and .o files I tricked ghc so that it didn't attempt to recompile the module, so the information in .hi and .o files is sufficient. But ghc insists on having the .hs file around, and I didn't find a way to turn it off. Is there any? Or there is a specific reason not to allow this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Compiled code
Sorry, I think that's not the right list for this question. Отправлено с iPhone 23.03.2013, в 2:04, MigMit miguelim...@yandex.ru написал(а): Suppose I compiled some module and kept it's .hi and .o files. Is it possible to use this module in my program if the source code was deleted for some reason? Seems like the answer is yes — by creating a fake .hs file (with no real content) and touch-in .hi and .o files I tricked ghc so that it didn't attempt to recompile the module, so the information in .hi and .o files is sufficient. But ghc insists on having the .hs file around, and I didn't find a way to turn it off. Is there any? Or there is a specific reason not to allow 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] Overloading
On Mar 13, 2013, at 12:54 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: The interesting challenge here is that we should have Date + Period - Date Date - Period - Date Period + Date - Date Period - Date - ILLEGAL Period + Period - DeriodPeriod - Period - Period Date + Date - ILLEGAL Date - Date - Date and _also_ (remember we are trying to beat C++ here) Int +/- Int - Int. Well, an obvious suggestion would be to use MultiParamTypeClasses and TypeFamilies: {- LANGUAGE MultiParamTypeClasses, TypeFamilies -} module Date where import Prelude hiding (Num, (+)) data Date = Date data Period = Period class Plus a b where type PlusResult a b (+) :: a - b - PlusResult a b instance Plus Date Period where type PlusResult Date Period = Date Date + Period = Date instance Plus Period Date where type PlusResult Period Date = Date Period + Date = Date instance Plus Period Period where type PlusResult Period Period = Period Period + Period = Period But I suppose you've been thinking about Haskell98. That, I'm afraid, doesn't seem possible. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Overloading
On Mar 12, 2013, at 12:44 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: Prelude :type (+) (+) :: Num a = a - a - a The predefined (+) in Haskell requires its arguments and its result to be precisely the same type. I think you had better justify the claim that Date+Period - Date and Date+Period - Period are possible at the same time by showing us actual code. Ehm... import Prelude hiding (Num) class SumDP a where (+) :: Date - Period - a instance SumDP Date where date + period = your_implementation_here instance SumDP Period where date + period = and_here ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Overloading
On Mar 10, 2013, at 11:47 AM, Peter Caspers pcaspers1...@gmail.com wrote: Thank you all for your answers, this helps a lot. To clarify my last point ... Also again, taking this way I can not provide several constructors taking inputs of different types, can I ? Sorry, didn't get what you mean here. In C++ it is perfectly normal to have overloaded functions like f : Int - Int - Int f : Int - Char - Int in coexistence, because the compiler can infer (at compile time) what function to call by looking at the arguments types. In Haskell I think this is not possible simply due to the flexibility given by partial function application, i.e. f 5 would not be well defined any more, it could be Int - Int or Char - Int. Well, that's what typeclasses are for. class F a where f :: Int - a - Int instance F Int where f = ... instance F Char where f = ... ghci :t f 5 ghci f 5 :: (F a) = a - Int ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Overloading
On Mar 10, 2013, at 12:33 AM, Peter Caspers pcaspers1...@gmail.com wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators. For example I want to write (Date 6 6 1973) + (Period 2 Months) for some self defined types Date and Period. Another example would be (Period 1 Years) + (Period 3 Months). Just defining the operator (+) does not work because it collides with Prelude.+. I assume using fully qualified names would work, but that is not what I want. So maybe make the types instances of typeclasses? This would be Num for (+) I guess. For the first example above it will not work however, alone for it is not of type a - a - a. Also the second example does not fit, because I would have to make Period an instance of Num, which does not make sense, because I can not multiply Periods (for example). If you really want that, you can stop ghc from importing Prelude. I haven't tested it yet, but I think import Prelude hiding (Num) should work. Of course, in this case you would lose all predefined instances of Num, including the ability to add integers, but you can get them back through another module. But I would strongly suggest that you define another operator instead. Unlike C++, Haskell allows you to define as many operators as you like. Am I missing something or is that what I am trying here just impossible by the language design (and then probably for a good reason) ? A second question concerns the constructors in own datatypes like Date above. Is it possible to restrict the construction of objects to sensible inputs, i.e. reject something like Date 50 23 2013 ? My workaround would be to provide a function say date :: Int-Int-Int-Date checking the input and returning a Date object or throw an error if the input does not correspond to a real date. I could then hide the Date constructor itself (by not exporting it). However this seems not really elegant. Well, it's the way it is usually done. This is called a smart constructor pattern. Also again, taking this way I can not provide several constructors taking inputs of different types, can I ? Sorry, didn't get what you mean here. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to input Unicode string in Haskell program?
Have you tried running ghci inside Emacs? Отправлено с iPhone 21.02.2013, в 13:58, Semyon Kholodnov joker...@gmail.com написал(а): Imagine we have this simple program: module Main(main) where main = do x - getLine putStrLn x Now I want to run it somehow, enter résumé 履歴書 резюме and see this string printed back as résumé 履歴書 резюме. Now, the first problem is that my computer runs Windows, which means that I can't use ghci :main or result of ghc main.hs to enter such an outrageous string — Windows console is locked to one specific local code page, and no codepage contains Latin-1, Cyrillic and Kanji symbols at the same time. But there is also WinGHCi. So I do :main, copy-paste this string into the window (It works! Because Windows has Unicode for 20 years now), but the output is all messed up. In a rather curious way, actually: the input string is converted to UTF-8 byte string, and its bytes are treated as being characters from my local code page. So, it appears that I have no way to enter Unicode strings into my Haskell programs by hands, I should read them from files. That's sad, and I refuse to think I am the first one with such a problem, so I assume there is a solution/workaround. Now would someone please tell me this solution? Except from Just stick to 127 letters of ASCII, of course. ___ 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] performance question
Well, this runtime errors are actually type errors. Regexps are actually a DSL, which is not embedded in Haskell. But it could be. Strings won't work for that, but something like that would: filter (match $ a many anyChar .txt) filenames and this certainly can be produced by TH like that: filter (match $(regexp a.*\\.txt)) filenames On Feb 13, 2013, at 8:43 PM, Nicolas Trangez nico...@incubaid.com wrote: On Wed, 2013-02-13 at 08:39 -0800, David Thomas wrote: One way in which regexps are foreign to Haskell-think is that, if they break, they generally break at run-time. This could be ameliorated with template haskell Care to elaborate on the ameliorate using TH part? I figure regexes would be mostly used to parse some runtime-provided string, so how could compile-TH provide any help? Nicolas ___ 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] Object Oriented programming for Functional Programmers
On Jan 2, 2013, at 2:26 AM, Bob Hutchison hutch-li...@recursive.ca wrote: On 2013-01-01, at 3:47 PM, MigMit miguelim...@yandex.ru wrote: Well, probably one of the reasons is that I've learned Eiffel later than Haskell. But really, Design by Contract — a theory? It certainly is a useful approach, but it doesn't seem to be a theory, not until we can actually prove something about it, and Eiffel doesn't seem to offer anything in this direction. Don't confuse OOSC2 and Eiffel. Eiffel implements the ideas in OOSC2 as best as Meyer can, but they are not the same thing. Well, we were talking about Eiffel. OOSC2 deserves a few unkind words as well, but I won't go there. And, personally, I think I would be willing to call DbC a theory, or a close precursor to a theory. I don't know about DbC in general, but it's implementation in Eiffel seems to be nothing more than a few ASSERT macros, for some weird reason embedded into the language. So, I think, you're saying take away the contracts and the outcome of compilation won't be any different. Whereas take away the types and Haskell is stopped cold. And that difference makes contracts a 'hack' but types not a 'hack'? I wasn't clear enough, sorry. I'm sure it's due to sleep deprivation. Or coffee deprivation. See, there are two parts of Eiffel, as I see it. First one is the contracts part. Second is… well, everything else. Second part seems to be doing all the real job, while the first one is doing something invisible, something that leaves no trace in the final result. Which doesn't mean it's unimportant, of course. The contracts part is designed to help the other part do it's job, but not to do the job by itself. Now, there are two problems with that: 1) The real job part needs helping. And a lot of it, actually, one doesn't need to look very closely to see that Eiffel type system is extremely unsafe (for the statically type language). 2) The contracts part does a very poor job. Instead of really improving the inherent unsafety, it resorts to testing. And... 2') ...not even the real, thorough testing — contracts system would be quite happy if the program works on the developer's machine. Which is the works for me approach certain languages gets rightfully blamed for. Seems to me you're ignoring everything that happens between an empty directory and a working program. Contracts help in that process (I say but can't prove). I agree. They do help — but there are lots of things that help in this transition. Versioning systems. Collaboration tools. Bug tracking software. Text editors. Even debuggers. Pre and post conditions with class invariants are neither types nor unit test, something in between. With the wonderful properties of 'useful' and 'executable'. Sometimes you just have to settle for the hacks. Cheers, Bob On Jan 1, 2013, at 11:41 PM, Mike Meyer m...@mired.org wrote: MigMit miguelim...@yandex.ru wrote: On Jan 1, 2013, at 10:23 PM, Никитин Лев leon.v.niki...@pravmail.ru wrote: Eiffel, for my opinion, is a best OOP language. Meyer use a theoretical approach as it is possible in OOP. Really? Because when I studied it I had a very different impression: that behind this language there was no theory at all. And it's only feature I remember that is not present in mainstream languages is it's pre/postconditions system, which looked like an ugly hack for me. I agree with Leon. Of course, I learned it out of OOSC2, which provides the theory. When compared to mainstream OO languages like C++, Java or Python, it's on a much solider theoretical basis. Compared to something like Scheme, Haskell or even Clojure, maybe not so much. On the other hand, one persons theory is another persons hack. The theory behind the pre/post conditions is Design by Contract. The contracts are as important as the type signature, and show up in the auto-generated docs in eiffel systems. I found at least one attempt to add DbC features to Haskell. I'm not sold on it as a programming technique - the bugs it uncovers are as likely to be in the pre/post conditions as in the code. -- Sent from my Android tablet with K-9 Mail. Please excuse my swyping. ___ 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] Object Oriented programming for Functional Programmers
On Jan 2, 2013, at 8:44 AM, Никитин Лев leon.v.niki...@pravmail.ru wrote: I said theoratical, but not mathematical or a scientific theory. Than what kind of theory did you mean? image1.gif Meyer have built a quite coherent construction in comparison with other OOP langs. More than Smalltalk, for example? BTW, when I started study haskell i had similar question: is it possible to add DbC to haskell? Does haskell need DbC? For example, class invariants may be expressed in DbC construction (fmap id = id for Functior, for example). 02.01.2013, 02:41, Mike Meyer m...@mired.org: MigMit miguelim...@yandex.ru wrote: On Jan 1, 2013, at 10:23 PM, Никитин Лев leon.v.niki...@pravmail.ru wrote: Eiffel, for my opinion, is a best OOP language. Meyer use a theoretical approach as it is possible in OOP. Really? Because when I studied it I had a very different impression: that behind this language there was no theory at all. And it's only feature I remember that is not present in mainstream languages is it's pre/postconditions system, which looked like an ugly hack for me. I agree with Leon. Of course, I learned it out of OOSC2, which provides the theory. When compared to mainstream OO languages like C++, Java or Python, it's on a much solider theoretical basis. Compared to something like Scheme, Haskell or even Clojure, maybe not so much. On the other hand, one persons theory is another persons hack. The theory behind the pre/post conditions is Design by Contract. The contracts are as important as the type signature, and show up in the auto-generated docs in eiffel systems. I found at least one attempt to add DbC features to Haskell. I'm not sold on it as a programming technique - the bugs it uncovers are as likely to be in the pre/post conditions as in the code. -- Sent from my Android tablet with K-9 Mail. Please excuse my swyping. ___ 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] Object Oriented programming for Functional Programmers
On Jan 2, 2013, at 10:52 AM, Mike Meyer m...@mired.org wrote: [Context destroyed by top posting.] MigMit miguelim...@yandex.ru wrote: But really, Design by Contract — a theory? It certainly is a useful approach, but it doesn't seem to be a theory, not until we can actually prove something about it, and Eiffel doesn't seem to offer anything in this direction. You just stated (briefly, and not very rigorously) the theory: DbC is a useful approach to programing. Note that it's a theory about *programming*, not the resulting program. Well, you can call that a theory, for sure. But I think it's usually called an observation. I always thought the theory is something that allows us to develop some new knowledge. Just stating that comfortable chairs make programmers more productive doesn't constitute a theory. Type classes are the wrong feature to look at. Type signatures are closer to what DbC is. Are type signatures a hack to get around deficiencies in the type inferencing engine? After all, you can strip all of them away and have essentially the same program. I've tried to clarify my position in my response to Bob Hutchison. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Object Oriented programming for Functional Programmers
On Jan 2, 2013, at 4:24 PM, Никитин Лев leon.v.niki...@pravmail.ru wrote: Well, we can say concepts in place of theory. And I'm comparing Eiffel with other OOP lang, not with some langs based on a solid math theory (lambda calcules for FP langs, for example). ok? I agree that there are certain concepts, or ideas, that Eiffel is built on. If that is what you meant, sure, I have no problem with that. Of course, there are plenty of languages based on some specific ideas. For example, take the following concepts: 1) it's better to do something instead of failing, even if it doesn't make any sense; 2) global is better then local; 3) for every feature that can be implemented in two ways there should be a switch that the user can set as xe wishes. Implement these as fully as possible — and you'll get PHP. So, somehow I doubt that being based on some set of ideas is a very strong selling point. BTW. Why you think that Eiffel type system is unsafe? Well, if I remember correctly, if you call some method of a certain object, and this call compiles, you can't be certain that this object actually has this method. Could be that this object belongs to some subclass which removes this method. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Object Oriented programming for Functional Programmers
2) prepost conditions and class invariants have defined behaviour in cases of inheritance, even/especially multiple inheritance. They are combined non-trivially in subclasses. Without this I don't think you have DbC. Yes, I forgot about that. Thanks. Feel free to enlighten me about these obvious and extremely unsafe aspects of Eiffel's type system. Personally, I can't say I ever noticed. Correct me if I'm wrong, but isn't it true that methods can be removed in subclasses? If that's not extreme, I don't know what is. 2) The contracts part does a very poor job. Instead of really improving the inherent unsafety, it resorts to testing. And… What constitutes a 'good' job? Well, a sound type system would certainly help. 'Resorts' to testing. I have to admit to resorting to testing on occasion myself. Frequent occasion. Routinely even. :-) You routinely try to overcome language weakness with tests? 2') ...not even the real, thorough testing — contracts system would be quite happy if the program works on the developer's machine. Which is the works for me approach certain languages gets rightfully blamed for. Really? You believe that automated testing and contracts are why software bugs *are not* found? Is that what I said? I believe that testing means a lot more than just making sure the program works on the developer's computer. I believe that system that encourages the works for me approach is one of the reasons software bugs are not found. Seems to me you're ignoring everything that happens between an empty directory and a working program. Contracts help in that process (I say but can't prove). I agree. They do help — but there are lots of things that help in this transition. Versioning systems. Collaboration tools. Bug tracking software. Text editors. Even debuggers. You should read OOSC2. You'll find that this is completely consistent with it. I've never said it's not. But all of these tools are external to the language, which means that they can be easily replaced if a better alternative surfaces. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Object Oriented programming for Functional Programmers
On Jan 3, 2013, at 2:09 AM, Gershom Bazerman gersh...@gmail.com wrote: On 1/2/13 4:29 PM, MigMit wrote: BTW. Why you think that Eiffel type system is unsafe? Well, if I remember correctly, if you call some method of a certain object, and this call compiles, you can't be certain that this object actually has this method. Could be that this object belongs to some subclass which removes this method. Eiffel doesn't handle the relationship of co- and contra-variance of arguments with subtyping in a principled way. This is apparently known as the catcall problem. See, e.g., this article: http://www.eiffelroom.org/node/517 Yes, variance is another big source of unsafety, that's for sure. And another reason I think there is no real theory behind Eiffel, just a bunch of features (or concepts) boiled together. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Object Oriented programming for Functional Programmers
Well, probably one of the reasons is that I've learned Eiffel later than Haskell. But really, Design by Contract — a theory? It certainly is a useful approach, but it doesn't seem to be a theory, not until we can actually prove something about it, and Eiffel doesn't seem to offer anything in this direction. And by hack I meant not the presence of pre/postconditions, but the fact that they don't affect anything else. Strip all of them away, and you'll have the program which is, essentially, the same (and, in fact, pre/postconditions are supposed to be removed in the final version of the program). Compare this to Haskell types, for example: an untyped version of Haskell won't be able to choose between two class instances, so, that would be an entirely different language. On Jan 1, 2013, at 11:41 PM, Mike Meyer m...@mired.org wrote: MigMit miguelim...@yandex.ru wrote: On Jan 1, 2013, at 10:23 PM, Никитин Лев leon.v.niki...@pravmail.ru wrote: Eiffel, for my opinion, is a best OOP language. Meyer use a theoretical approach as it is possible in OOP. Really? Because when I studied it I had a very different impression: that behind this language there was no theory at all. And it's only feature I remember that is not present in mainstream languages is it's pre/postconditions system, which looked like an ugly hack for me. I agree with Leon. Of course, I learned it out of OOSC2, which provides the theory. When compared to mainstream OO languages like C++, Java or Python, it's on a much solider theoretical basis. Compared to something like Scheme, Haskell or even Clojure, maybe not so much. On the other hand, one persons theory is another persons hack. The theory behind the pre/post conditions is Design by Contract. The contracts are as important as the type signature, and show up in the auto-generated docs in eiffel systems. I found at least one attempt to add DbC features to Haskell. I'm not sold on it as a programming technique - the bugs it uncovers are as likely to be in the pre/post conditions as in the code. -- Sent from my Android tablet with K-9 Mail. Please excuse my swyping. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Object Oriented programming for Functional Programmers
Well, functional programmer is a relatively broad term. If you're coming from academia, so that for you Haskell is some sort of lambda-calculus, spoiled by practical aspects, then I'd suggest Luca Cardelli's book Theory of Objects. Also, as Daniel told you already, don't start from C++, it really has very little to do with OOP. It's primary merit is a very powerful system of macros (called templates in C++ world), not objects. If you want something mainstream, Java would be a good choice, and C# even better one (although it would be more convenient for you if you use Windows). Or you can try OCaml, which is functional enough for you not to feel lost, and object-oriented as well. Отправлено с iPad 30.12.2012, в 23:58, Daniel Díaz Casanueva dhelta.d...@gmail.com написал(а): Hello, Haskell Cafe folks. My programming life (which has started about 3-4 years ago) has always been in the functional paradigm. Eventually, I had to program in Pascal and Prolog for my University (where I learned Haskell). I also did some PHP, SQL and HTML while building some web sites, languages that I taught to myself. I have never had any contact with JavaScript though. But all these languages were in my life as secondary languages, being Haskell my predominant preference. Haskell was the first programming language I learned, and subsequent languages never seemed so natural and worthwhile to me. In fact, every time I had to use another language, I created a combinator library in Haskell to write it (this was the reason that brought me to start with the HaTeX library). Of course, this practice wasn't always the best approach. But, why I am writing this to you, haskellers? Well, my curiosity is bringing me to learn a new general purpose programming language. Haskellers are frequently comparing Object-Oriented languages with Haskell itself, but I have never programmed in any OO-language! (perhaps this is an uncommon case) I thought it could be good to me (as a programmer) to learn C/C++. Many interesting courses (most of them) use these languages and I feel like limited for being a Haskell programmer. It looks like I have to learn imperative programming (with side effects all over around) in some point of my programming life. So my questions for you all are: * Is it really worthwhile for me to learn OO-programming? * If so, where should I start? There are plenty of functional programming for OO programmers but I have never seen OO programming for functional programmers. * Is it true that learning other programming languages leads to a better use of your favorite programming language? * Will I learn new programming strategies that I can use back in the Haskell world? Thanks in advance for your kind responses, Daniel Díaz. ___ 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] Object Oriented programming for Functional Programmers
Sorry for the stupid mistake — when I said Daniel in the previous message, I've meant Jay. Отправлено с iPad 30.12.2012, в 23:58, Daniel Díaz Casanueva dhelta.d...@gmail.com написал(а): Hello, Haskell Cafe folks. My programming life (which has started about 3-4 years ago) has always been in the functional paradigm. Eventually, I had to program in Pascal and Prolog for my University (where I learned Haskell). I also did some PHP, SQL and HTML while building some web sites, languages that I taught to myself. I have never had any contact with JavaScript though. But all these languages were in my life as secondary languages, being Haskell my predominant preference. Haskell was the first programming language I learned, and subsequent languages never seemed so natural and worthwhile to me. In fact, every time I had to use another language, I created a combinator library in Haskell to write it (this was the reason that brought me to start with the HaTeX library). Of course, this practice wasn't always the best approach. But, why I am writing this to you, haskellers? Well, my curiosity is bringing me to learn a new general purpose programming language. Haskellers are frequently comparing Object-Oriented languages with Haskell itself, but I have never programmed in any OO-language! (perhaps this is an uncommon case) I thought it could be good to me (as a programmer) to learn C/C++. Many interesting courses (most of them) use these languages and I feel like limited for being a Haskell programmer. It looks like I have to learn imperative programming (with side effects all over around) in some point of my programming life. So my questions for you all are: * Is it really worthwhile for me to learn OO-programming? * If so, where should I start? There are plenty of functional programming for OO programmers but I have never seen OO programming for functional programmers. * Is it true that learning other programming languages leads to a better use of your favorite programming language? * Will I learn new programming strategies that I can use back in the Haskell world? Thanks in advance for your kind responses, Daniel Díaz. ___ 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] lambda case (was Re: A big hurray for lambda-case (and all the other good stuff))
Syntax extensibility is usually too powerful, it surely would be abused extensively, which would make developer's life a nightmare, unless there is only one developer and whole development takes no more than a couple of months. On Dec 31, 2012, at 1:09 AM, Dan Burton danburton.em...@gmail.com wrote: My 2 cents on the issue: We should have a better forms of meta-programming to solve this sort of issue generally. With the power of first-class functions and laziness, we can get away with a lot of things without meta-programming, but case expression syntax is not first class, so cannot benefit from the flexibility proffered to the rest of the language. tl;dr give me easily extensible syntax, rather than having to run to GHC devs every time I want a new or different flavor of sugar. -- Dan Burton ___ 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] Can not use ST monad with polymorphic function
Yes, monomorphism. do binding requires your fold'' to be of some monomorphic type, but runST requires some polymorphism. If you want, you can use special type like that: data FoldSTVoid = FoldSTVoid {runFold :: forall a. (Int - ST a ()) - ST a ()} fold :: Monad m = (Int - m ()) - m () fold f = mapM_ f [0..20] selectFold :: String - IO FoldSTVoid -- ((Int - m ()) - m ()) selectFold method = do -- in real program I'd like to choose between -- different fold methods, based on some IO context return $ FoldSTVoid fold useFold :: FoldSTVoid - ST a () useFold fold' = runFold fold' f where f _ = return () -- some trivial iterator main = do fold'' - selectFold some-method-id print $ runST $ useFold fold'' On Nov 28, 2012, at 9:52 PM, Dmitry Kulagin dmitry.kula...@gmail.com wrote: Hi Cafe, I try to implement some sort of monadic fold, where traversing is polymorphic over monad type. The problem is that the code below does not compile. It works with any monad except for ST. I suspect that monomorphism is at work here, but it is unclear for me how to change the code to make it work with ST. fold :: Monad m = (Int - m ()) - m () fold f = mapM_ f [0..20] selectFold :: Monad m = String - IO ((Int - m ()) - m ()) selectFold method = do -- in real program I'd like to choose between -- different fold methods, based on some IO context return fold useFold :: Monad m = ((Int - m ()) - m ()) - m () useFold fold' = fold' f where f _ = return () -- some trivial iterator main = do fold'' - selectFold some-method-id print $ runST $ useFold fold'' Thank you! Dmitry ___ 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] Common function names for '(.) . (.)', '(.) . (.) . (.)' ...?
Tits? On Nov 21, 2012, at 9:43 PM, Daniel Trstenjak daniel.trsten...@gmail.com wrote: Greetings, Daniel ___ 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] need help with understanding expression
Отправлено с iPhone 17.11.2012, в 11:19, damodar kulkarni kdamodar2...@gmail.com написал(а): In the second case, why the GHC doesn't give something like? ([Char] (a - t), Num a) = t Because Num is a class of types, while String is a type. In other words, in the expression 3 a ghc doesn't know, what type 3 belongs to, it just knows that it should be of class Num. In particular, it could be of type String - t for some t, ghc wouldn't go over all possible types to see that there is no such instance of Num. On the other hand, in a 3 it knows exactly what type a is, strings are always of one type, String (which is an alias for [Char]). You can enable OverloadedStrings extension, which makes string literals polymorphic; then you'll have your type, which would be something like (IsString (a - b), Num a) = b. Now let's consider the evaluation scenario: Prelude 3 2 interactive:1:0: No instance for (Num (t - t1)) arising from the literal `3' at interactive:1:0-2 Possible fix: add an instance declaration for (Num (t - t1)) In the expression: 3 2 In the definition of `it': it = 3 2 Note, how the GHC suggests us this strange constraint as a possible fix BUT see this: Prelude a 2 interactive:1:0: Couldn't match expected type `t1 - t' against inferred type `[Char]' In the expression: a 2 In the definition of `it': it = a 2 In this case the GHC doesn't even allow us to add any possible fix. Same thing. String is NOT a functional type, and it would never be, while it's possible (and sometimes reasonable) to have a functional type of class Num. Enable OverloadedStrings, and you'll see your desired possible fix.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] local type denotation
{-# LANGUAGE ScopedTypeVariables #-} Отправлено с iPhone 14.11.2012, в 16:03, Serge D. Mechveliani mech...@botik.ru написал(а): Please, how to correctly set an explicit type for a local value in the body of a polymorphic function? Example (tested under ghc-7.6.1): data D a = D1 a | D2 a (a - a) f :: Eq a = D a - a f (D1 x) = x f (D2 x g) = let -- y :: Eq a = a y = g x in if x == y then x else g y main = putStr $ shows (f (D2 (1 :: Int) succ)) \n This is compiled byghc --make Main Now I need, for a certain reason, to explicitly set the type for y in `let', with the meaning: this very `a' which is in the signature for f (and I think that this type Haskell assignes to y in y = g x). I need to declare this type in a separate line: y :: what ever it is. Both `y :: a' and `y :: Eq a = a' are not compiled. Please, copy the answer to mech...@botik.ru Thanks, -- Sergei ___ 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] serialize an unknown type
Seems like nobody really understands what is it that you want to accomplish or what your problem is. Отправлено с iPhone 21.10.2012, в 20:39, Corentin Dupont corentin.dup...@gmail.com написал(а): Nobody on this one? Here is a simplified version: data Event a where InputChoice :: a - Event a How to serialize/deserialize this? Cheers, Corentin On Sat, Oct 20, 2012 at 10:49 PM, Corentin Dupont corentin.dup...@gmail.com wrote: Hi the list! I have a simple question, how can I serialize/deserialize a structure like this: data InputChoice c deriving Typeable data Event a where InputChoice :: (Eq c, Show c) = [c] - c - Event (InputChoice c) (...) I'd like that the values of type c get serialized to a String... That's the easy part, but for deserializing, oops! Cheers, Corentin ___ 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] serialize an unknown type
Oh, now I've got it. First of all, functions of type IO () - Event a are impossible (unless you resort to tricks with unsafePerformIO, which is not what you want to deal with right now). You've probably meant something like IO (Event a) (at least, that is the type of function which would read Event a from file or input stream or something else external). Secondly, functions (and values) with parametric types, like IO (Event a) require you to provide the type a in your code. They won't take it from somewhere magically. You can take a look at the read function in Prelude for example. If you really want to store the type information and read it back, you should do it yourself, inventing some representation for your type, writing it to disk, reading back and parsing it. And you can't do that for all types in existence, so you'll need to do that for some specific types (and no, instances of Typeable aren't what you want). And you'll have to deal with type system, which won't allow you to just say hey, let that be whatever type it happens to be, I don't care; you'd have to wrap this into one existentially quantified type (or GADT). Keep in mind that this is not very Haskell-y. First of all, try to analyse, what this a in Event a could be. What are the limits here? And don't say there aren't any, because if you don't know anything about the type, you can't do anything with it. So, maybe you would end up with a finite set of types — this would simplify matters a lot. Or maybe you'd find out that there are inifinitely many types of events — but they can be somehow generated with a finite number of constructors — that would be quite simple as well. So, what is the bigger picture here? On Oct 21, 2012, at 9:20 PM, Corentin Dupont corentin.dup...@gmail.com wrote: Hi, Sorry if it was not enough explicit. I want to write functions like this: serialize :: (Show a) = Event a - IO () deserialize :: (Read a) = IO () - Event a The functions would write and read the data in a file, storing/retrieving also the type a I suppose... BR, C On Sun, Oct 21, 2012 at 7:03 PM, MigMit miguelim...@yandex.ru wrote: Seems like nobody really understands what is it that you want to accomplish or what your problem is. Отправлено с iPhone 21.10.2012, в 20:39, Corentin Dupont corentin.dup...@gmail.com написал(а): Nobody on this one? Here is a simplified version: data Event a where InputChoice :: a - Event a How to serialize/deserialize this? Cheers, Corentin On Sat, Oct 20, 2012 at 10:49 PM, Corentin Dupont corentin.dup...@gmail.com wrote: Hi the list! I have a simple question, how can I serialize/deserialize a structure like this: data InputChoice c deriving Typeable data Event a where InputChoice :: (Eq c, Show c) = [c] - c - Event (InputChoice c) (...) I'd like that the values of type c get serialized to a String... That's the easy part, but for deserializing, oops! Cheers, Corentin ___ 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] A yet another question about subtyping and heterogeneous collections
Why do you need ALike x, BLike x etc.? Why not just Like u x? Отправлено с iPhone Oct 18, 2012, в 14:36, Dmitry Vyal akam...@gmail.com написал(а): Hello list! I've been experimenting with emulating subtyping and heterogeneous collections in Haskell. I need this to parse a binary representation of objects of a class hierarchy in C++ program. So far I implemented upcasting using a chain of type classes and now I'm playing with heterogeneous lists. For future purposes It would be ideal to be able to have something like these functions: upcast_list :: [LikeC] - [LikeA] downcast_list :: [LikeA] - [LikeC] First one only replaces the existential wrapper leaving the actual value intact, and the second one also filters the list, passing the elements with specific enough type. I can implement this particular functions, but what's about a more general one? Something like cast_list :: [a] - [b], where a and b are existential types from one hierarchy. Something like LikeA and LikeC in my example. Is my approach feasible? Is there a better one? Am I missing something obvious? Any relevant advices are welcome. The example code follows: {-# LANGUAGE FlexibleInstances, UndecidableInstances, OverlappingInstances, ExistentialQuantification, DeriveDataTypeable #-} import Data.Typeable import Data.Maybe data A = A {a_x :: Int} deriving (Show, Typeable) data B = B {b_x :: Int, b_a :: A} deriving (Show, Typeable) data C = C {c_z :: Int, c_b :: B} deriving (Show, Typeable) data D = D {d_w :: Int, d_c :: C, d_a :: A} deriving (Show, Typeable) class ALike x where toA :: x - A class BLike x where toB :: x - B class CLike x where toC :: x - C class DLike x where toD :: x - D instance ALike A where toA = id instance BLike B where toB = id instance CLike C where toC = id instance DLike D where toD = id instance ALike B where toA = b_a instance BLike C where toB = c_b instance CLike D where toC = d_c instance (BLike x) = (ALike x) where toA = (toA :: B - A) . toB instance CLike x = BLike x where toB = toB . toC a1 = A 1 b1 = B 2 (A 2) c1 = C 3 b1 d1 = D 4 c1 (A 10) print_a :: ALike x = x - String print_a v = A = ++ show (a_x $ toA v) sum_a :: (ALike x, ALike y) = x - y - String sum_a v1 v2 = A1 = ++ show (a_x $ toA v1) ++ A2 = ++ show (a_x $ toA v2) data LikeA = forall a. (ALike a, Typeable a) = LikeA a instance ALike LikeA where toA (LikeA x) = toA x get_mono :: Typeable b = [LikeA] - [b] get_mono = catMaybes . map ((\(LikeA x) - cast x)) data LikeC = forall c. (CLike c, Typeable c) = LikeC c instance CLike LikeC where toC (LikeC x) = toC x lst_a = [LikeA a1, LikeA b1, LikeA c1, LikeA d1] lst_c = [LikeC c1, LikeC d1] ___ 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] Safe Haskell and instance coherence
On Oct 11, 2012, at 5:30 PM, Mikhail Glushenkov the.dead.shall.r...@gmail.com wrote: Hello Simon, On Thu, Oct 11, 2012 at 11:24 AM, Simon Marlow marlo...@gmail.com wrote: On 08/10/2012 20:11, Mikhail Glushenkov wrote: I couldn't find anything on the interplay between orphan instances and Safe Haskell both in the Haskell'12 paper and online. Is this something that the authors of Safe Haskell are aware of/are intending to fix? [...] I don't know what we should do about this. Disallowing orphan instances seems a bit heavy-handed. David, Simon, any thoughts? What about detecting duplicate instances at link time? We could put information about all instances defined in a given module into the .comment section of the corresponding .o file and then have a pre-link step script extract this information from all .o files in the program and check that there are no duplicate or conflicting instances. You have a bigger problem coming. Some extensions make multiple instances OK, even in Safe Haskell. For example: {-# LANGUAGE FlexibleInstances, IncoherentInstances, Safe #-} module Over where data Nil = Nil newtype Cons a = Cons a class Number n where value :: n - Integer instance Number Nil where value Nil = 0 instance Number a = Number (Cons a) where value (Cons n) = value n + 1 instance Number (Cons (Cons Nil)) where value (Cons (Cons Nil)) = 2012 naturals = nats Nil where nats :: Number n = n - [Integer] nats n = value n : nats (Cons n) Here we have two different instances Number (Con (Cons Nil)) at play, because it gives you: *Over value (Cons (Cons Nil)) 2012 *Over take 5 naturals [0,1,2,3,4] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Safe Haskell and instance coherence
On Oct 11, 2012, at 6:23 PM, Mikhail Glushenkov the.dead.shall.r...@gmail.com wrote: Hello, On Thu, Oct 11, 2012 at 3:54 PM, MigMit miguelim...@yandex.ru wrote: You have a bigger problem coming. Some extensions make multiple instances OK, even in Safe Haskell. For example: {-# LANGUAGE FlexibleInstances, IncoherentInstances, Safe #-} [...] Safe Haskell already disallows OverlappingInstances. It doesn't. Overlapping instances are allowed in safe modules, provided that they won't be used in other modules. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Safe Haskell and instance coherence
I hate to admit it, but it seems to me now that one would need dependent types to guarantee Set's good behavior (so that the dictionary for the Ord instance is contained within the Set type). Отправлено с iPhone Oct 11, 2012, в 18:42, Mikhail Glushenkov the.dead.shall.r...@gmail.com написал(а): Hello, On Thu, Oct 11, 2012 at 4:33 PM, MigMit miguelim...@yandex.ru wrote: On Oct 11, 2012, at 6:23 PM, Mikhail Glushenkov the.dead.shall.r...@gmail.com wrote: On Thu, Oct 11, 2012 at 3:54 PM, MigMit miguelim...@yandex.ru wrote: You have a bigger problem coming. Some extensions make multiple instances OK, even in Safe Haskell. For example: {-# LANGUAGE FlexibleInstances, IncoherentInstances, Safe #-} [...] Safe Haskell already disallows OverlappingInstances. It doesn't. Overlapping instances are allowed in safe modules, provided that they won't be used in other modules. I stand corrected. Still, I think that something will have to be done about IncoherentInstances if the aforementioned restriction will be added. -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Class constraints with free type variables and fundeps
Well, it seems that you can't do exactly what you want. So, the simplest way to do this would be not to make Foo a superclass for Bar: class Bar a where foo :: Foo a b = a - b - c Then you would have to mention Foo everywhere. If you really need, for some reason, to ensure that every Bar instance has a corresponding Foo instance, you can do some oleging this way: data Void b = Void data FooEv a where FooEv :: Foo a b = Void b - FooEv a class Bar a where barFoo :: FooEv a bar :: Foo a b = a - b - c Then, whenever you need Foo methods, you can do pattern-matching: case barFoo :: FooEv a of FooEv (Void :: Void b) - … Now some b is in scope, and there is an instance of Foo a b. On Sep 28, 2012, at 8:36 PM, Francesco Mazzoli f...@mazzo.li wrote: I would expect this to work, maybe with some additional notation (a la ScopedTypeVariables) {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-} class Foo a b | a - b class Foo a b = Bar a where foo :: a - b - c The type family equivalent works as expected: {-# LANGUAGE TypeFamilies #-} class Foo a where type T a :: * class Bar a where foo :: a - T a - c I can't use type families because the `Foo' I'm using is in an external library. Is there any way to achieve what I want without adding `b' to `Bar'? -- Francesco * Often in error, never in doubt ___ 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] Class constraints with free type variables and fundeps
On Sep 29, 2012, at 9:49 PM, Gábor Lehel illiss...@gmail.com wrote: On Fri, Sep 28, 2012 at 6:36 PM, Francesco Mazzoli f...@mazzo.li wrote: I would expect this to work, maybe with some additional notation (a la ScopedTypeVariables) {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-} class Foo a b | a - b class Foo a b = Bar a where foo :: a - b - c The type family equivalent works as expected: {-# LANGUAGE TypeFamilies #-} class Foo a where type T a :: * class Bar a where foo :: a - T a - c I can't use type families because the `Foo' I'm using is in an external library. Is there any way to achieve what I want without adding `b' to `Bar'? I was browsing the GHC bug tracker and accidentally might have found a solution to your problem: http://hackage.haskell.org/trac/ghc/ticket/7100 Basically you have to make a type family to recapitulate the functional dependencies in the instances of Foo: type family FooFD a Actually, I think it's better to use a class here: class Foo a (FooFD a) = FooProxy a where type FooFD a -- for each instance Foo A B, you have to write: -- type instance FooFD A = B class Foo a (FooFD a) = Bar a where foo :: a - FooFD a - c Anywhere you would use 'b', you use the type family instead. The example in the ticket also had a 'b ~ FooFD a' superclass constraint on Foo itself, which you can't add if you don't control Foo, but I'm not sure what it's necessary for - in my brief tests removing it didn't cause problems. A weakness of this approach is that you have to manually add a type instance for every instance of Foo, which may or may not be a problem in your situation. -- Francesco * Often in error, never in doubt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Your ship was destroyed in a monadic eruption. ___ 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] Type error with Type families
It shoudn't typecheck. Suppose you have instances like instance ReplaceOneOf Foo where type Item Foo = Baz element = elementFoo instance ReplaceOneOf Bar where type Item Bar = Baz element = elementBar Now if you call replaceOneOf manyBazs foo1 foo2, Haskell should consult element :: Baz - [Baz] - Baz — but which one, elementBar or elementFoo? The error message is a bit criptic, but what it really means is that Haskell sees the possibility of such confusion and has to resort to the general element function of type Item something - [Item something] - Item something, and then fails to unify this Item something with Item full. It correctly notes that the type function Item is not injective, which means that Item Foo ~ Item Bar is possible even if Foo ~ Bar. For the solution. I assume that the standard elementOf function doesn't suit you. If so, you can make your Items instances of another class: class Element item where element :: item - [item] - Bool and change ReplaceOneOf declaration to class (LL.ListLike full (Item full), Element (Item full)) = ReplaceOneOf full where ... On Sep 16, 2012, at 3:05 PM, Marco Túlio Pimenta Gontijo marcotmar...@gmail.com wrote: Hi. I cannot make this program type check: {-# LANGUAGE TypeFamilies, FlexibleContexts #-} import qualified Data.ListLike as LL class LL.ListLike full (Item full) = ReplaceOneOf full where type Item full :: * replaceOneOf :: [Item full] - full - full - full replaceOneOf from to list | LL.null list = list | x `element` from = LL.concat [to, replaceOneOf from to $ LL.dropWhile (`element` from) xs] | otherwise = LL.cons x $ replaceOneOf from to xs where x = LL.head list xs = LL.tail list element :: Item full - [Item full] - Bool The error message is: Line 9: 1 error(s), 0 warning(s) Could not deduce (Item full0 ~ Item full) from the context (ReplaceOneOf full) bound by the class declaration for `ReplaceOneOf' at /home/marcot/tmp/test_flymake.hs:(4,1)-(15,45) NB: `Item' is a type function, and may not be injective Expected type: [Item full0] Actual type: [Item full] In the second argument of `element', namely `from' In the expression: x `element` from I have tried using asTypeOf, but it did not work: {-# LANGUAGE TypeFamilies, FlexibleContexts, ScopedTypeVariables #-} import qualified Data.ListLike as LL class LL.ListLike full (Item full) = ReplaceOneOf full where type Item full :: * replaceOneOf :: Item full - [Item full] - full - full - full replaceOneOf xt from to list | LL.null list = list | (x `asTypeOf` xt) `element` from = LL.concat [to, replaceOneOf xt from to $ LL.dropWhile (`element` from) xs] | otherwise = LL.cons x $ replaceOneOf xt from to xs where x = LL.head list xs = LL.tail list element :: Item full - [Item full] - Bool Can someone point me to a solution? Greetings. -- marcot http://marcot.eti.br/ ___ 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] Tutorial: Haskell for the Evil Genius
Mind if I join you in praising this? On Sep 17, 2012, at 12:06 AM, Kristopher Micinski krismicin...@gmail.com wrote: Agreed. Great. I still contend that it would be cool to get this to be a real thing at something like the Haskell workshop, I think hearing the different perspectives would be an interesting insight into the many different ways to explain monads. But I suppose the way to start would be to put up a webpage for collecting them.. kris On Sun, Sep 16, 2012 at 3:55 PM, Conal Elliott co...@conal.net wrote: Hi Tillmann. Wow. Lovely and spot on! And I almost never hear monad explanations without wincing. Thanks for sharing. -- Conal On Sun, Sep 16, 2012 at 7:48 AM, Tillmann Rendel ren...@informatik.uni-marburg.de wrote: Hi, Kristopher Micinski wrote: Everyone in the Haskell cafe probably has a secret dream to give the best five minute monad talk. (1) Most programming languages support side effects. There are different kinds of side effects such as accessing mutable variables, reading files, running in parallel, raising exceptions, nondeterministically returning more than one answer, and many more. Most languages have some of these effects built into their semantics, and do not support the others at all. (2) Haskell is pure, so it doesn't support any side effects. Instead, when Haskell programmers want to perform a side effect, they explicitly construct a description of the side effecting computation as a value. For every group of related side effects, there is a Haskell type that describes computations that can have that group of side effects. (3) Some of these types are built in, such as IO for accessing the world outside the processor and ST for accessing local mutable variables. Other such types are defined in Haskell libraries, such as for computations that can fail and for computations that can return multiple answers. Application programmers often define their own types for the side effects they need to describe, tailoring the language to their needs. (4) All computation types have a common interface for operations that are independent of the exact side effects performed. Some functions work with arbitrary computations, just using this interface. For example, we can compose a computation with itself in order to run it twice. Such generic operations are highly reusable. (5) The common interface for constructing computations is called Monad. It is inspired by the mathematical theory that some computer scientists use when they describe what exactly the semantics of a programming language with side effects is. So most other languages support some monad natively without the programmer ever noticing, whereas Haskell programmers can choose (and even implement) exactly the monads they want. This makes Haskell a very good language for side effecting computation. Tillmann ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Destructive updates to plain ADTs
Why modify it instead of creating the new one and let the previous tree get garbage collected? On Sep 9, 2012, at 12:46 PM, Milan Straka f...@ucw.cz wrote: Hi all, is there any way to perform a destructive update on a plain ADT? Imagine I have a simple data Tree a = Nil | Node a (Tree a) (Tree a) I would like to be able to modify right subtree of an existing tree. I can do that for example when using IORefs by changing the datatype to data Tree a = Nil | Node a (IORef (Tree a)) (IORef (Tree a)) and use unsafePerformIO + writeIORef. But the IORefs cause additional complexity when working with the data type. At the moment I am interested in any GHC solution, be it non-portable or version specific. I would like just to run some benchmarks and see the results. Cheers, Milan ___ 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] Platform Versioning Policy: upper bounds are not our friends
What if instead of upper (and lower) bounds we just specify our interface requirements? Like package bull-shit should provide value Foo.Bar.baz :: forall a. [a] - [a] - [a] or more general. Sure, it won't help dealing with strictness/lazyness, but it would capture most interface differences. And, in case the requirements aren't specified, we could also specify the default, like bool-shit 2.0 is known to fulfil this requirement; if yours doesn't, consider installing this one. On Aug 17, 2012, at 7:28 PM, Leon Smith leon.p.sm...@gmail.com wrote: I see good arguments on both sides of the upper bounds debate, though at the current time I think the best solution is to omit upper bounds (and I have done so for most/all of my packages on hackage).But I cannot agree with this enough: On Thu, Aug 16, 2012 at 4:45 AM, Joachim Breitner m...@joachim-breitner.de wrote: I think what we’d need is a more relaxed policy with modifying a package’s meta data on hackage. What if hackage would allow uploading a new package with the same version number, as long as it is identical up to an extended version range? Then the first person who stumbles over an upper bound that turned out to be too tight can just fix it and upload the fixed package directly, without waiting for the author to react. I think that constraint ranges of a given package should be able to both be extended and restricted after the fact. Those in favor of the reactionary approach (as I am at the moment, or Bryan O'Sullivan) would find the ability of to restrict the version range useful, while those in favor of the proactive approach (like Joachim Breitner or Doug Beardsley) would find the ability to extend the version range useful. I suspect that attitudes towards upper bounds may well change if we can set version ranges after the fact.I know mine very well might.And the difference between reactionary and proactive approaches I think is a potential justification for the hard and soft upper bounds; perhaps we should instead call them reactionary and proactive upper bounds instead. ___ 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] Platform Versioning Policy: upper bounds are not our friends
On Aug 18, 2012, at 12:35 AM, Bryan O'Sullivan b...@serpentine.com wrote: We already have a simple versioning scheme for which, despite it being easy to grasp, we have amply demonstrated that we cannot make it work well, because it has emergent properties that cause it to not scale well across a large community. Well, I think that the main reason for this failure is that despite being easy to grasp, this scheme doesn't really reflect the reality. It seems to be chosen arbitrarily. Any vastly more complicated and detailed versioning scheme has a huge burden to prove that it won't collapse dramatically more quickly. (Frankly, I think that anything involving specify every detail of your known dependencies is dead on arrival from a practical standpoint: it's way too much work.) That's not true. All this work can be automated — if you're the developer, you've certainly compiled the code yourself, and the compiler knows what was imported from other packages. The only problem is to make it save this information into a specific file. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Explicit forall - Strange Error
It really seems to me that the error message you've got explains everything quite clear. Отправлено с iPad 31.07.2012, в 22:59, Shayan Najd Javadipour sh.n...@gmail.com написал(а): Hi, I wonder why the following code doesn't typecheck in GHC 7.4.1: {-# LANGUAGE GADTs,RankNTypes #-} data T a where T1 :: (forall b. b - b) - (forall a. Int - T a) {- Error: Data constructor `T1' returns type `forall a. Int - T a' instead of an instance of its parent type `T a' In the definition of data constructor `T1' In the data type declaration for `T' Failed, modules loaded: none. -} While: {-# LANGUAGE GADTs,RankNTypes #-} f :: (forall b. b - b) - (forall a. Int - Maybe a) f = undefined {- ghci :t f f :: (forall b. b - b) - Int - Maybe a -} Thanks, Shayan ___ 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] Polyvariadic composition
Works here. GHC 7.4.2 On Jul 30, 2012, at 11:32 PM, Artyom Kazak artyom.ka...@gmail.com wrote: Hello, I have accidentally written my version of polyvariadic composition combinator, `mcomp`. It differs from Oleg’s version ( http://okmij.org/ftp/Haskell/polyvariadic.html#polyvar-comp ) in three aspects: a) it is simpler, b) it works without enumerating basic cases (all existing types, in other words), and c) it needs more type extensions. {-# LANGUAGE MultiParamTypeClasses , FunctionalDependencies , FlexibleInstances , UndecidableInstances , TypeFamilies , OverlappingInstances #-} class Mcomp a ar b br | a br - b where mcomp :: a - (ar - br) - b instance (a ~ ar, b ~ br) = Mcomp a ar b br where mcomp a f = f a instance (Mcomp a ar b br) = Mcomp (x - a) ar (x - b) br where mcomp a f = \x - mcomp (a x) f My question is: why doesn’t it work when I replace instance (a ~ ar, b ~ br) = Mcomp a ar b br with instance Mcomp a a b b ? I thought that equal letters mean equal types… ___ 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] Haskell's type inference considered harmful
Actually, both examples show that the problem isn't type inference, it's defaulting mechanism. Отправлено с iPhone Jul 17, 2012, в 12:46, o...@okmij.org написал(а): 1. Haskell's type inference is NON-COMPOSITIONAL! Yes, it is -- and there are many examples of it. Here is an example which has nothing to do with MonomorphismRestriction or numeric literals {-# LANGUAGE ExtendedDefaultRules #-} class C a where m :: a - Int instance C () where m _ = 1 instance C Bool where m _ = 2 main = do x - return undefined let y = x print . fst $ (m x, show x) -- let dead = if False then not y else True return () The program prints 1. If you uncomment the (really) dead code, it will print 2. Why? The dead code doesn't even mention x, and it appears after the printing! What is the role of show x, which doesn't do anything? Exercises: what is the significance of the monadic bind to x? Why can't we replace it with let x = undefined? [Significant hint, don't look at it] Such a behavior always occurs when we have HM polymorphism restriction and some sort of non-parametricity -- coupled with default rules or overlapping instances or some other ways of resolving overloading. All these features are essential (type-classes are significant, defaulting is part of the standard and is being used more and more). ___ 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] existential types and cast
Actually, using cast seems to be a perfect solution here. I can't see anything wrong with it. Отправлено с iPad 03.07.2012, в 20:33, Corentin Dupont corentin.dup...@gmail.com написал(а): Hi all, I read somewhere (here: http://stackoverflow.com/questions/2300275/how-to-unpack-a-haskell-existential-type) that it's bad to try to unbox an existential type using a cast. OK, but without I really can't figure out how to do what I want: data NewPlayer = NewPlayer deriving (Typeable, Eq) data NewRule = NewRule deriving (Typeable, Eq) class (Eq e, Typeable e) = Event e where data EventData e instance Event NewPlayer where data EventData NewPlayer = P Int instance Event NewRule where data EventData NewRule = R Int instance Typeable1 EventData where typeOf1 _ = mkTyConApp (mkTyCon EventData) [] data EventHandler = forall e . (Event e) = EH e (EventData e - IO ()) addEvent :: (Event e) = e - (EventData e - IO ()) - [EventHandler] - [EventHandler] addEvent e h ehs = (EH e h):ehs triggerEvent :: (Event e) = e - (EventData e) - [EventHandler] - IO () triggerEvent e d ehs = do let r = find (\(EH myEvent _) - cast e == Just myEvent) ehs case r of Nothing - return () Just (EH _ h) - case cast h of Just castedH - castedH d Nothing - return () How to remove the casts from triggerEvent? All that I want is to apply the handler found on the data passed in parameter. I tried to add a function apply in the class, without success: apply :: (EventData e - IO ()) - (EventData e) - IO () apply = ($) Thanks! Corentin ___ 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] transformers problem: Could not deduce MonadTrans (StateT s) ??
On 23 Jun 2012, at 21:27, Anton Kholomiov wrote: At last.. No, it wants me to define an instance for (StateT s) which is supposed to be defined be the authors of the library. Actually I discovered that I have two libraries called transformers. transformers-0.2.2.0 transformers-0.3.0.0 So when I'm doing import Control.Monad.Trans (0.2.2.0) Ehm... seems like you're importing mtl instead of transformers. AFAIK there is no Control.Monad.Trans module in transformers. I get the error And when I'm doing import Control.Monad.Trans.Class (0.2.2.0) It compiles. Anton ___ 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] Performance with do notation, mwc-random and unboxed vector
Well, it's not do notation, since replacing standard g with standard g = return gives the same poor performance. I wonder if it has something to do with error checking. On 11 Jun 2012, at 13:38, Dmitry Dzhus wrote: Hello everyone. I wonder why using do notation with `-` can ruin the performance. In essence the problem is that, for some action `f :: m Double`, running the code (in my case, `standard` from mwc-random). f for million times is fast but the code do v - f return v is slower about a hundred times. Consider this simple source where we generate an unboxed vector with million pseudo-random numbers: 8 - import qualified Data.Vector.Unboxed as VU import System.Random.MWC import System.Random.MWC.Distributions (standard) count = 100 main = do g - create e' - VU.replicateM count $ standard g return () 8 - Being compiled with -O2, this runs for 0.052 s on my machine. Changing the replicateM line to use do notation brings the runtime down to 11.257 s! See below: 8 - import qualified Data.Vector.Unboxed as VU import System.Random.MWC import System.Random.MWC.Distributions (standard) count = 100 main = do g - create e' - VU.replicateM count $ do v - standard g return v return () 8 - I don't quite understand why this happens. I'm using GHC 7.4.1 on Linux x86_64 system. Compiling *both* versions with profiling enabled changes runtime to 5.673 sec, which is exactly half the runtime of slow version without profiling, and this is awkward (double calculations occuring in do block?). Does anybody have an idea if this is a problem with my do, or with mwc-random, or with vector (my notation disallowing efficient unboxing?). ___ 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] Inheritance constraints
On 7 Jun 2012, at 20:55, Gábor Lehel wrote: If I'm understanding you correctly, this is similar to something I recently filed as a feature request: http://hackage.haskell.org/trac/ghc/ticket/5927 Yes, that seems to be it. Now I know I'm not alone. In the meantime it's possible to emulate it to a limited extent with the Sub type from the constraints package: http://hackage.haskell.org/packages/archive/constraints/0.3/doc/html/Data-Constraint.html#g:3 Good. Seems to be enough for me. Out of curiosity, do you have any specific use case in mind? It's something like Data types à la carte, but instead of a sum of all possible operations I try to use a class. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Unit and pair
Hi café, a quick question. Is there a somewhat standard class like this: class Something c where unit :: c () () pair :: c x y - c u v - c (x, u) (y, v) ? I'm using it heavily in my current project, but I don't want to repeat somebody else's work, and it seems general enough to be defined somewhere; but my quick search on Hackage didn't reveal anything. I know about arrows; this, however, is something more general, and it's instances aren't always arrows. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Unit and pair
On 8 May 2012, at 21:42, Felipe Almeida Lessa wrote: On Tue, May 8, 2012 at 2:36 PM, MigMit miguelim...@yandex.ru wrote: Hi café, a quick question. Is there a somewhat standard class like this: class Something c where unit :: c () () pair :: c x y - c u v - c (x, u) (y, v) ? I'm using it heavily in my current project, but I don't want to repeat somebody else's work, and it seems general enough to be defined somewhere; but my quick search on Hackage didn't reveal anything. I know about arrows; this, however, is something more general, and it's instances aren't always arrows. Are you aware of generalized arrows [1]? It's still a lot more than your Something, though. I've heard of them, but some instances of my Something class aren't categories either, which rules out GArrows too. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Unit and pair
That's an interesting idea, thanks. Отправлено с iPad 08.05.2012, в 23:31, Daniel Peebles pumpkin...@gmail.com написал(а): To expand on that, this class basically allows you to prove your relation c holds pointwise across arbitrary binary trees, represented by nested tuples and terminated by ()s. If individual instances of the class had additional ways of constructing values (i.e., proving the relation for the two type parameters), then your trees could contain other types. For example, if you had another type data Iso a b = Iso (a - b) (b - a) -- the functions must be inverses you could write an instance of Something for Iso and build a proof that ((), (a, ((), b)) is isomorphic to ((), (c, ((), d)) given Iso a c and Iso b d using your class. I'm not sure I'd bundle the two parts together, but I'd call your pair method (or the class it lives in) something like congruent or ProductsRespectThisRelation :) Dan On Tue, May 8, 2012 at 3:15 PM, Daniel Peebles pumpkin...@gmail.com wrote: FullBinaryTreeRelation? :P On Tue, May 8, 2012 at 1:36 PM, MigMit miguelim...@yandex.ru wrote: Hi café, a quick question. Is there a somewhat standard class like this: class Something c where unit :: c () () pair :: c x y - c u v - c (x, u) (y, v) ? I'm using it heavily in my current project, but I don't want to repeat somebody else's work, and it seems general enough to be defined somewhere; but my quick search on Hackage didn't reveal anything. I know about arrows; this, however, is something more general, and it's instances aren't always arrows. ___ 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 only one data structure per ST monad?
I would argue that there is just one ST monad, which makes the question even more strange. On 23 Apr 2012, at 22:32, KC wrote: Is it only one data structure per ST monad? -- -- Regards, KC ___ 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] Monad laws in presence of bottoms
Ehm... why exactly don't domain products form domains? On 21 Feb 2012, at 19:44, wren ng thornton wrote: On 2/21/12 2:17 AM, Roman Cheplyaka wrote: * Sebastian Fischerfisc...@nii.ac.jp [2012-02-21 00:28:13+0100] On Mon, Feb 20, 2012 at 7:42 PM, Roman Cheplyakar...@ro-che.info wrote: Is there any other interpretation in which the Reader monad obeys the laws? If selective strictness (the seq combinator) would exclude function types, the difference between undefined and \_ - undefined could not be observed. This reminds me of the different language levels used by the free theorem generator [1] and the discussions whether seq should have a type-class constraint.. It's not just about functions. The same holds for the lazy Writer monad, for instance. That's a similar sort of issue, just about whether undefined == (undefined,undefined) or not. If the equality holds then tuples would be domain products[1], but domain products do not form domains! In order to get a product which does form a domain, we'd need to use the smash product[2] instead. Unfortunately we can't have our cake and eat it too (unless we get rid of bottom entirely). Both this issue and the undefined == (\_ - undefined) issue come down to whether we're allowed to eta expand functions or tuples/records. While this is a well-studies topic, I don't know that anyone's come up with a really pretty answer to the dilemma. [1] Also a category-theoretic product. [2] Aka: data SmashProduct a b = SmashProduct !a !b -- Live well, ~wren ___ 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] Failing to find a function
Isn't that just something like liftA2 mplus? Отправлено с iPhone Feb 19, 2012, в 15:50, Jon Fairbairn jon.fairba...@cl.cam.ac.uk написал(а): This is probably a failure of my search fu or some other mental lacuna, but is there already a definition of this function somewhere: \a b - runKleisli $ (Kleisli a) + Kleisli b ? Hoogling for its type MonadPlus m = (a - m b) - (a - m b) - a - m b doesn’t net me anything useful. -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk ___ 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] types and number of evaluation steps
Different kinds of optimization. I expect you'd have different results even if you use one type, but different -O flags. On 18 Feb 2012, at 13:28, Heinrich Hördegen wrote: Dear all, I have a question about evaluation with respect to types and currying. Consider this programm: import Debug.Trace -- add :: Integer - Integer - Integer add :: Int - Int - Int add x y = x + y f a b c = trace b (add x c) where x = trace a (add a b) main :: IO () main = do print (f 1 2 3) print (f 1 2 4) Compiled with ghc-7.0.3: $ ghc --make Main.hs -o main -O2 The function add has to types. When we use type Int - Int - Int, the programm produces b a 6 b a 7 as output which shows that the x from the where clause in f is evaluated twice. However, when we use type Integer - Integer - Integer, this will give b a 6 b 7 which shows that x is evaluated only once. This was rather unexpected to me. Why does the number of evaluation steps depend on a type? Can anybody explain this or give a hint? Thank you very much, Heinrich -- -- hoerde...@funktional.info www.funktional.info -- ___ 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] types and number of evaluation steps
I'm not sure you can. Why do you need it? Отправлено с iPad 18.02.2012, в 14:56, Heinrich Hördegen hoerde...@funktional.info написал(а): Hi, this is true. The optimization only works with -O2. I'd like to have more details about what's going on. How can I make sure, that this optimization triggers? Heinrich On 18.02.2012 11:10, MigMit wrote: Different kinds of optimization. I expect you'd have different results even if you use one type, but different -O flags. On 18 Feb 2012, at 13:28, Heinrich Hördegen wrote: Dear all, I have a question about evaluation with respect to types and currying. Consider this programm: import Debug.Trace -- add :: Integer - Integer - Integer add :: Int - Int - Int add x y = x + y f a b c = trace b (add x c) where x = trace a (add a b) main :: IO () main = do print (f 1 2 3) print (f 1 2 4) Compiled with ghc-7.0.3: $ ghc --make Main.hs -o main -O2 The function add has to types. When we use type Int - Int - Int, the programm produces b a 6 b a 7 as output which shows that the x from the where clause in f is evaluated twice. However, when we use type Integer - Integer - Integer, this will give b a 6 b 7 which shows that x is evaluated only once. This was rather unexpected to me. Why does the number of evaluation steps depend on a type? Can anybody explain this or give a hint? Thank you very much, Heinrich -- -- hoerde...@funktional.info www.funktional.info -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- -- Funktionale Programmierung Dr. Heinrich Hördegen Gutenbergstr. 26 80638 München FON: +49 (89) 12 59 79 49 FAX: +49 (89) 12 59 79 50 hoerde...@funktional.info www.funktional.info -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] how to print out intermediate results in a recursive function?
Well, if you want that in production, not for debugging purposes, you should change the type signature of mergesort so that it uses some monad. Printing requires IO monad; however, I would advise to collect all intermediate results using Writer monad, and print them afterwards: mergesort [] = return [] mergesort [x] = return [x] mergesort xs = do tell [xs] -- that's right, [xs], not xs let (as, bs) = splitAt (length xs `quot` 2) xs liftM2 merge (mergesort as) (mergesort bs) On 4 Feb 2012, at 22:23, Qi Qi wrote: Hello, I have a question;how can I print out the intermediate number lists in a mergesort recursive function like the following one. merge [] ys = ys merge xs [] = xs merge (x:xs) (y:ys) = if x = y then x : merge xs (y:ys) else y : merge (x:xs) ys mergesort [] = [] mergesort [x] = [x] mergesort xs = let (as, bs) = splitAt (length xs `quot` 2) xs in merge (mergesort as) (mergesort bs) main = do print $ mergesort [5,4,3,2,1] In the main function, it only prints out the final number list. But I'd like to print out the number lists in every recursive level. How can I do that? Thanks. -- Qi Qi ___ 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] Monads, do and strictness
Отправлено с iPad 22.01.2012, в 20:25, David Barbour dmbarb...@gmail.com написал(а): Attempting to shoehorn `undefined` into your reasoning about domain algebras and models and monads is simply a mistake. No. Using the complete semantics — which includes bottoms aka undefined — is a pretty useful technique, especially in a non-strict language. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monads, do and strictness
On 21 Jan 2012, at 21:29, Victor S. Miller wrote: The do notation translates do {x - a;f} into a=(\x - f) However when we're working in the IO monad the semantics we want requires that the lambda expression be strict in its argument. So is this a special case for IO? If I wanted this behavior in other monads is there a way to specify that? No, why? The (=) combinator (for the IO monad) is strict on it's first argument, that's all. We don't impose any special requirements on the lambda expression. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] black Wikipedia (Was: PhD program at Portland State accepting applications)
On 18 Jan 2012, at 21:37, Henning Thielemann wrote: On Wed, 18 Jan 2012, Nathan Collins wrote: - Portland is a very popular US city, known for beer, bikes, music, and street food: http://en.wikipedia.org/wiki/Portland_Oregon (wikipedia is blacked out today) Maybe it is only a JavaScript trick. In Firefox (with JavaScript) I see the complete a page before it is overwritten by the protest page. In Konqueror of KDE 3 (with and without JavaScript) I can read the Wiki pages without problems. Edit however is really disabled. Sometimes I am glad to have the old technology available. :-) Well, I must admit, they succeeded in making me install AdBlock - just to block this banner (it really is a JavaScript trick). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Spurious pattern match warnings with GADTs
Type classes are inherently open. The compiler uses only the facts that there ARE some instances of the classes it needs, but it doesn't attempt to use information that some types AREN'T instances of certain classes. So, it can't use information that T0 isn't an instance of C1. And that's right thing to do — it could happen that there is instance C1 T0 in another module, which imports this one. On 13 Jan 2012, at 00:40, Tom Hawkins wrote: Let's say I have: data T0 data T1 data T a where A :: T T0 B :: T T1 Then I can write the following without getting any non-exhaustive pattern match warnings: t :: T T0 - String t a = case a of A - A However, if I use type classes to constrain the constructors, instead of using the phantom types directly: class C0 a instance C0 T0 class C1 a instance C1 T1 data T a where A :: C0 a = T a B :: C1 a = T a Then I get a non-exhaustive pattern match warning on 't'. How come? (I'm using GHC 7.0.4) It appears that the intelligent pattern analysis of the first example is a relatively recent addition [1]. -Tom [1] http://hackage.haskell.org/trac/ghc/ticket/3476 ___ 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] strict, lazy, non-strict, eager
On 24 Dec 2011, at 11:31, Albert Y. C. Lai wrote: So, on IRC in #haskell, from the same person, speaking on the same topic in the same context, in the same interval of 3 minutes (the first two sentences in the same minute): 1. a function f is strict if f ⊥ = ⊥ 2. ⊥ represents any computation which does not terminate, i.e. an exception or an infinite loop 3. strict describes the denotational semantics What's wrong with that? Denotational semantics: A. There are no computational steps. There is no termination, and there is no non-termination, since there are no steps to finish, and no steps to keep going. Incorrect. There ARE computational steps, of course, we just agree not to mention them when we talk about denotational semantics. Not mentioning something is not the same as stating that it doesn't exist. B. ⊥ represents no information, not non-termination. There is no non-termination to represent. There is, as there are computational steps. And the statement (2) above is not about denotational semantics only, so it's OK to talk about non-termination. Don't you know that you are allowed to use both semantics at the same time? C. fix id = ⊥ because ⊥ is the least fixed point of id, not because fix id non-terminates. There is nothing more obscure in science then the notion of because. fix id = (_|_) for the reason that suits your purposes. D. You say strict, more strict, less strict; non-strict, more non-strict, less non-strict. You don't say eager, and you don't say lazy. Oh, right, there is nothing more important then using the words properly. Operational semantics: A. There is no ⊥; it does not appear in any sequence of computational steps, finitely long or infinitely long. B. You say eager, more eager, less eager; lazy, more lazy, less lazy; or speculative, more speculative, less speculative; or any other adjectives for evaluation strategies. You don't say strict, and you don't say non-strict. See above. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
Отправлено с iPad 24.12.2011, в 18:50, Alexander Solla alex.so...@gmail.com написал(а): In the same way, denotational semantics adds features which do not apply to a theory of finite computation. And why exactly should we limit ourselves to some theory you happen to like? The /defining/ feature of a bottom is that it doesn't have an interpretation. What do you mean by interpretation? You know, the basic notion of a function which maps syntax to concrete values. http://en.wikipedia.org/wiki/Model_theory But (_|_) IS a concrete value. But they ARE very similar to other values. They can be members of otherwise meaningful structures, and you can do calculations with these structures. fst (1, _|_) is a good and meaningful calculation. Mere syntax. So what? Every other Haskell value /does/ have an interpretation. So, (_|_) is bad, but (1, _|_) is good? I did not introduce good and bad into this discussion. I have merely said (in more words) that I want my hypothetical perfect language to prefer OPERATIONAL (model) SEMANTICS for a typed PARACONSISTENT LOGIC over the DENOTATIONAL SEMANTICS which the official documentation sometimes dips into. Well, that's a different story. But it seems to me that the term Haskell-like won't apply to that kind of language. Also, it seems to me (though I don't have any kind of proof) that denotational semantics is something that is much simpler. It is clear that denotational semantics is a Platonic model of constructive computation. Could you please stop offending abstract notions? Then you are mistaken. I am talking about choosing the appropriate mathematical model of computation to accurately, clearly, and simply describe the language's semantics. Well, domain theory does exactly that for Haskell.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
On 23 Dec 2011, at 02:11, Conor McBride wrote: So... you are developing a programming language with all calculations being automatically lifted to a monad? What if we want to do calculations with monadic values themselves, like, for example, store a few monadic calculations in a list (without joining all there effects as the sequence function does)? The plan is to make a clearer distinction between being and doing by splitting types clearly into an effect part and a value part, in a sort of a Levy-style call-by-push-value way. The notation [list of effects]value type is a computation type whose inhabitants might *do* some of the effects in order to produce a value which *is* of the given value type. Oh, so it's not an arbitrary monad, but a single one. That's a bit disappointing. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
On 23 Dec 2011, at 02:11, Conor McBride wrote: So... you are developing a programming language with all calculations being automatically lifted to a monad? What if we want to do calculations with monadic values themselves, like, for example, store a few monadic calculations in a list (without joining all there effects as the sequence function does)? The plan is to make a clearer distinction between being and doing by splitting types clearly into an effect part and a value part, in a sort of a Levy-style call-by-push-value way. The notation [list of effects]value type is a computation type whose inhabitants might *do* some of the effects in order to produce a value which *is* of the given value type. Oh, so it's not an arbitrary monad, but a single one. That's a bit disappointing. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
Отправлено с iPad 22.12.2011, в 23:56, Conor McBride co...@strictlypositive.org написал(а): I'd be glad if pure meant total, but partiality were an effect supported by the run-time system. Then we could choose to restrict ourselves, but we wouldn't be restricted by the language. I second that. Having a special partiality monad would be nice. However, I'm not certain as to how it would interact with recursion — if f is a total function, fix f could be (and almost certainly would be) a possibly undiefined value. So, fix should have type (a - a) - Partial a; that's OK, but implicit uses of fix (I mean let statements) would be quite different. I'd like to program with an applicative notion, but in monadic types. That's what I'd do different, and for me, the subject is not a hypothetical question. So... you are developing a programming language with all calculations being automatically lifted to a monad? What if we want to do calculations with monadic values themselves, like, for example, store a few monadic calculations in a list (without joining all there effects as the sequence function does)? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
On 22 Dec 2011, at 06:25, Alexander Solla wrote: Denotational semantics is unrealistic. And so are imaginary numbers. But they are damn useful for electrical circuits calculations, so who cares? The /defining/ feature of a bottom is that it doesn't have an interpretation. What do you mean by interpretation? They should all be treated alike, and be treated differently from every other Haskell value. But they ARE very similar to other values. They can be members of otherwise meaningful structures, and you can do calculations with these structures. fst (1, _|_) is a good and meaningful calculation. Every other Haskell value /does/ have an interpretation. So, (_|_) is bad, but (1, _|_) is good? You know, my scientific advisor used to say math is about calling different things by the same name; philosophy is about calling the same thing by different names. It seems to me that philosophy is something you're doing now, whereas programming is all about math. I happen to only write Haskell programs that terminate. Sure, but if you've ever used recursion, then you do have bottoms in your program. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
Отправлено с iPhone Dec 20, 2011, в 7:10, Alexander Solla alex.so...@gmail.com написал(а): * Documentation that discourages thinking about bottom as a 'value'. It's not a value, and that is what defines it. It's definitely a value. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] If you'd design a Haskell-like language, what would you do different?
Отправлено с iPhone Dec 20, 2011, в 14:40, Jesse Schalken jesseschal...@gmail.com написал(а): On Tue, Dec 20, 2011 at 9:34 PM, Gregory Crosswhite gcrosswh...@gmail.com wrote: On Dec 20, 2011, at 8:30 PM, Jesse Schalken wrote: On Tue, Dec 20, 2011 at 8:46 PM, Ben Lippmeier b...@ouroborus.net wrote: On 20/12/2011, at 6:06 PM, Roman Cheplyaka wrote: In denotational semantics, every well-formed term in the language must have a value. So, what is a value of fix id? There isn't one! Bottoms will be the null pointers of the 2010's, you watch. This ×1000. Errors go in an error monad. Including all possible manifestations of infinite loops? Definitely. If you think a value might not reduce, return an error in an error monad. Then the caller is forced to handle the case of an error, or propagate the error upwards. The error can also be handled in pure code this way, whereas bottom can only be handled within the IO monad. So... this imaginary language of yours would be able to solve the halting problem? Cheers, Greg ___ 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] If you'd design a Haskell-like language, what would you do different?
On 21 Dec 2011, at 08:24, Alexander Solla wrote: I would rather have an incomplete semantic, and have all the incomplete parts collapsed into something we call bottom. I don't see the reason to limit ourselves to that. Of course, in total languages like Agda there is no need for (_|_). But in a turing-complete lazy language like Haskell we really need it. Of course, it makes not much sense to write fix id anywhere in your program; but, for example, lists like 1:2:3:4:5:_|_ can be really useful. And denotational semantics is not just nice. It is useful. It's the best way to understand why the program we just wrote doesn't terminate. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Poll: Do you want a mascot?
No On 23 Nov 2011, at 23:11, heathmatlock wrote: Question: Do you want a mascot? Answers: Yes No -- This is an attempt to figure out if this idea is going anywhere. ___ 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] A Mascot
The fact that nobody bothered to write one down doesn't mean there isn't one. Отправлено с iPhone Nov 16, 2011, в 13:07, Andrew Butterfield andrew.butterfi...@cs.tcd.ie написал(а): On 16 Nov 2011, at 08:46, Ertugrul Soeylemez wrote: But I think, despite the well-founded denotational semantics of Haskell, bottom does not play that much of a role. There is one? Where? Last time I looked (a while ago, admittedly) there was no denotational (or any formal) semantics for Haskell. - lots of stuff for fragments of Haskell-like languages or parts of Haskell, but not a full proper definitive semantics for *Haskell*, as found in the wild... Looking at http://en.wikibooks.org/wiki/Haskell/Denotational_semantics the first footnote states In fact, there are no written down and complete denotational semantics of Haskell. This would be a tedious task void of additional insight and we happily embrace the folklore and common sense semantics. However, if you have a proof-based tool used for reasoning about Haskell programs in a safety-critical environment, you might just need to do this tedious task, particularly in order to show your proof rules sound. - has anyone in that area done this? is it available ? Is there a definitive Operational Semantics? Axiomatic? PS - I love the mascot - thanks Heath ! Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife = sex) http://ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204 Lero@TCD, Head of Foundations Methods Research Group Director of Teaching and Learning - Undergraduate, School of Computer Science and Statistics, Room G.39, O'Reilly Institute, Trinity College, University of Dublin http://www.scss.tcd.ie/Andrew.Butterfield/ ___ 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] A Mascot
Maybe it's just me, but I've thought that being non-strict just means that it's possible for a function to produce some value even if it's argument doesn't; in other words, that it's possible to have f (_|_) ≠ (_|_). If there was no such thing as (_|_), what would non-strictness mean? On 16 Nov 2011, at 13:46, Bas van Dijk wrote: On 16 November 2011 05:18, John Meacham j...@repetae.net wrote: Not nearly enough attention is paid to the other striking feature, the laziness. The 'bottom' symbol _|_ should feature prominently. The two most defining features of haskell are that it is purely functional and _|_ inhabits every type. The combination of which is very powerful. Is ⊥ the right symbol to express the non-strict evaluation of the language? Is it true that non-strict evaluation requires that ⊥ inhabits every type? In other words: why can't there exist a non-strict total language (probably having some form of coinductive types)? Cheers, Bas ___ 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] A Mascot
You're probably missing the fact that it's much harder to understand how the Haskell program works without (_|_). I've seen lots of questions like why doesn't my recursion work that could be answered simply as because your function is strict, so (_|_) is it's minimal fixpoint. Отправлено с iPhone Nov 16, 2011, в 15:31, Jesse Schalken jesseschal...@gmail.com написал(а): I like the idea of a mascot. I like the idea of a lamb called Da, as most of Haskell's strength comes from it's closeness to pure lambda calculus. A few things I'd like to see in a mascot: - Simple. You should be able to draw it in a few seconds. - Look good in black and white. - Have obvious features so it is identifiable from a distance. - Be a little bit cute. I don't see why ⊥ has to be featured. ⊥ means a computation can terminate without returning a value. That is a flaw, not a strength. If a computation may fail, return a Maybe or Either String. If a computation might not terminate, let it not terminate and I can find out why with my debugger. That covers all the use cases of ⊥. It also undermines the type system as beginners often write functions which return ⊥ where they should either be returning a Maybe or Either String, or expressing the violated precondition in the type system so it can be tested at compile time. What am I missing? On Wed, Nov 16, 2011 at 9:47 PM, Bas van Dijk v.dijk@gmail.com wrote: On 16 November 2011 11:05, MigMit miguelim...@yandex.ru wrote: Maybe it's just me, but I've thought that being non-strict just means that it's possible for a function to produce some value even if it's argument doesn't; in other words, that it's possible to have f (_|_) ≠ (_|_). If there was no such thing as (_|_), what would non-strictness mean? Thanks, non-strictness is indeed defined using ⊥ like you mentioned. I think I was confusing non-strict evaluation with coinduction. They have the same advantages but the latter is less powerful but safer than the former. Bas ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Deduce problem.
You've declared from as forall b. Test - [b], but you're trying to implement it as Test - H. On 17 Nov 2011, at 07:48, Magicloud Magiclouds wrote: Hi, Consider I have declarations like this: class (ClassA a) = ClassC a where from :: (ClassB b) = a - [b] to :: (ClassB c) = a - [c] data H = ... instance ClassB H where ... data Test = Test { m :: H } instance ClassA Test where ... instance ClassC Test where from = m to = m Well, I got could not deduce error here at from = m and to = m. `c' is a rigid type variable bound by the type signature for to :: ClassB c = Test - [c]. Referring to some similar questions on internet, I should remove the (ClassB c) thing. Is this the only solution? -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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] Deduce problem.
Of course, b can be H. The important question is: why can't it be something else? ClassC signature implies that b can be anything (of class ClassB) — not just H. Another error is that you declare from as returning a list, but you try to implement it as returning a single value. On 17 Nov 2011, at 08:54, Magicloud Magiclouds wrote: I think this is where I did not understand from the very beginning. If the the declaration was correct, then why cannot b be H? Referring to Data.List.genericLength, I was confused. On Thu, Nov 17, 2011 at 12:34 PM, MigMit miguelim...@yandex.ru wrote: You've declared from as forall b. Test - [b], but you're trying to implement it as Test - H. On 17 Nov 2011, at 07:48, Magicloud Magiclouds wrote: Hi, Consider I have declarations like this: class (ClassA a) = ClassC a where from :: (ClassB b) = a - [b] to :: (ClassB c) = a - [c] data H = ... instance ClassB H where ... data Test = Test { m :: H } instance ClassA Test where ... instance ClassC Test where from = m to = m Well, I got could not deduce error here at from = m and to = m. `c' is a rigid type variable bound by the type signature for to :: ClassB c = Test - [c]. Referring to some similar questions on internet, I should remove the (ClassB c) thing. Is this the only solution? -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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] German names for kinds and sorts
In Russian we have the same problem: there is no such thing as a usual translation of the word kind. Seems to me that russian Haskell programmers mostly use an English word adapted to the Russian language: кайнды (kaindy). So, I think, you can do the same thing in German, just name them Kinden or Kinder. Отправлено с iPhone Nov 12, 2011, в 20:05, Robert Clausecker fuz...@gmail.com написал(а): Hi all! I want to write my Facharbeit (kind of an essay you have to write on a specific topic you can choose yourself for highschool graduation) about the type-system of Haskell. It is required in our school to write this document in German language. Most time, it is not really difficult to find an appropriate term for concepts of Haskell, like types (Typen) or type classes (Typklassen). But I really don't know how to call kinds and sorts in German. Any ideas? Yours, Robert Clausecker ___ 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 do you describe systems in general with Haskell?
Well, I usually use whatever comes handy, but I'm sure there are other approaches — like, for example, trying something almost unusable first. Отправлено с iPad 05.11.2011, в 21:17, Grigory Sarnitskiy sargrig...@ya.ru написал(а): If you are to describe a system, which consists of several subsystems, how do you approach the problem? What types, classes, functions whatever do you introduce? I guess it is a common problem, is there a general method? Just to describe, not to solve (though if the description implies the solution then it is wonderful). Obviously this is not just a haskell-specific problem, but I think there might be people who are aware of the best current solution (category theory?). For a dummy example, how would you describe the system from a fox, goose and bag of beans puzzle (wolf, goat and cabbage)? ___ 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 get the information of instances of a type?
Can't be done. Even if this particular module doesn't contain instance Class Type, it's quite possible that the said instance would be defined in another module, about which this one knows nothing about. On the other hand, what would you do with that information? Отправлено с iPad 26.10.2011, в 17:53, Magicloud Magiclouds magicloud.magiclo...@gmail.com написал(а): Hi, If this was in ruby or other languages that support reflection, it won't be a question. But in Haskell, could I write a code to list the classes that a type instanced? TemplateHaskell as well. -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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] Message
Yeah, I was going to mention Smalltalk too, as one of the languages NOT using plain text to store programs — which led to a very strong boundary between ST and other world, not doing any favors to the first. The idea of using some non-plaintext-based format to store programs appeared lots of times, without any significant achivements. And I think one of the main reasons for that is that it makes interacting with other tools extremely difficult. Not just with pre-existing tools. Even if grep didn't exist, it would be very easy to hack something like it if you need to search your codebase for a specific word; you don't need any complex APIs to read plain text files, there are just two functions — one to read a line of code, and another one to check for eof. Similarly, it's easy to generate your Java files with a Perl script — with Perl itself not knowing anything about Java. Text has the advantage of being SIMPLE — and the vague idea of embedding a spreadsheet in your code (what the hell for?) doesn't come close to beating it. And you know what? You don't really need to give up text-based storage to have graphic capabilities. Windows resources files (.rc) are text-based, and there are plenty of visual editors for them, including one in Visual Studio; and, thankfully, it still produces the same old text-based file — and sometimes it's very desirable to look into one, for example, if you want to know which control is tagged with this ID. Отправлено с iPad 22.10.2011, в 21:06, Claus Reinke claus.rei...@talk21.com написал(а): The world needs programmers to accept and take seriously Greg Wilson's extensible programming, and stop laughing it off as lolwut wysiwyg msword for programming, and start implementing it. http://third-bit.com/blog/archives/4302.html Who is the world? For starters, I don't think it is Greg Wilson's idea, and if you look for alternate sources, often under other titles, you'll find parts of it implemented, with varying degrees of success and often little acceptance. The idea is much older than one might think - conferences on extensible languages were held around 1970. Early implementation approximations didn't have the disposable computing power of today's PCs, nor did early implementers find an audience ready for their ideas (to feed their students or themselves, some of those who were such ahead of the curve had to switch to working on more conventional, funded, topics). Useful search keys: - extensible languages (as in AI, the meaning of extensible tends to be redefined whenever a problem gets solved, so many features that used to mark an extensible language in the past have now become standard) - structure editors (in that they were forerunners of projectional IDEs, and exhibited some of their advantages and disadvantages; there have been many efforts to generate structure editors fromlanguage descriptions) - projectional language workbenches (instead of parsing source to AST, the IDE/workbench operates on an AST-like abstract model, and source code views are just projections of that;makes it easier to embed sublanguages); Smalltalkers will probably claim their image-based IDEs have been doing that all along. - hyper-programming (where persistent runtime data can beembedded in code via linking, similar to hypertext, with generic editors instead of generic Read/Show) - Banana Algebra: Syntactic Language Extension via an Algebraof Languages and Transformations (one example of research on language composition) IDE generators, IDE tooling for domain-specific languages, language-oriented programming, language workbenches, ... they all contribute to the now broader interest in the topic. In the context of Haskell, there once was Keith Hanna's document-centered programming: http://www.cs.kent.ac.uk/projects/vital/ http://www.cs.kent.ac.uk/projects/pivotal/ Perhaps Keith's projects can serve as an inspiration to just start hacking?-) The subject is an instance of these quotes: The future is already here - it's just not very evenly distributed. William Gibson The best way to predict the future is to invent it. Alan Kay Claus http://clausreinke.github.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] Arrow based re-definition of `StateT' included in `Control.Arrow.'?
Control.Arrow.Transformer.State.StateArrow? Отправлено с iPad 11.10.2011, в 17:02, Captain Freako capn.fre...@gmail.com написал(а): Hi all, Is the Arrow-based re-definition of `StateT' included somewhere in the `Control.Arrow.' stack, or do you put the code into your program explicitly? Thanks, -db ___ 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] Configuration Problem and Plugins
data Renderer = Renderer {destroy :: IO (); render :: SystemOutput - IO ()} newtype Initializer = Initializer {initialize :: IO Renderer} Отправлено с iPad 03.09.2011, в 14:15, M. George Hansen technopolit...@gmail.com написал(а): Greetings, I'm a Python programmer who is relatively new to Haskell, so go easy on me :) I have a program that uses (or will use) plugins to render output to the user in a generic way. I'm basing the design of the plugin infrastructure on the Plugins library, and have the following interface: data Renderer = Renderer { initialize :: IO (), destroy :: IO (), render :: SystemOutput - IO () } The program loads plugins at the start and runs the initialize function, and then enters the main loop where it repeatedly calls the render function with output to display. When the program exits the main loop, it calls the destroy function to clean up any resources used by the plugin. You can probably already see my problem: how do I pass initialization information created in the initialize function to the render function? I'm vaguely aware of some solutions to the typical configuration problem, such as implicit arguments or explicitly passing the configuration data through the function call hierarchy. As far as I can tell, neither of these approaches would work because the program can't know at compile time what, if any, configuration data is used by the plugin. I suppose I could pass a Dynamic up the call chain and let the plugin decode it in the render function, but that seems a little kludgy to me. Any thoughts would be greatly appreciated. -- M. George Hansen ___ 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] Existential question
Ehm... what? How can you do such a replacement without losing, for example, functions like this: f (KI s h) i = snd $ h i $ fst $ h i s Отправлено с iPad 24.08.2011, в 11:43, o...@okmij.org написал(а): I had simplified the type to make the plumbing simpler. My intention was to include an initial value to use the function as a sequence transformer / generator: data Kl i o = forall s. Kl s (i - s - (s, o)) That change makes a world of difference! For example, the above type (Kl i) is clearly a monad instance Monad (Kl i) where return x = Kl () (\_ s - (s,x)) (Kl s m) = f = Kl s (\i s - case f (snd (m i s)) of Kl s' m' - (s,snd (m' i s'))) It is the Reader monad. Different Kl values have their own, private s. The quantification ensures that each encapsulated 's' applies only to its generator. Therefore, we can just as well apply that 's' right at the very beginning. Therefore, data Kl i o = forall s. Kl s (i - s - (s, o)) is essentially data Kl' i o = Kl' (i - o) which is certainly and Arrow and a Monad. We do not need existential at all. The web page http://okmij.org/ftp/Computation/Existentials.html describes other eliminations of Existentials. Does the growing type s1 - s2 - (s1,s2) in the bind-like method below support some other abstraction that is monad-like? data Kl1' s o = Kl1' (s - (s,o)) bind' :: (Kl1' s1 i) - (i - Kl1' s2 o) - (Kl1' (s1,s2) o) bind' mi f = Kl1' mo where mo (s1,s2) = ((s1',s2'),o) where (Kl1' u1) = mi (s1', i) = u1 s1 (Kl1' u2) = f i (s2', o) = u2 s2 Not all things are monads; for example, restricted and parameterized monads are not monads (but do look like them, enough for the do-notation). Your Kl1' does look like another generalization of monads. I must say that it seems to me more fitting for a parametrized applicative: class Appish i where purish :: a - i s a appish :: i s1 (a -b) - i s2 a - i (s1,s2) b data KL s a = KL (s - (s,a)) instance Appish KL where purish x = KL (\s - (s,x)) appish (KL f1) (KL f2) = KL $ \(s1,s2) - let (s1', ab) = f1 s1 (s2', a) = f2 s2 in ((s1',s2'), ab a) ___ 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] Problem with types
p :: (forall o. M o - M o) - ... Отправлено с iPad 19.08.2011, в 16:06, Anupam Jain ajn...@gmail.com написал(а): Hi all, Suppose I have a compound data type - data M o = M (String,o) Now, I can define a function that works for ALL M irrespective of o. For example - f :: M o - M o f (M (s,o)) = M (s++!, o) I can also use this function in an expression, applying it to different types without problem - p = (m1',m2') where m1 = M (1, ()) m2 = M (2, True) m1' = f m1 m2' = f m2 Main* p (M (1!,()),M (2!,True)) However, if I try to parameterise over the function 'f' it does not work! - p f = (m1',m2') where m1 = M (1, ()) m2 = M (2, True) m1' = f m1 m2' = f m2 It doesn't even typecheck, producing the error - Couldn't match expected type 'Bool' with actual type '()' Is there a particular reason for this? How can I define a function like 'p' within Haskell? Thanks, Anupam Jain ___ 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] Question about data
Your MathExpression data type has nothing to do with numbers of any kind. Your Float data constructor doesn't mean that float numbers are a part of your type; instead it means that you have a SINGLE value of type MathExpression, and this value is named Float. You should modify your data declaration as data MathExpression = Float Float | …, and after that you can write something like a = Float 4.2, which would automatically make a a value of type MathExpession. Отправлено с iPad 20.08.2011, в 0:40, Paul Reiners paul.rein...@gmail.com написал(а): I've created a simple type declaration: data MathExpression = Float | Add MathExpression MathExpression | Subtract MathExpression MathExpression | Multiply MathExpression MathExpression | Divide MathExpression MathExpression deriving (Show) Now how do I create an instance of MathExpression which is just a Float? This doesn't work: *Main let pi = 3.14 :: MathExpression interactive:1:10: No instance for (Fractional MathExpression) arising from the literal `3.14' Possible fix: add an instance declaration for (Fractional MathExpression) In the expression: 3.14 :: MathExpression In an equation for `pi': pi = 3.14 :: MathExpression ___ 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] Invitation to connect on LinkedIn
Not so sure; his company's website is under construction for more than a year and after brief google'ing I still don't understand even what kind of business are they supposed to be in. Seems more likely that it's actually Andrew who does the spamming. Отправлено с iPad 14.08.2011, в 21:18, Brandon Allbery allber...@gmail.com написал(а): On Sun, Aug 14, 2011 at 13:09, vagif.ve...@gmail.com wrote: That's a clever way to build your resume. :)) No, just LinkedIn being stupid; the sign-up form is designed to spam your contacts, and you actually have to take some care to avoid it. -- 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Category theory as a design tool
I remember myself complaining about how when one says something stupid and corrects himself in a few minutes, it's the first message that attracts all the attention, not the second one. Отправлено с iPhone Jun 22, 2011, в 8:42, Alex Rozenshteyn rpglove...@gmail.com написал(а): Funny, I didn't hear anyone say Candlejack. What abou ___ 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] Probably type checker error.
Yeah, seems to work too. Отправлено с iPhone Jun 20, 2011, в 10:55, Corey O'Connor coreyocon...@gmail.com написал(а): Not just a proposal any more. :-) GHC 7.0 does not generalize local let bindings in some situations. See here for information: http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7 There is a proposal (from Big Simon) to remove let-generalization: http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf On 19 Jun 2011, at 18:26, Serguey Zefirov wrote: Right now I write a quite heavy transformation of Haskell source code and found some strange behaviour of typechecker. Some prerequisites: -- dummy class. My own class is much bigger, but I -- could reproduce that behaviour with that class. class ToWires a -- a type with phantom type arguments. data E ins outs = E -- a function that relates E and its inputs. projectInsType :: E ins outs - ins projectInsType = error projectInsType gets evaluated. -- register function. register :: a - a - a register def a = def -- a simple addition. add2 :: (ToWires a, Num a) = (a,a) - a add2 (a,b) = a+b First I have a function: func :: (ToWires a, Num a) = Maybe a - a func mbA = currentSum where x = case mbA of Just a - a Nothing - 0 nextSum = add2 (x,currentSum) currentSum = register 0 nextSum It typechecks and works just fine after some transformation. The transformation I work on transform code into something like that: func_E :: (ToWires a, Num a) = E (Maybe a) a func_E = r where r = E -- here we relate mbA and r. mbA = projectInsType r x = case mbA of Just a - a Nothing - 0 nextSum = add2 (x,currentSum) currentSum = register 0 nextSum Note the absence of input of func in transformed func_E. I relate mbA with it's proper type using binding mbA = projectInsType r. Then suddently ghc loses all of the context associated with mbA. And find type error at the calling of add2. If I drop ToWires from contexts of func_E and add2 types, all works fine. If I change add2 to simple addition (x + currentSum), all works fine. Full source code is in attachment. I found it using ghc 6.12.1. I asked colleagues, they told me that the same error manifests itself in ghc 7.0.3. Should I fill a bug report or maybe I misunderstood something? a.hs___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell *interpreter* on iPad? (Scheme and Ocaml are there)
Well, Haskell is fun, isn't it? And that's what iPhone is perfect for: fun. Back when I had iPod Touch 1G (jailbroken, of course), I used to run Hugs on it. Now I would love to see a Haskell interpreter in the App Store — which, by the way, is possible; as there are Scheme interpreters there, why not Haskell? Отправлено с iPhone Jun 18, 2011, в 22:27, Jack Henahan jhena...@uvm.edu написал(а): I suppose you could make a GUI, by why? Given that you'll have to be working on a jailbroken device, anyway, one could just as well use one of the numerous terminal emulators now floating around for jailbroken iOS. That said, the idea of people writing Haskell on phones and iPads and so on makes me just a little bit grinny. On Jun 18, 2011, at 2:17 PM, Alexander Solla wrote: On Sat, Jun 18, 2011 at 10:46 AM, John Velman vel...@cox.net wrote: To further emphasize, I'd like to type in (or paste in) Haskell code and have it executed on the iPad. To reiterate: Something like Hugs, or ghci on the iPad. Since the iPhone OS is pretty much OS X for ARM, and GHC apparently now supports cross-compilation, you can compile GHC for iOS. I guess you could cross compile Hugs with GCC. Doing so probably isn't trivial, but it should be straightforward. I bet you could even use Xcode to make a graphical user interface to GHCi. ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Instances and multiple inheritance
I fail to understand why instantiating a four-argument class with five arguments seems obvious to you. Отправлено с iPhone Jun 12, 2011, в 12:37, Patrick Browne patrick.bro...@dit.ie написал(а): class (Surfaces v o, Paths a b (v o)) = Vehicles v o a b where -- I do not know how to make an instance of Vehicles -- What seems to be the *obvious* does not work -- instance Vehicles [] Integer (,) Integer Integer where -- Kind error: `Vehicles' is applied to too many type arguments -- In the instance declaration for -- `Vehicles [] Integer (,) Integer Integer' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cons of -XUndecidableInstances
One particularly trivial example that comes to mind is: newtype Mu f = Mu (f (Mu f)) instance Show (f (Mu f)) = Show (Mu f) where show (Mu x) = Mu ( ++ show x ++ ) -- Or however you'd like to show it Ehm, that does look like poor design. Sure you don't mean Mu f can be printed if and only if f (Mu f) can be printed. What you probably mean is if f transforms printable things to printable things, then Mu f is a printable thing. And you CAN express just that: type ShowD a = forall p. (forall x. Show x = p x) - p a showD :: Show a = ShowD a showD px = px class ShowF f where showF :: Show a = ShowD (f a) instance Show a = Show (F a) where... -- here goes your f instance ShowF F where showF = showD -- and that is the only line of boilerplate instance ShowF f = Show (Mu f) where show (Mu fm) = Mu ( ++ runShowHelper (showF (ShowHelper show)) fm ++ ) newtype ShowHelper x = ShowHelper {runShowHelper :: x - String} Sorry for possible bugs — I don't have ghc anywhere near me at the moment, but the idea is clear, I guess. Отправлено с iPhone ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Robert Harper on monads and laziness
Yes, I'm following it too, and it seems to me that Harper just allows his dislike for Haskell to take advantage of his judgement. Monads as a way to deal with laziness are a very common misconception. Отправлено с iPhone May 2, 2011, в 11:54, Ketil Malde ke...@malde.org написал(а): I'm following Harper's blog, Existential Type¹, which I find to be an enjoyable and entertainingly written tirade about the advantages of teaching functional programming - specifically ML - to students. Of course, he tends to be critical of Haskell, but it's nice to get some thought provoking opinion from somebody who knows a bit about the business. Recently, he had a piece on monads, and how to do them in ML, and one statement puzzled me: There is a particular reason why monads had to arise in Haskell, though, which is to defeat the scourge of laziness. My own view is/was that monads were so successful in Haskell since it allowed writing flexible programs with imperative features, without sacrificing referential transparency. Although people are quick (and rightly so) to point out that this flexibility goes way beyond IO, I think IO was in many ways the killer application for monads. Before IO, we had very limited functionality (like 'interact' taking a 'String - String' function and converting it into an exectuable program) to build real programs from. Laziness does require referential transparency (or at least, it is easier to get away with the lack of RT in a strict language), so I can see that he is indirectly correct, but RT is a goal in itself. Thus, I wonder if there are any other rationale for a statement like that? -k ¹ http://existentialtype.wordpress.com/ -- 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Python is lazier than Haskell
It would be, if only it checked the (necessary) types during compile time. As it is now, it seems like a claim that C is lazy just because any pointer can be null. Отправлено с iPhone Apr 27, 2011, в 13:30, Henning Thielemann lemm...@henning-thielemann.de написал(а): I like to apply for the quote of the week. :-) If Haskell is great because of its laziness, then Python must be even greater, since it is lazy at the type level. Dynamically typed languages only check types if they have to, that is if expressions are actually computed. Does this prove that laziness at type level as in Python is a great thing or does this prove that laziness at the value level as in Haskell is a bad thing or does this prove nothing? Hope for controversial discussion ... ___ 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] Code Golf
If I understand the problem correctly... Prelude let diag = concat . diags where diags ((x:xs):xss) = [x] : zipWith (:) xs (diags xss) Prelude take 10 $ diag [[ (m,n) | n - [1..]] | m - [1..]] [(1,1),(1,2),(2,1),(1,3),(2,2),(3,1),(1,4),(2,3),(3,2),(4,1)] Sebastian Fischer wrote on 15.04.2009 14:32: Fancy some Codegolf? I wrote the following function for list diagonalization: diag l = foldr (.) id ((sel l . flip sel) ((:[]).(:))) [] where sel = foldr (\a b c - id : mrg (a c) (b c)) (const []) . map (flip id) mrg [] ys = ys mrg xs [] = xs mrg (x:xs) (y:ys) = (x.y) : mrg xs ys Self explanatory, isn't it? Here is a test case: *Main take 10 $ diag [[ (m,n) | n - [1..]] | m - [1..]] [(1,1),(1,2),(2,1),(1,3),(2,2),(3,1),(1,4),(2,3),(3,2),(4,1)] I was trying to golf it down [^1] but my brain explodes. If you succeed in reducing keystrokes, I'd be happy to know! Cheers, Sebastian [^1]: http://codegolf.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