[Haskell-cafe] (Pre-) Announce: Data.GDS 0.1.0
Hello, all, I'm hereby announcing Data.GDS, a small module to write and (eventually -- that's part of the pre) read GDS files. For those of you not in the semiconductor biz, GDS-II is one of the classic formats of the industry. It's perhaps ever so slightly obsolete at this point, as the OASIS format is in the process of displacing it, but there are still huge numbers of designs in GDS format, and lots and lots of tools deal with it. Since I'm a sad sick weirdo(*), I spent a perfectly nice sunny NorCal day hacking up this initial version of this module. It is to the point where it can generate a GDS file of your devising, although your specification of it still has to be at a very low level. It would be, and eventually will be, nicer to specify things at a higher level of abstraction. Also, it will eventually be nice to be able to read GDS files, returning an array of GDSRecord. I know how to do that, and I plan to, but I haven't got there yet. This ought to already be properly cabalized, and there's a small test program included; run it, save the output somewhere, and compare that with the sample GDS file which I also included in the tarball. If you examine the GDS file itself, you will see that, although it is small, it does in fact contain vital bits of design which will no doubt enable the biz to continue Moore's law for at least another century or so. Once I've implemented the reader, I'll upload this to hackage; in the meantime, if any of you are especially interested in what the rest of the interface to this should look like, I'm happy to hear your suggestions! Uwe (*) In point of fact, I am neither sad nor sick; I am in fact mostly happy healthy. The reason I wasn't out taking a long walk today was because, alas, I dinged one achilles tendon a few days ago, and wanted to let it heal a bit... as to the weirdo charge, I beg you, gentle readers, avert your eyes while I plead no contest! :-) gds-0.1.0.tar.gz Description: GNU Zip compressed data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Umlauts in command line arguments
Hello Gwern, Monday, June 1, 2009, 4:35:25 AM, you wrote: GHC mangles UTF by default. You probably want to use one of the utf8 packages; eg. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-string or http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-light (Neither of them seems to allow for accessing *arguments* rather than stdin/stdout, but you could probably do something with the encoding/decoding functions.) in order to get proper unicode handling, one should ask win api directly for cmdline: myGetArgs = do alloca $ \p_argc - do p_argv_w - commandLineToArgvW getCommandLineW p_argc argc - peek p_argc argv_w - peekArray (i argc) p_argv_w mapM peekTString argv_w == tail foreign import stdcall unsafe windows.h GetCommandLineW getCommandLineW :: LPTSTR foreign import stdcall unsafe windows.h CommandLineToArgvW commandLineToArgvW :: LPCWSTR - Ptr CInt - IO (Ptr LPWSTR) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] iota
Hi all, I was looking for an APL-style iota function for array indices. I noticed range from Data.Ix which, with a zero for the lower bound (here (0,0)), gives the values I need: let (a,b) = (2,3) index ((0,0),(a-1,b-1)) [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)] However, I need the results as a list of lists rather than a list of tuples; and my input is a list of integral values. I ended up writing the following function instead. The function isn't long, but longer than I first expected. Did I miss a simpler approach? iota :: (Integral a) = [a] - [[a]] iota is = let count = product is tups = zip (tail $ scanr (*) 1 is) is buildRepList (r,i) = genericTake count $ cycle $ [0..i-1] = genericReplicate r lists = map buildRepList tups in transpose lists length $ iota [2,3,4] 24 Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] problem with inf-haskell + ghci?
Hello all I recently found strange problem in use of inf-haskell + ghci on my Mac OS X Tyger. I haven't used inf-haskell for a some time, and several days ago i found, that it stopped to work - when I run C-c C-l (load file) it signal error, and when I perform C-c C-b (start interpreter) it load it, but entering of any text in it, leads to message: Leaving GHCi. Process haskell finished In terminal ghci works fine, but I couldn't find why ghci terminates when it called from Emacs. May be somebody had such problem with ghci? P.S. I use Carbon Emacs 22 + ghc 6.10.1 installed from macports -- With best wishes, Alex Ott, MBA http://alexott.blogspot.com/http://xtalk.msk.su/~ott/ http://alexott-ru.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bool as type class to serve EDSLs.
On Jun 1, 2009, at 12:17 AM, Henning Thielemann wrote: On Thu, 28 May 2009, Bulat Ziganshin wrote: i use another approach which imho is somewhat closer to interpretation of logical operations in dynamic languages (lua, ruby, perl): [...] The absence of such interpretations and thus the increased type safety was one of the major the reasons for me to move from scripting languages to Haskell. Do you argue that overloading logical operations like this in Haskell sacrifices type safety? Could programs go wrong [1] that use such abstractions? [1]: Robin Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17:348–375, 1978. -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] iota
The iota function you're looking for can be a whole lot simpler if you know about monads (list monad in particular) and sequence. For lists, sequence has the following behaviour: sequence [xs1,xs2, ... xsn] = [[x1,x2, ... , xn] | x1 - xs1, x2 - xs2, ... , xn - xsn] Using this, you can reduce your iota function to a powerful one-liner: iota = sequence . map (enumFromTo 0 . pred) Kind regards, Raynor Vliegendhart On 6/1/09, Paul Keir pk...@dcs.gla.ac.uk wrote: Hi all, I was looking for an APL-style “iota” function for array indices. I noticed “range” from Data.Ix which, with a zero for the lower bound (here (0,0)), gives the values I need: let (a,b) = (2,3) index ((0,0),(a-1,b-1)) [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)] However, I need the results as a list of lists rather than a list of tuples; and my input is a list of integral values. I ended up writing the following function instead. The function isn’t long, but longer than I first expected. Did I miss a simpler approach? iota :: (Integral a) = [a] - [[a]] iota is = let count = product is tups = zip (tail $ scanr (*) 1 is) is buildRepList (r,i) = genericTake count $ cycle $ [0..i-1] = genericReplicate r lists = map buildRepList tups in transpose lists length $ iota [2,3,4] 24 Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: iota
That is quite spectacular. I revised my knowledge of sequence with a little function, akin to sequence [xs1,xs2]: seq2 xs1 xs2 = do x1 - xs1 x2 - xs2 return [x1,x2] seq2 [0,1] [0,1,2] [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2]] I like your point-free style too; and that's a nice use of pred. Many thanks, Paul The iota function you're looking for can be a whole lot simpler if you know about monads (list monad in particular) and sequence. For lists, sequence has the following behaviour: sequence [xs1,xs2, ... xsn] = [[x1,x2, ... , xn] | x1 - xs1, x2 - xs2, ... , xn - xsn] Using this, you can reduce your iota function to a powerful one-liner: iota = sequence . map (enumFromTo 0 . pred) Kind regards, Raynor Vliegendhart From: Paul Keir Sent: 01 June 2009 10:01 To: haskell-cafe@haskell.org Subject: iota Hi all, I was looking for an APL-style iota function for array indices. I noticed range from Data.Ix which, with a zero for the lower bound (here (0,0)), gives the values I need: let (a,b) = (2,3) index ((0,0),(a-1,b-1)) [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)] However, I need the results as a list of lists rather than a list of tuples; and my input is a list of integral values. I ended up writing the following function instead. The function isn't long, but longer than I first expected. Did I miss a simpler approach? iota :: (Integral a) = [a] - [[a]] iota is = let count = product is tups = zip (tail $ scanr (*) 1 is) is buildRepList (r,i) = genericTake count $ cycle $ [0..i-1] = genericReplicate r lists = map buildRepList tups in transpose lists length $ iota [2,3,4] 24 Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GUI and background processing
Greetings, fellow haskellers. Currently I'm writing some kind of web crawler in haskell with gtk2hs gui. All network operations are run in separate thread, but sometimes input from user is needed. Afaik, gtk2hs is not thread safe, so I came up with following: I create two mvars, A and B, one for question, one for answer. Worker thread puts question in A and blocks trying to take B. Gui thread checks for question by polling with tryTakeMVar. Then question is ready, it asks user and puts his answer into B. Worker awakens and continues processing. Also, for progress report, I use a Chan which is written to by worker and is read by polling by gui thread. This scheme works, but I don't like it. All these mvars and chans create too much clutter, and polling looks rather ugly too. Is there a better way for implementing similar patterns of interaction? Best regards, Dmitry. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GUI and background processing
Hello Dmitry, Monday, June 1, 2009, 4:24:36 PM, you wrote: All network operations are run in separate thread, but sometimes input from user is needed. Afaik, gtk2hs is not thread safe, so I came up with look for postGUISync and postGUIASync -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Trouble with types
Hi, I tried this code: --- f, g :: a - a (f, g) = (id, id) --- Hugs: OK GHC: Couldn't match expected type `forall a. a - a' against inferred type `a - a' In the expression: id In the expression: (id, id) In a pattern binding: (f, g) = (id, id) What does mean this error message? And what of them (Hugs, GHC) is correct? Thanks Vladimir ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble with types
Am Montag 01 Juni 2009 14:44:37 schrieb Vladimir Reshetnikov: Hi, I tried this code: --- f, g :: a - a (f, g) = (id, id) --- Hugs: OK GHC: Couldn't match expected type `forall a. a - a' against inferred type `a - a' In the expression: id In the expression: (id, id) In a pattern binding: (f, g) = (id, id) What does mean this error message? And what of them (Hugs, GHC) is correct? http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs-and-infelicities.html Section 12.1.1.4, Declarations and bindings GHC's typechecker makes all pattern bindings monomorphic by default; this behaviour can be disabled with -XNoMonoPatBinds. See Section 7.1, “Language options”. Hugs is correct, it's a known infelicity in GHC which can be disabled. Thanks Vladimir ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bool as type class to serve EDSLs.
On Mon, Jun 1, 2009 at 3:06 AM, Sebastian Fischer s...@informatik.uni-kiel.de wrote: On Jun 1, 2009, at 12:17 AM, Henning Thielemann wrote: On Thu, 28 May 2009, Bulat Ziganshin wrote: i use another approach which imho is somewhat closer to interpretation of logical operations in dynamic languages (lua, ruby, perl): [...] The absence of such interpretations and thus the increased type safety was one of the major the reasons for me to move from scripting languages to Haskell. Do you argue that overloading logical operations like this in Haskell sacrifices type safety? Could programs go wrong [1] that use such abstractions? If I understand your point correctly, you are suggesting that such programs are still type safe. I agree with the claim that such features are detrimental in practice though. Instead of lumping it with type safety, then what do we call it? I think I've heard of languages that do such conversions as weakly typed. Really the issue is with implicit conversions, right? Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing a Deriving?
I went back and tried to convert the YAHT example to Monad, importing Monad, commenting out all but the data descriptions and the searchAll function, and finally replacing success, failure, augment, and combine in the searchAll function with return, fail, =, and mplus. *Main let g = Graph [(1,'a'),(2,'b'),(3,'c'),(4,'d')] [(1,2,'p'),(2,3,'q'),(1,4,'r'),(4,3,'s')] *Main searchAll g 1 3 :: [[Int]] [[1,2,3],[1,4,3]] *Main searchAll g 1 3 :: Maybe [Int] Just [1,2,3] *Main searchAll g 3 1 :: Maybe [Int] Nothing *Main searchAll g 3 1 :: [[Int]] [] All good so far, but then tried to convert Failable from Computation to Monad instance Monad Failable where return = Success fail = Fail = (Success x) f = f x = (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x and got the following error. Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:34:4: parse error on input `=' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail = (Success x) f = f x = (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to implement this? A case for scoped record labels?
On Sun, May 31, 2009 at 06:20:23PM -0700, Iavor Diatchki wrote: and so on. It is a bit verbose, but you only have to do it once for your protocol, and then you get the nice overloaded interface. This also seems like the kind of thing perfectly suited to Template Haskell. Especially if the records might end up being modified, fields added, etc., having some TH code to regenerate all the necessary classes and instances from some compact description could be a big win, and probably not too hard to code either. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] MySQL, CouchDB, and Haskell
Dear Group, I've spent the last few days trying to convert a bunch of mysql tables into couchdb using haskell, and I've documented my efforts, in case anyone else intends to wander in similar waters. The tutorial is at: http://maztravel.com/haskell/mySqlToCouchDB.html comments welcome here at the list or to me privately at nadine.and.henry -AT- pobox.com Best wishes, Henry Laxen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing a Deriving?
Am Montag 01 Juni 2009 19:02:36 schrieb michael rice: All good so far, but then tried to convert Failable from Computation to Monad instance Monad Failable where return = Success fail = Fail = (Success x) f = f x = (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x and got the following error. Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:34:4: parse error on input `=' Failed, modules loaded: none. Prelude When you use an operator in prefix position, you must enclose it in parentheses, like you must enclose a function in backticks if you use it infix. So the definition of (=) should read (=) (Success x) f = f x (=) (Fail s) _ = Fail s or, defining it in infix position, (Success x) = f = f x (Fail s) = _ = Fail s Complete code follows. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bool as type class to serve EDSLs.
Do you argue that overloading logical operations like this in Haskell sacrifices type safety? Could programs go wrong [1] that use such abstractions? If I understand your point correctly, you are suggesting that such programs are still type safe. I agree with the claim that such features are detrimental in practice though. Instead of lumping it with type safety, then what do we call it? I think I've heard of languages that do such conversions as weakly typed. Really the issue is with implicit conversions, right? Isn't it merely a matter of balance? In order for typed programs not to go wrong, one has to define right and wrong, and devise a type system that rules out anything that might go wrong, usually at the expense of some programs that might go right. Advanced type system features like overloading take that unused space and devise ways to redirect code that would go wrong (in simpler systems) to go right in useful new ways (eg: adding two functions or matrices or .. does not have to be wrong, there are interpretations in which all of these make perfect sense, and Haskell can express many of them). What is happening then is that more and more of the previously wrong space is filled up with meaningful ways of going right, until nearly every syntactically valid program goes somewhere. That can make for an extremely expressive and powerful language, but it renders the naive notion of going wrong or right rather meaningless: wrong just means we haven't figured out a meaningful way to interpret it, and going right can easily be a far cry from where you wanted it to go. Claus PS. this problem can be made worse if the implicit conversions aren't consistent, if small twitches in source code can lead to grossly different behaviour. There is a fine line between advanced and uncontrollable, and opinions on what side of the line any given definition is on can differ. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: new version of uu-parsinglib
And rename empty to fail? You managed to confuse me since I always use pSucceed to recognise the empty string. Doaitse On 1 jun 2009, at 01:21, Ross Paterson wrote: On Sun, May 31, 2009 at 09:40:38PM +0200, S. Doaitse Swierstra wrote: A new version of the uu-parsinglib has been uploaded to hackage. It is now based on Control.Applicative where possible. Be warned that functions like some and many will be redefined in the future. Perhaps we should make some and many methods of Alternative, * and * methods of Applicative and $ a method of Functor, all with the current definitions as defaults. (John Meacham was also asking for the first of these.) ___ 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] Re: Error message reform (was: Strange type errorwith associated type synonyms)
I once thought, that error messages must be configurable by libraries, too. This would be perfect for EDSLs that shall be used by non-Haskellers. Yes, that is a problem. But I have no idea how to design that. There was some work in that direction in the context of the Helium project. See the publication lists of Bastiaan Heeren and Jurriaan Hage: http://people.cs.uu.nl/bastiaan/#Publications http://www.cs.uu.nl/research/techreps/aut/jur.html Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing a Deriving?
Got it. Thanks! Michael --- On Mon, 6/1/09, Daniel Fischer daniel.is.fisc...@web.de wrote: From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-cafe] Missing a Deriving? To: haskell-cafe@haskell.org Date: Monday, June 1, 2009, 1:51 PM Am Montag 01 Juni 2009 19:02:36 schrieb michael rice: All good so far, but then tried to convert Failable from Computation to Monad instance Monad Failable where return = Success fail = Fail = (Success x) f = f x = (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x and got the following error. Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:34:4: parse error on input `=' Failed, modules loaded: none. Prelude When you use an operator in prefix position, you must enclose it in parentheses, like you must enclose a function in backticks if you use it infix. So the definition of (=) should read (=) (Success x) f = f x (=) (Fail s) _ = Fail s or, defining it in infix position, (Success x) = f = f x (Fail s) = _ = Fail s Complete code follows. Michael ___ 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] Bool as type class to serve EDSLs.
Do you argue that overloading logical operations like this in Haskell sacrifices type safety? Could programs go wrong [1] that use such abstractions? If I understand your point correctly, you are suggesting that such programs are still type safe. My asking was really meant as a question to find out what Henning meant when he talked about type safety. I agree with the claim that such features are detrimental in practice though. I also feel uncomfortable about such features, but the problem seems to be different from type safety. Maybe it is more about predictability. For example, if '1 + 23 = 24' and '1 + 23 = 123' this can lead to confusion although using overloading this could be done in Haskell. That the compiler is able to figure out a correct instantiation of an overloaded operation does not mean that it is easy for the programmer too. And if it is not, programs are hard to understand. Instead of lumping it with type safety, then what do we call it? I think I've heard of languages that do such conversions as weakly typed. Really the issue is with implicit conversions, right? Isn't it merely a matter of balance? In order for typed programs not to go wrong, one has to define right and wrong, and devise a type system that rules out anything that might go wrong, usually at the expense of some programs that might go right. I had in mind causes a run-time error as definition of goes wrong. But this simple view may well be inaccurate. Advanced type system features like overloading take that unused space and devise ways to redirect code that would go wrong (in simpler systems) to go right in useful new ways (eg: adding two functions or matrices or .. does not have to be wrong, there are interpretations in which all of these make perfect sense, and Haskell can express many of them). What is happening then is that more and more of the previously wrong space is filled up with meaningful ways of going right, until nearly every syntactically valid program goes somewhere. That can make for an extremely expressive and powerful language, but it renders the naive notion of going wrong or right rather meaningless: wrong just means we haven't figured out a meaningful way to interpret it, and going right can easily be a far cry from where you wanted it to go. I (think I) agree with you. Overloading could give a meaning to almost everything. Not necessarily a sensible one, and judgements about what is sensible seem to differ among different people. Regardless of whether a specific overloading is *sensible*, wanting it to be *predictable* seems like a reasonable requirement which may be easier to agree on. Cheers, Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Checking a value against a passed-in constructor?
Hi, (Relatively new to Haskell here ..) So I have the following: data MyVal = Atom String | Bool Bool And I want to do something like this check :: (Bool - MyVal) - MyVal - True check f (f x) = True check _ _ = False What that means is I want to pass a MyVal constructor and a MyVal, and return True if the second argument was constructed with the first. More generally, I'd like to be able to do genCheck :: (* - MyVal) - MyVal - True genCheck f (f x) = True genCheck _ _ = False So that I can pass in _any_ MyVal constructor and let the function just check if the second argument was constructed with the first, without caring which constructor it is. What is the preferred way to do this, since neither of those functions compile? Cheers, - Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Checking a value against a passed-in constructor?
Hi Dan, On Mon, Jun 1, 2009 at 8:39 PM, Dan Cook danielkc...@gmail.com wrote: Hi, (Relatively new to Haskell here ..) So I have the following: data MyVal = Atom String | Bool Bool And I want to do something like this check :: (Bool - MyVal) - MyVal - True check f (f x) = True check _ _ = False You may be confusing yourself here on one point. The type 'Bool' is already defined by the prelude, but the data constructor is not. So you are able to create a data constructor for MyVal that is called Bool and contains a Bool. I think this distinction is leading to the next probem I see. Type signatures have to contain types and not values in Haskell. 'True' is a value so it can't be placed in the type signature. The type of True is Bool. So I think you meant to ask about: check :: (Bool - MyVal) - MyVal - Bool Now if you define this function the first parameter can be any function Bool - MyVal, not just the data constructors of MyVal. Also, the type of Atom :: String - MyVal so you can't even pass it to 'check'. What that means is I want to pass a MyVal constructor and a MyVal, and return True if the second argument was constructed with the first. More generally, I'd like to be able to do genCheck :: (* - MyVal) - MyVal - True genCheck f (f x) = True genCheck _ _ = False So that I can pass in _any_ MyVal constructor and let the function just check if the second argument was constructed with the first, without caring which constructor it is. This strikes me as a job for template haskell, but the use of TH is beyond what I can explain :) What is the preferred way to do this, since neither of those functions compile? My preferred way, is just to define isAtom and isBool both with type MyVal - Bool and use them where I need them. There are a number of tools to generate such things like DrIFT, TH, and maybe some others? I hope that helps, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing a Deriving?
Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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] Missing a Deriving?
mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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] Missing a Deriving?
Hi Ross, I thought of that, but return, fail, and = became not visible when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and =) and one for MonadPlus (giving it mplus)? Michael --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:33 PM mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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] Missing a Deriving?
Oh I wasn't clear -- you need multiple instance declarations for a given type (Failable, for example), one for each type class you're implementing. That is, instance Monad Failable where return = ... ... instance MonadPlus Failable where mplus = ... ... -Ross On Jun 1, 2009, at 9:40 PM, michael rice wrote: Hi Ross, I thought of that, but return, fail, and = became not visible when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and =) and one for MonadPlus (giving it mplus)? Michael --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:33 PM mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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] Missing a Deriving?
I didn't know I could do that. Works fine. Output below. Thanks! This is some pretty neat stuff, and I've only scratched the surface. Michael === [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:37:9: Warning: No explicit method nor default method for `mzero' In the instance declaration for `MonadPlus Failable' Ok, modules loaded: Main. *Main let g = Graph [(1,'a'),(2,'b'),(3,'c'),(4,'d')] [(1,2,'p'),(2,3,'q'),(1,4,'r'),(4,3,'s')] *Main searchAll g 1 3 :: Failable [Int] Success [1,2,3] *Main searchAll g 3 1 :: Failable [Int] Fail no path *Main searchAll g 1 3 :: Maybe [Int] Just [1,2,3] *Main searchAll g 3 1 :: Maybe [Int] Nothing *Main searchAll g 1 3 :: [[Int]] [[1,2,3],[1,4,3]] *Main searchAll g 3 1 :: [[Int]] [] *Main --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:43 PM Oh I wasn't clear -- you need multiple instance declarations for a given type (Failable, for example), one for each type class you're implementing. That is, instance Monad Failable where return = ... ... instance MonadPlus Failable where mplus = ... ... -Ross On Jun 1, 2009, at 9:40 PM, michael rice wrote: Hi Ross, I thought of that, but return, fail, and = became not visible when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and =) and one for MonadPlus (giving it mplus)? Michael --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:33 PM mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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] Missing a Deriving?
graph5.hs:37:9: Warning: No explicit method nor default method for `mzero' In the instance declaration for `MonadPlus Failable' This warning is saying you didn't finish the declaration. Try something like instance MonadPlus Failable where mplus (Fail _) y = y mplus x _ = x mzero = Fail mzero Also, I'd use import Control.Monad instead of import Monad. -- ryan On Mon, Jun 1, 2009 at 7:03 PM, michael rice nowg...@yahoo.com wrote: I didn't know I could do that. Works fine. Output below. Thanks! This is some pretty neat stuff, and I've only scratched the surface. Michael === [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:37:9: Warning: No explicit method nor default method for `mzero' In the instance declaration for `MonadPlus Failable' Ok, modules loaded: Main. *Main let g = Graph [(1,'a'),(2,'b'),(3,'c'),(4,'d')] [(1,2,'p'),(2,3,'q'),(1,4,'r'),(4,3,'s')] *Main searchAll g 1 3 :: Failable [Int] Success [1,2,3] *Main searchAll g 3 1 :: Failable [Int] Fail no path *Main searchAll g 1 3 :: Maybe [Int] Just [1,2,3] *Main searchAll g 3 1 :: Maybe [Int] Nothing *Main searchAll g 1 3 :: [[Int]] [[1,2,3],[1,4,3]] *Main searchAll g 3 1 :: [[Int]] [] *Main --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:43 PM Oh I wasn't clear -- you need multiple instance declarations for a given type (Failable, for example), one for each type class you're implementing. That is, instance Monad Failable where return = ... ... instance MonadPlus Failable where mplus = ... ... -Ross On Jun 1, 2009, at 9:40 PM, michael rice wrote: Hi Ross, I thought of that, but return, fail, and = became not visible when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and =) and one for MonadPlus (giving it mplus)? Michael --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:33 PM mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus`
Re: [Haskell-cafe] Checking a value against a passed-in constructor?
On 2 Jun 2009, at 3:39 pm, Dan Cook wrote: Hi, (Relatively new to Haskell here ..) So I have the following: data MyVal = Atom String | Bool Bool And I want to do something like this check :: (Bool - MyVal) - MyVal - True check f (f x) = True check _ _ = False What that means is I want to pass a MyVal constructor and a MyVal, and return True if the second argument was constructed with the first. Yeek. Why do you want to do _that_? You could quite easily determine whether two values were constructed with the _same_ constructor: check (Atom _) (Atom _) = True check (Bool _) (Bool _) = True check __= False and instead of passing in a constructor pass in an example of a term constructed by that constructor. So instead of check Atom foo, do check (Atom undefined) foo instead of check Bool bar, do check (Bool undefined) bar Another approach is to write a boolean function for each constructor, e.g., is_atom (Atom _) = True is_atom _= False is_bool (Bool _) = True is_bool _= False and pass one of these instead of a constructor: check :: (MyVal - Bool) - MyVal - Bool check f x = f x which makes the check function itself pointless. More generally, I'd like to be able to do genCheck :: (* - MyVal) - MyVal - True genCheck f (f x) = True genCheck _ _ = False So that I can pass in _any_ MyVal constructor and let the function just check if the second argument was constructed with the first, without caring which constructor it is. There are some very high-powered things you can do in Haskell these days which would let you get closer to this than most people would be happy reading. We can use the same idea of passing an example. So given data Biffo x y z = Ping x | Pong y z | Pang x y z you can easily write check (Ping _) (Ping _) = True check (Pong _ _) (Pong _ _) = True check (Pang _ _ _) (Pang _ _ _) = True check __= False called as check (Ping undefined) foo or check (Pong undefined undefined) bar or check (Pang undefined undefined undefined) or much better, go the Boolean function route: is_ping (Ping _) = True is_ping _= False is_pong (Pong _ _) = True is_pong _ = False is_pang (Pang _ _ _) = True is_pang _= False and use one of these functions whenever you want something you can use to check for a particular constructor. There are various meta-programming (Scrap Your Boilerplate, Template Haskell) approaches you can use to automate some of these. The first step is the step backwards where you ask why am I trying to do this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Possible Haskell Project
My family and I are moving in the coming months. My wife will be attending a new school in the fall. Among the many hassles of moving are locating and transferring medical records to new doctors and clinics. During our time in Minnesota, we've visited several clinics and hospitals, so our medical data is spread across a dozen different networks. Collecting this data is a chore. And reciting it to every new medical provider is frustrating, especially knowing someone else has already typed this stuff into the computer. For obvious reasons, there are many software companies competing in the Electronic Health Record (EHR) industry. I haven't spent much time researching the field, but I have to imagine there is no shortage of bloated standards and next to nil interoperability. With President Obama pushing for electronic health records, this could be an opportunity for the Haskell community to deliver a common framework that the US, and maybe the rest of the world, could build upon -- a longshot I realize. At the core, the fundamental problem is not that complicated. It's just storing and retrieving a person's various health events: checkups, prescriptions, procedures, test results, etc. The main technical challenges are database distribution and patient security. Both are fun problems, and our friends at Galios continue to show how effective Haskell is at building secure systems. Any thoughts? Ideas? -Tom BTW, Anyone looking to rent a house in Eden Prairie, MN? A Haskell employer is just 4 miles down the road (Eaton). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Possible Haskell Project
On Mon, Jun 1, 2009 at 11:18 PM, Tom Hawkins tomahawk...@gmail.com wrote: My family and I are moving in the coming months. My wife will be attending a new school in the fall. Among the many hassles of moving are locating and transferring medical records to new doctors and clinics. During our time in Minnesota, we've visited several clinics and hospitals, so our medical data is spread across a dozen different networks. Collecting this data is a chore. And reciting it to every new medical provider is frustrating, especially knowing someone else has already typed this stuff into the computer. For obvious reasons, there are many software companies competing in the Electronic Health Record (EHR) industry. I haven't spent much time researching the field, but I have to imagine there is no shortage of bloated standards and next to nil interoperability. With President Obama pushing for electronic health records, this could be an opportunity for the Haskell community to deliver a common framework that the US, and maybe the rest of the world, could build upon -- a longshot I realize. At the core, the fundamental problem is not that complicated. It's just storing and retrieving a person's various health events: checkups, prescriptions, procedures, test results, etc. The main technical challenges are database distribution and patient security. Both are fun problems, and our friends at Galios continue to show how effective Haskell is at building secure systems. Any thoughts? Ideas? -Tom A good place to start is http://en.wikipedia.org/wiki/HL7 , which is a not-for-profit organization which tries to define interfacing standards between medical devices and medical records providers. I haven't worked much with their standards so I don't know how useful they'd be. I think they might be geared towards vendor-to-vendor interop. As for the legacy of people who thought it wasn't complex: http://histalk.blog-city.com/guest_article__repeat_after_me_healthcare_data_models_matter.htm I don't agree with everything the guy wrote, but it's an interesting article. As for knowing how to use the data once you've got it, there were some recent news articles about the Google personal-health-record (PHR) importing billing codes and trying to use them to reconstruct a clinical history to not-so-great effect. And I would say that the security problem is more than a technical problem - the big security issue in medical record interchange is privacy. What data can flow between healthcare organizations? What information can individual organizations restrict access to? How can we get the patient's input in how their data can move between healthcare organizations? Should we? And how should data move to organizations that are both providers and payors? Does it matter? Maybe I'm drifting a bit far afield from Haskell ... Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble with types
Hi Daniel, Could you please explain what does mean 'monomorphic' in this context? I thought that all type variables in Haskell are implicitly universally quantified, so (a - a) is the same type as (forall a. a - a) Thank you, Vladimir On 6/1/09, Daniel Fischer daniel.is.fisc...@web.de wrote: Am Montag 01 Juni 2009 14:44:37 schrieb Vladimir Reshetnikov: Hi, I tried this code: --- f, g :: a - a (f, g) = (id, id) --- Hugs: OK GHC: Couldn't match expected type `forall a. a - a' against inferred type `a - a' In the expression: id In the expression: (id, id) In a pattern binding: (f, g) = (id, id) What does mean this error message? And what of them (Hugs, GHC) is correct? http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs-and-infelicities.html Section 12.1.1.4, Declarations and bindings GHC's typechecker makes all pattern bindings monomorphic by default; this behaviour can be disabled with -XNoMonoPatBinds. See Section 7.1, “Language options”. Hugs is correct, it's a known infelicity in GHC which can be disabled. Thanks Vladimir ___ 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