[Haskell-cafe] Can't use libraries in haskell
Hello, I'm new in haskell. I want to use xml library (http://hackage.haskell.org/package/xml) in my project. I downloaded it.then try to build and install: runhaskell Setup.hs configure runhaskell Setup.hs build runhaskell Setup.hs install All ok. There are no errors. When i try import modules from this lib to my project, for example: import Text.XML.Light.Cursor I get error: /home/shk/dev/src/XMPP.hs:8:8: Could not find module `Text.XML.Light.Cursor': Use -v to see a list of the files searched for. Failed, modules loaded: none. if i try: > cabal install xml Resolving dependencies... No packages to be installed. All the requested packages are already installed. If you want to reinstall anyway then use the --reinstall flag. What's wrong? How can i install and use library in haskell? Thank you. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is a "simple pattern binding"?
At Sun, 26 Jun 2011 01:41:01 +0100, Paterson, Ross wrote: > > > I thought "no type signature" meant no type signature inside b1. > > No, it means no type signature for the variable. > > > Otherwise, you are saying nothing could depend on a binding with a > > type signature. By that logic, there can be no mutual dependence, > > and so every declaration with a type signature is its own (singleton) > > declaration group. > > A pattern binding can bind more than one variable. If all the variables > bound by a binding have type signatures, that binding is indeed a > singleton declaration group. If this is the case, then multiple sentences in the 2010 report don't make sense, though the way in which they don't make sense sort of depends on what "simple pattern binding" means. Which of the following constitute a simple pattern binding? a. a | False = undefined | otherwise = \x -> x b. Just b = Just (\x -> x) c. Just c | False = undefined | otherwise = Just (\x -> x) d. (d, d') = (\x -> x, d) e. (e, e') | False = undefined | otherwise = (\x -> x, e) If it's any clue, GHC infers a polymorphic type for a only. It infers type "GHC.Prim.Any -> GHC.Prim.Any" for the others. Moreover, GHC accepts the type signature "a :: t -> t", but rejects such a polymorphic signature for the other variables, and also rejects programs such as: Just b = Just (\x -> x) f :: (Show a) => a -> a f = b -- illegal So let's work under the assumption that a is a simple pattern binding, and the others are not. If you have a different definition, I'll make a different argument. (Note also that if you agree with this definition, then there is a bug in section 4.4.3.2 of the report, since a is not of the form "p = e". But if you take the 4.4.3.2 definition, then I'll argue section 4.5.5 has a bug.) Let's posit a definition that accepts only a (and in particular that rejects d and e). Such a definition is further supported by the phrase "a simple pattern binding is a pattern binding in which the pattern consists of only a single variable" (from section 4.5.5). If we accept that a simple pattern binding cannot bind more than one variable, then the definition of the monomorphism restriction in section 4.5.5 is not consistent with your interpretation of the term declaration group. After all, given our posited definition, the following language in 4.5.5: (a): every variable in the group is bound by a function binding or a simple pattern binding (Section 4.4.3.2), and (b): an explicit type signature is given for every variable in the group that is bound by simple pattern binding. should instead read: (a): every binding is a function binding, or (b): the group consists of a simple pattern binding with an explicit type signature. In particular, why would the report say "an explicit type signature is given for EVERY variable" when there can be only one such variable? David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Time
I've tended to use the attached module. It is basic, but has covered my needs. It probably has many issues (bugs, inefficiencies, naming conventions, etc) but has been sufficient so far. Developed by myself a few years ago, under no particular licence - happy for reuse or for someone to take it and package it up under cabal if it is useful or maybe even better for someone to suggest a simple alternative. cheers, Joe > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > I recently set out to write a library that required a decent time > library. Having only had a flirt with Data.Time previously, I assumed > it would be robust like many other haskell libraries. I don't know > about consensus, but I have been massively let down. I won't go in to > the details, since this is not the point -- I don't wish to complain > - -- I wish to get on with it. > > So, assuming the consensus is in agreement, is there a reasonable > alternative to Data.Time (I looked on hackage and nothing seemed to > have come close)? Am I wrong in assuming Data.Time is pretty useless? > > If I am right, and there is no alternative, I see no option but to > take an excursion into writing my own. Ultimately, I am just trying to > avoid this. Tips welcome. > > - -- > Tony Morris > http://tmorris.net/ > > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAk4Ggx4ACgkQmnpgrYe6r61BRQCfbn+1jqNSjR+lxM+4h3gpvAMM > VskAoKxqDCETyVAaOdoYDmFJGz1fOGd/ > =IC7O > -END PGP SIGNATURE- > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > --module Dates (datetime, sixNum, hours, minutes, seconds, -- yearPart, monthPart, dayPart, -- hourPart, minutePart, secondPart, dateFromString, -- dateSub, dateAdd, Date, TimeSpan, fromNum, toNum, hms) where module Dates where data Date = Date Int Int deriving (Eq, Ord) data TimeSpan = TimeSpan Int deriving (Show, Eq, Ord) instance Show Date where show = toString instance Enum Date where pred (Date d s) = Date (d-1) s succ (Date d s) = Date (d+1) s toEnum d = Date d 0 fromEnum (Date d _) = d enumFrom d = (d:(enumFrom (succ d))) enumFromThen a b = (a:(enumFromThen b (dateAdd b (dateSub b a enumFromThenTo a b c = takeWhile (<= c) (enumFromThen a b) isLeapYear :: Int -> Bool isLeapYear x | x `mod` 400 == 0 = True | x `mod` 100 == 0 = False | x `mod` 4 == 0 = True | otherwise= False daysInMonth :: Int -> Int -> Int daysInMonth _ 1 = 31 daysInMonth y 2 | isLeapYear y = 29 | otherwise= 28 daysInMonth _ 3 = 31 daysInMonth _ 4 = 30 daysInMonth _ 5 = 31 daysInMonth _ 6 = 30 daysInMonth _ 7 = 31 daysInMonth _ 8 = 31 daysInMonth _ 9 = 30 daysInMonth _ 10 = 31 daysInMonth _ 11 = 30 daysInMonth _ 12 = 31 daysInMonth _ x = 0 daysInYear x | isLeapYear x = 366 | otherwise= 365 normalize :: Date -> Date normalize (Date days seconds) = (Date (days + sdays) sseconds) where sdays = seconds `div` 86400 sseconds = seconds `mod` 86400 baseYear = 2000 datetime :: Int -> Int -> Int -> Int -> Int -> Int -> Date datetime y m d h minute s = (Date days seconds) where days = yearDays + monthDays + d - 1 yearDays = sum [daysInYear x | x <- [baseYear..(y-1)]] monthDays = sum [(daysInMonth y x) | x <- [1..(m-1)]] seconds = h * 3600 + minute * 60 + s toString d = concat [(p 4 year), "-", (p 2 month), "-", (p 2 day), " ", (p 2 hour), ":", (p 2 minute), ":", (p 2 second)] where (year, month, day, hour, minute, second) = sixNum d p x v = pad (show v) x dateFromString s = datetime (read year) (read month) (read day) (read hour) (read minute) (read second) where (dpart:tpart:xs) = split s ' ' (year:month:day:[]) = split dpart '-' (hour:minute:second:[]) = split tpart ':' toNum d = x where (TimeSpan x) = dateSub d (datetime 2000 1 1 0 0 0) fromNum d = dateAdd (datetime 2000 1 1 0 0 0) (TimeSpan d) sixNum d = (year, month, mdaysRemaining, hour, minute, second) where (Date days seconds) = normalize d (year, ydaysBefore) = yearOf days ydaysRemaining = days - ydaysBefore (month, mdaysBefore) = monthOf year ydaysRemaining mdaysRemaining = ydaysRemaining - mdaysBefore + 1 hour = seconds `div` 3600 minute = (seconds `mod` 3600) `div` 60 second = seconds - (hour * 3600) - (minute * 60) yearPart d = x where (x, _, _, _, _, _) = sixNum d monthPart d = x where (_, x, _, _, _, _) = sixNum d dayPart d = x where (_, _, x, _, _, _) = sixNum d hourPart d = x where (_, _, _, x, _, _) = sixNum d minutePar
[Haskell-cafe] Data.Time
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I recently set out to write a library that required a decent time library. Having only had a flirt with Data.Time previously, I assumed it would be robust like many other haskell libraries. I don't know about consensus, but I have been massively let down. I won't go in to the details, since this is not the point -- I don't wish to complain - -- I wish to get on with it. So, assuming the consensus is in agreement, is there a reasonable alternative to Data.Time (I looked on hackage and nothing seemed to have come close)? Am I wrong in assuming Data.Time is pretty useless? If I am right, and there is no alternative, I see no option but to take an excursion into writing my own. Ultimately, I am just trying to avoid this. Tips welcome. - -- Tony Morris http://tmorris.net/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4Ggx4ACgkQmnpgrYe6r61BRQCfbn+1jqNSjR+lxM+4h3gpvAMM VskAoKxqDCETyVAaOdoYDmFJGz1fOGd/ =IC7O -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is a "simple pattern binding"?
> I thought "no type signature" meant no type signature inside b1. No, it means no type signature for the variable. > Otherwise, you are saying nothing could depend on a binding with a > type signature. By that logic, there can be no mutual dependence, > and so every declaration with a type signature is its own (singleton) > declaration group. A pattern binding can bind more than one variable. If all the variables bound by a binding have type signatures, that binding is indeed a singleton declaration group. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is a "simple pattern binding"?
At Sun, 26 Jun 2011 00:17:12 +0100, Paterson, Ross wrote: > > > > > g1 x y z = if x>y then show x ++ show z else g2 y x > > > > > > > > g2 :: (Show a, Ord a) => a -> a -> String > > > > g2 | False = \p q -> g1 q p () > > > >| otherwise = \p q -> g1 q p 'a' > > > >where x = True > > > > > > It appears to me that GHC is justified. According to 4.5.1 and 4.5.2, g1 > > > by itself constitutes a declaration group. It is considered by itself > > > and is generalized prior to combining it with g2. > > > Great, now I'm even more confused. 4.5.1 says: > > > A binding b1 depends on a binding b2 in the same list of > > declarations if either > > > 1. b1 contains a free identifier that has no type signature > > and is bound by b2, or > > > 2. b1 depends on a binding that depends on b2. > > > A declaration group is a minimal set of mutually dependent > > bindings. Hindley-Milner type inference is applied to each > > declaration group in dependency order. > > > So here the first binding (of g1) contains the free identifier g2, > > which is bound by the second binding. Conversely, the second binding > > contains g1 free. So the two bindings are mutually dependent, no? > > No, the binding of g1 doesn't depend on the binding of g2, because g2 > has a type signature (clause 1). I thought "no type signature" meant no type signature inside b1. Otherwise, you are saying nothing could depend on a binding with a type signature. By that logic, there can be no mutual dependence, and so every declaration with a type signature is its own (singleton) declaration group. But this can't be what the committee was thinking given the following language in section 4.5.2: If the programmer supplies explicit type signatures for more than one variable in a declaration group, the contexts of these signatures must be identical up to renaming of the type variables. Such a restriction would be vacuous if every type signature created a singleton declaration groups. Moreover, section 4.5.5 is also inconsistent with such an interpretation: The monomorphism restriction Rule 1. We say that a given declaration group is unrestricted if and only if: (a): every variable in the group is bound by a function binding or a simple pattern binding (Section 4.4.3.2), and (b): an explicit type signature is given for every variable in the group that is bound by simple pattern binding. If every binding with an explicit type signature is its own declaration group, then why isn't the monomorphism restriction stated more simply as follows? (a): every binding is a function binding, or (b): the group consists of a pattern binding with an explicit type signature. When they say "an explicit type signature is given for every variable in the group..." they have to be thinking there may be more than one of them. > The type of g1 is inferred using the declared type of g2. Then that > type is used in inferring a type for g2, which will be compared with > its declared signature. Thanks for the reply, but now I'm now even more confused. Perhaps I should ask if someone can give me a better definition of declaration group, ideally with support in the language spec... David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Iteratee IO examples
On Sat, Jun 25, 2011 at 10:18 PM, wren ng thornton wrote: > On 6/25/11 6:51 AM, John Lato wrote: > > Honestly I'm quite dis-satisfied with the current state of code which > > depends on iteratee/enumerator. It's nearly all written in a very > low-level > > style, i.e. directly writing 'liftI step', or 'case x of Yield -> ...'. > > This is exactly what I would hope users could avoid, by using the > functions > > in e.g. Data.Iteratee.ListLike. > > > > I've recently added more functions to iteratee which greatly reduce the > need > > for this type of code. I don't know about enumerator, but I expect it > isn't > > rich enough since most user code I've seen is pretty low-level. > > I have a rather large suite of list-like functions for the old version of > iteratee (used by a project I've been working on for a while). Once I get > the time to convert the project to the newer iteratee, I'll send a patch > with any you're still missing. > I'd greatly appreciate it. Even if they're for the old version; doing the conversion is fairly mechanical. > (Though, admittedly, I'm not terribly keen on ListLike. The classes still > seem too monolithic and ad-hoc. Though I'm not sure there's a way around > that without something closer to ML's functor modules.) > Refactoring ListLike has been a long-standing objective of mine, but I haven't put much time into it because it would cause breaking changes which I didn't think anyone else would appreciate. No way to tell except to just release it I guess. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is a "simple pattern binding"?
> > > g1 x y z = if x>y then show x ++ show z else g2 y x > > > > > > g2 :: (Show a, Ord a) => a -> a -> String > > > g2 | False = \p q -> g1 q p () > > >| otherwise = \p q -> g1 q p 'a' > > >where x = True > > > > It appears to me that GHC is justified. According to 4.5.1 and 4.5.2, g1 > > by itself constitutes a declaration group. It is considered by itself > > and is generalized prior to combining it with g2. > Great, now I'm even more confused. 4.5.1 says: > A binding b1 depends on a binding b2 in the same list of > declarations if either > 1. b1 contains a free identifier that has no type signature > and is bound by b2, or > 2. b1 depends on a binding that depends on b2. > A declaration group is a minimal set of mutually dependent > bindings. Hindley-Milner type inference is applied to each > declaration group in dependency order. > So here the first binding (of g1) contains the free identifier g2, > which is bound by the second binding. Conversely, the second binding > contains g1 free. So the two bindings are mutually dependent, no? No, the binding of g1 doesn't depend on the binding of g2, because g2 has a type signature (clause 1). The type of g1 is inferred using the declared type of g2. Then that type is used in inferring a type for g2, which will be compared with its declared signature. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is a "simple pattern binding"?
At Sat, 25 Jun 2011 14:20:52 -0400, Scott Turner wrote: > > > g1 x y z = if x>y then show x ++ show z else g2 y x > > > > g2 :: (Show a, Ord a) => a -> a -> String > > g2 | False = \p q -> g1 q p () > >| otherwise = \p q -> g1 q p 'a' > >where x = True > > It appears to me that GHC is justified. According to 4.5.1 and 4.5.2, g1 > by itself constitutes a declaration group. It is considered by itself > and is generalized prior to combining it with g2. > > I agree that the report is confusing in its use of "simple pattern binding". Great, now I'm even more confused. 4.5.1 says: A binding b1 depends on a binding b2 in the same list of declarations if either 1. b1 contains a free identifier that has no type signature and is bound by b2, or 2. b1 depends on a binding that depends on b2. A declaration group is a minimal set of mutually dependent bindings. Hindley-Milner type inference is applied to each declaration group in dependency order. So here the first binding (of g1) contains the free identifier g2, which is bound by the second binding. Conversely, the second binding contains g1 free. So the two bindings are mutually dependent, no? In fact, section 4.5.2 goes on to use the following example for a declaration group: f x = let g1 x y = if x>y then show x else g2 y x g2 p q = g1 q p in ... This example is very close to the code I gave. How can my example have two declaration groups when this example has only one? David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)
On 6/25/11 2:15 PM, Erik Hesselink wrote: > On Sat, Jun 25, 2011 at 19:07, Evan Laforge wrote: >> On Sat, Jun 25, 2011 at 9:00 AM, Jens Blanck wrote: > So there's a range of possible Monoid instances for each type, More for some types than for others. For Maybe there are three: * always take the first/left value; * always take the last/right value; * or, use a semigroup operation defined on the values. > > Brent Yorgey recently blogged about a fourth instance [1] which also > uses the semigroup operation on the values, but treats Nothing as > failure, returning Nothing. > > Erik > > [1] https://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/ Ah, yes. I forgot about that one. Though technically that one actually requires a monoid, not just a semigroup, since mempty = Just mempty. Which furthers the point that most types have an abundance of monoid instances. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] commutative monoid?
On Sat, Jun 25, 2011 at 2:02 PM, Brent Yorgey wrote: > Actually, there are (at least) four: there's also the one where > mappend = liftA2 mappend, i.e. introduce potential failure into a > monoid operation defined on the values. I wrote about it here: > > http://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/ Just out of curiosity, what was the problem that wanted this kind of monoid for the solution? I always find concrete examples useful in addition to the abstract explorations and toy examples. It's Map not Maybe, but in my case, I have "damage", which is user-modified data that will have to be recomputed. Given a Map from IDs to damage ranges, mappending two bits of damage means the ranges (themselves monoids of course) also have to be mappended. The case for not lifting is that elsewhere, during said recomputation, I accumulate some intermediate results for display. It's actually a bug if two results share the same ID, but in any case it wouldn't make sense to merge them, and the value type isn't in monoid. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)
On 6/25/11 1:07 PM, Evan Laforge wrote: > In the > case of the overriding version, you have to decide on which side to > merge the new monoid, and on the lifted one the two choices become > four, since you then have to decide whether the unionWith argument > should be flipped or not. > [...] > So I think the Data.Map choice is reasonable for that reason. If it > were lifted, it would have to make a hard-coded decision about the > "side". If you have to write your own, that's under your control. You should pass them through in the same order, to maximize intuitability. Order swapping can be handled by the Dual newtype. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)
On 6/25/11 12:00 PM, Jens Blanck wrote: >>> So there's a range of possible Monoid instances for each type, >> >> More for some types than for others. For Maybe there are three: >> >> * always take the first/left value; >> * always take the last/right value; >> * or, use a semigroup operation defined on the values. >> >> The first two options are provided by the First and Last newtypes, and the >> third option is provided by the instance for Maybe itself (except that it >> spuriously requires a Monoid instance instead of just a semigroup). > > But why does the Map instance of Monoid _not_ mimic the one chosen for > Maybe. I claim this causes unnecessary surprises for users (and lifting the > Monoid instance seems more useful, but that is harder to substantiate). For what it's worth, if people come to a decent enough consensus on which instance should be the default for Data.Map, then we should propose it on the libraries@ list. Of course we'll want to have Data.IntMap behave the same way, and consequently I'd update Data.Trie to follow suit. The various hashable and unordered containers will also probably want to follow suit. For Data.Trie, I only chose the version I did for conformity with IntMap. There's nothing especially interesting about the choice nor difficult about changing it (other than backwards compatibility issues). One issue that will come up, however, is that we'll want to generalize the First and Last newtypes so that they can be used consistently for all of different types which have these three Monoid instances. I'm not sure off hand where those newtypes are living these days, nor how much code it'd break to change them thus (and move them to base, if necessary). -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Iteratee IO examples
On 6/25/11 6:51 AM, John Lato wrote: > Honestly I'm quite dis-satisfied with the current state of code which > depends on iteratee/enumerator. It's nearly all written in a very low-level > style, i.e. directly writing 'liftI step', or 'case x of Yield -> ...'. > This is exactly what I would hope users could avoid, by using the functions > in e.g. Data.Iteratee.ListLike. > > I've recently added more functions to iteratee which greatly reduce the need > for this type of code. I don't know about enumerator, but I expect it isn't > rich enough since most user code I've seen is pretty low-level. I have a rather large suite of list-like functions for the old version of iteratee (used by a project I've been working on for a while). Once I get the time to convert the project to the newer iteratee, I'll send a patch with any you're still missing. (Though, admittedly, I'm not terribly keen on ListLike. The classes still seem too monolithic and ad-hoc. Though I'm not sure there's a way around that without something closer to ML's functor modules.) -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] commutative monoid?
On Fri, Jun 24, 2011 at 11:13:46PM -0700, wren ng thornton wrote: > On 6/25/11 1:34 AM, Evan Laforge wrote: > > So there's a range of possible Monoid instances for each type, > > More for some types than for others. For Maybe there are three: > > * always take the first/left value; > * always take the last/right value; > * or, use a semigroup operation defined on the values. Actually, there are (at least) four: there's also the one where mappend = liftA2 mappend, i.e. introduce potential failure into a monoid operation defined on the values. I wrote about it here: http://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/ -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] commutative monoid?
On Fri, 24 Jun 2011, Evan Laforge wrote: So there's a range of possible Monoid instances for each type, and maybe they were chosen by historical happenstance rather than some kind of "principle monoid" (is there such a thing?). Is there a name for the thing that's like a monoid, but the operator is commutative too? http://en.wikipedia.org/wiki/Commutative_monoid ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: Win32-junction-point-0.0.1
I'm pleased to announce the initial release of Win32-junction-point * hackage: http://hackage.haskell.org/package/Win32-junction-point * git repository: https://github.com/mikesteele81/Win32-junction-point This package provides the ability to manipulate NTFS junction points as supported by Windows 2000 and above. Junction points, along with NTFS hard links and NTFS symbolic links, are a type of symbolic link that can be made between folders existing on the same filesystem. Please read Microsoft KB205524 [1] for more information on junction points. Junction points have always been left undocumented in the Win32 SDK. The Windows 2000 Resource Kit came with a command-line utility named linkd.exe to work with them. Later, Mark Russinovich of SysInternals distributed a replacement utility named Junction [2] which accomplished the same thing. This source code is based on an article [3] and C++ library [4] written by Mike Nordell at codeproject.com. It is against Microsoft's recommendation to make use of undocumented API features. Use this library at your own risk. [1] http://support.microsoft.com/?kbid=205524 [2] http://technet.microsoft.com/en-us/sysinternals/bb896768 [3] http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=194 [4] http://www.codeproject.com/KB/winsdk/junctionpoints.aspx -- Michael Steele ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help
The error in ghci is Couldn't match expected type `Int' with actual type `[a0]' In the expression: [] In an equation for `p': p [] = [] You've defined p as [String] -> Int, but then your base case is p [] = []. [] is not an Int. I changed it to 0 and it'll compile, at least, but I'm not sure if that's the effect you're after. http://hpaste.org/48324 Edited code (really just indentation changes and the change from p [] = [] to p [] = 0) On Jun 25, 2011, at 3:19 PM, Stoyan Peev wrote: > First I am using WinHugs. > > that's the code i made so far but it's still not working: > > http://hpaste.org/48318 > > > Error: > ERROR file:.\kursovazadacha.hs:36 - Type error in explicitly typed binding > *** Term : p > *** Type : [String] -> [a] > *** Does not match : [String] -> Int > > > I'm still breaking down somewhere ... > > > > 2011/6/25 Daniel Patterson : >> what haskell compiler are you using? And what does the "include" line do? >> >> That does not look like a GHC error message (the only compiler I'm familiar >> with), but it seems like it is saying that you should not have the extra >> newlines between the function type signature and declaration. - that's only >> my guess, based on the assumption that the whitespace is being converted to >> a syntax with explicit semilcolon line terminations. >> >> now, looking at the actual code, the type of the parse function is [a] -> >> [a]. This means that you can parse a list of anything into a list of >> anything, which doesnt make much sense. This should probably be [String] -> >> [String] (you are parsing a list of strings to a list of strings, yes?). >> Now the base case of parse (the first case) makes sense, but look at the >> second case. parse is being given a list of elements (which you have used >> pattern matching to decompose, but the whole argument, (x:xs), is a list of >> elements). You are then passing that, unchanged, to eval. This means that >> eval must take the same type. Does it? how would you apply eval to each >> element in that list, instead of just applying it to the whole list? >> >> On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote: >> >>> I found the library myself, and i already put the code in that site: >>> >>> http://hpaste.org/48277 >>> >>> >>> >>> That's what i have tried to do for making the task by calling the one >>> string function by another one: >>> >>> include kursovazadacha >>> >>> parse :: [a] -> [a] >>> >>> parse [] = [] >>> >>> parse (x:xs) = eval (x:xs) >>> >>> >>> The error from the compiler: >>> >>> ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;', >>> possibly due to bad layout) >>> >>> >>> On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson >>> wrote: What have you tried to do in order to make it work for the list, and what error results? What is confusing about the error message? More generally, how could you transform an operation on a single string into one that does the same thing to a list of strings? You've probably talked about higher order functions in your class - would any of the common ones (filter, map, foldr) be helpful here? Would any encapsulate what you are trying to do? If you include these kinds of things, I think you'll find this community to be very helpful; without that (showing what your thought process is, why it isn't working, what seems confusing about what the haskell compiler is telling you, etc), you are not going to get help here. People here are very friendly and willing to help people learn; this is not a place to come to get an assignment finished :) Also, could you put the library you are using (I'm assuming that this is provided by your university) and the code on somewhere like hpaste.org, so that the formatting is not messed up by email, and it is syntax highlighted? On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote: > Hello all, > > I am experiencing some issues to do my course task in university. > > I have to write a calculator- function in Haskell. The function > argument is a list of strings and also form such list, as each string > of the argument made definite action: > - If the string has the form of an arithmetic _expression_ - calculate > this _expression_. The string result becomes part of the list-result. > If the _expression_ contains a variable which is not assigned value, > the result is displayed "undefined". > - If the string has the form- Name = value calculated from the last > _expression_ is assigned to the variable with the corresponding name > in the list, and in the result list is formed a string with type > - If there is not a calculated _expression_ to be assigned to form a > string "no value". > - If the string is non-blank, but there is a species different from > the above two case
Re: [Haskell-cafe] Help
First I am using WinHugs. that's the code i made so far but it's still not working: http://hpaste.org/48318 Error: ERROR file:.\kursovazadacha.hs:36 - Type error in explicitly typed binding *** Term : p *** Type : [String] -> [a] *** Does not match : [String] -> Int I'm still breaking down somewhere ... 2011/6/25 Daniel Patterson : > what haskell compiler are you using? And what does the "include" line do? > > That does not look like a GHC error message (the only compiler I'm familiar > with), but it seems like it is saying that you should not have the extra > newlines between the function type signature and declaration. - that's only > my guess, based on the assumption that the whitespace is being converted to a > syntax with explicit semilcolon line terminations. > > now, looking at the actual code, the type of the parse function is [a] -> > [a]. This means that you can parse a list of anything into a list of > anything, which doesnt make much sense. This should probably be [String] -> > [String] (you are parsing a list of strings to a list of strings, yes?). Now > the base case of parse (the first case) makes sense, but look at the second > case. parse is being given a list of elements (which you have used pattern > matching to decompose, but the whole argument, (x:xs), is a list of > elements). You are then passing that, unchanged, to eval. This means that > eval must take the same type. Does it? how would you apply eval to each > element in that list, instead of just applying it to the whole list? > > On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote: > >> I found the library myself, and i already put the code in that site: >> >> http://hpaste.org/48277 >> >> >> >> That's what i have tried to do for making the task by calling the one >> string function by another one: >> >> include kursovazadacha >> >> parse :: [a] -> [a] >> >> parse [] = [] >> >> parse (x:xs) = eval (x:xs) >> >> >> The error from the compiler: >> >> ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;', >> possibly due to bad layout) >> >> >> On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson >> wrote: >>> What have you tried to do in order to make it work for the list, and what >>> error results? What is confusing about the error message? More generally, >>> how could you transform an operation on a single string into one that does >>> the same thing to a list of strings? You've probably talked about higher >>> order functions in your class - would any of the common ones (filter, map, >>> foldr) be helpful here? Would any encapsulate what you are trying to do? >>> >>> If you include these kinds of things, I think you'll find this community >>> to be very helpful; without that (showing what your thought process is, why >>> it isn't working, what seems confusing about what the haskell compiler is >>> telling you, etc), you are not going to get help here. People here are very >>> friendly and willing to help people learn; this is not a place to come to >>> get an assignment finished :) >>> >>> Also, could you put the library you are using (I'm assuming that this is >>> provided by your university) and the code on somewhere like hpaste.org, so >>> that the formatting is not messed up by email, and it is syntax highlighted? >>> >>> On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote: >>> Hello all, I am experiencing some issues to do my course task in university. I have to write a calculator- function in Haskell. The function argument is a list of strings and also form such list, as each string of the argument made definite action: - If the string has the form of an arithmetic _expression_ - calculate this _expression_. The string result becomes part of the list-result. If the _expression_ contains a variable which is not assigned value, the result is displayed "undefined". - If the string has the form- Name = value calculated from the last _expression_ is assigned to the variable with the corresponding name in the list, and in the result list is formed a string with type - If there is not a calculated _expression_ to be assigned to form a string "no value". - If the string is non-blank, but there is a species different from the above two case, form the string "error". - If the string is empty, incl. when it contains only spaces, in the result there is not form a string. Expressions consist of integers without sign variables, operations + (Addition), - (subtraction), * (multiplication) and / (divide) and parentheses. Where no brackets, the operations are performed from left to right, but * and / precede the + and -. Implementation of any operation gives integer; in the division rejected the fractional part, if any. Variables have names of one letter - from the Latin small letter. In the beginning, end or between the elements of each
Re: [Haskell-cafe] What is a "simple pattern binding"?
On 2011-06-25 10:52, David Mazieres wrote: > Further confusing things, GHC accepts the following: > > g1 x y z = if x>y then show x ++ show z else g2 y x > > g2 :: (Show a, Ord a) => a -> a -> String > g2 | False = \p q -> g1 q p () > | otherwise = \p q -> g1 q p 'a' >where x = True > > > and infers type: > > g1 :: (Show a, Show a1, Ord a1) => a1 -> a1 -> a -> [Char] > > According to 4.4.3.2, g2 definitely does not have a simple pattern > binding, as its binding is not of the form p = e where p is a pattern. > Yet by section 4.5.5, if g2 were not considered a simple pattern > binding, the constrained type variables in the binding group > containing g1 and g2 (in particular the inferred type (Show a => a) of > z in g1) would not be allowed to be generalized. It appears to me that GHC is justified. According to 4.5.1 and 4.5.2, g1 by itself constitutes a declaration group. It is considered by itself and is generalized prior to combining it with g2. I agree that the report is confusing in its use of "simple pattern binding". ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)
On Sat, Jun 25, 2011 at 19:07, Evan Laforge wrote: > On Sat, Jun 25, 2011 at 9:00 AM, Jens Blanck wrote: >>> > So there's a range of possible Monoid instances for each type, >>> >>> More for some types than for others. For Maybe there are three: >>> >>> * always take the first/left value; >>> * always take the last/right value; >>> * or, use a semigroup operation defined on the values. Brent Yorgey recently blogged about a fourth instance [1] which also uses the semigroup operation on the values, but treats Nothing as failure, returning Nothing. Erik [1] https://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)
On Sat, Jun 25, 2011 at 9:00 AM, Jens Blanck wrote: > I don't think the original question really is about commutativity, but > rather the choice of Monoid instance. Well, it was about two things, and that was one of them :) >> > So there's a range of possible Monoid instances for each type, >> >> More for some types than for others. For Maybe there are three: >> >> * always take the first/left value; >> * always take the last/right value; >> * or, use a semigroup operation defined on the values. >> >> The first two options are provided by the First and Last newtypes, and the >> third option is provided by the instance for Maybe itself (except that it >> spuriously requires a Monoid instance instead of just a semigroup). >> > > But why does the Map instance of Monoid _not_ mimic the one chosen for > Maybe. I claim this causes unnecessary surprises for users (and lifting the > Monoid instance seems more useful, but that is harder to substantiate). I'm guessing it's just historical happenstance. Instances that were introduced together, like the ones in Data.Monoid, show that thought was definitely put in to how they interact with each other. However for Data.Map is in a different package and may well have been written by a different person at a different time. I was wondering about any notions of "principal monoid" because I was wondering if there's any way to have guidelines about monoid instances to avoid the "different authors" effect. For Data.Map, it's hard to say. I have cases where I need both the default instance and a mappend I wrote 'mappend = Map.unionWith Monoid.mappend'. I have Monoid instances where some fields use the default "overriding" mappend, and some use the lifted version. In the case of the overriding version, you have to decide on which side to merge the new monoid, and on the lifted one the two choices become four, since you then have to decide whether the unionWith argument should be flipped or not. In practice, when I use the lifted mappend, it's with commutative operators, so the multiplication of possibilities doesn't matter. So that's what started me down the commutative path. So I think the Data.Map choice is reasonable for that reason. If it were lifted, it would have to make a hard-coded decision about the "side". If you have to write your own, that's under your control. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why aren't there anonymous sum types in Haskell?
Arlen Cuss writes: >> import Data.Either >> type (:|:) a b = Either a b >> (???) = either >> >> foo :: (Int :|: Bool :|: String :|: Double) -> Int >> foo = >> \ i -> i + 7 ??? >> \ b -> if b then 1 else 0 ??? >> \ s -> length s ??? >> \ d -> floor d > > INFIX TYPE OPERATORS!!??! > > O_O Yep. http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/data-type-extensions.html#infix-tycons -- lelf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] commutative monoid?
>> So is there a typeclass for that? > > There might be one hidden in one of the attempts at redesigning the > numeric hierarchy (e.g., Numeric Prelude), but there's not a canonical > typeclass for them. Unfortunately it's not really a good match for the > typeclass system since it doesn't introduce any new operations, it only > introduces laws--- which aren't verified nor enforced. > > Though, if you happen to know the property does hold, then you're free to > take advantage of it. (E.g., for the Maybe instance which uses a semigroup > operation, if the semigroup op is commutative then so is the monoid op.) That's a good point about laws vs. typeclasses. Though I think if I were doing something that relied on commutativity for e.g. Maybe I would still define my own typeclass. That way at least there is documentation in the name without having to put in a comment everywhere saying "btw I'm relying on this xyz", and if I want to give the same treatment to some other types then I don't have to deal with newtype wrappers. While I'm sure 'map Newtype biglist' can be optimized away, I'm not so sure about 'Map.map (second Newtype) bigmap'. But in any case, it's fine the stdlib doesn't have one, because it's easy enough to write your own. thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Map Monoid instance (was commutative monoid?)
I don't think the original question really is about commutativity, but rather the choice of Monoid instance. Not being especially mathematically inclined, every once and a while I > get a little panicked when I notice that, e.g. Data.Map mappend is a > plain left-biased union, and doesn't actually mappend the values of > the map. > As noted in the reply > > So there's a range of possible Monoid instances for each type, > > More for some types than for others. For Maybe there are three: > > * always take the first/left value; > * always take the last/right value; > * or, use a semigroup operation defined on the values. > > The first two options are provided by the First and Last newtypes, and the > third option is provided by the instance for Maybe itself (except that it > spuriously requires a Monoid instance instead of just a semigroup). > > But why does the Map instance of Monoid _not_ mimic the one chosen for Maybe. I claim this causes unnecessary surprises for users (and lifting the Monoid instance seems more useful, but that is harder to substantiate). Jens ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What is a "simple pattern binding"?
Section 4.4.3.2 of the 2010 Haskell report says: A simple pattern binding has form p = e. The pattern p is matched “lazily” as an irrefutable pattern, as if there were an implicit ~ in front of it. This makes it sound as though p is a pattern, which I assume means what section 3.17 defines as the non-terminal "pat". pat -> lpat qconop pat | lpat This is further suggested by the explicit mention of ~, which would be redundant if p had to be a var, since variables always match (according to section 3.17.2 rule 1). So my reading of section 4.4.3.2 is that the following is considered a simple pattern binding (because it has no guards): (f, g) = (\x -> x, f) However, section 4.5.5 seems to contradict this. It reads: Recall that a variable is bound by either a function binding or a pattern binding, and that a simple pattern binding is a pattern binding in which the pattern consists of only a single variable (Section 4.4.3). Moreover, it goes on to give an example and explanation: [(n,s)] = reads t ... Hence, when non-simple pattern bindings are used This text makes it sound as though a "simple pattern binding" can have only a single variable to the left of the = sign, meaning: f = \x -> x Further confusing things, GHC accepts the following: g1 x y z = if x>y then show x ++ show z else g2 y x g2 :: (Show a, Ord a) => a -> a -> String g2 | False = \p q -> g1 q p () | otherwise = \p q -> g1 q p 'a' where x = True and infers type: g1 :: (Show a, Show a1, Ord a1) => a1 -> a1 -> a -> [Char] According to 4.4.3.2, g2 definitely does not have a simple pattern binding, as its binding is not of the form p = e where p is a pattern. Yet by section 4.5.5, if g2 were not considered a simple pattern binding, the constrained type variables in the binding group containing g1 and g2 (in particular the inferred type (Show a => a) of z in g1) would not be allowed to be generalized. So is section 4.4.3.2 of the Haskell 2010 report just wrong? Or is GHC allowing code prohibited by the standard? Or am I somehow misreading the standard? Anyway, if someone can provide a less ambiguous definition of the term "simple pattern binding", I would appreciated it, particularly if you can point to support for your definition in the Haskell 2010 report... Thanks, David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Logo
http://en.wikipedia.org/wiki/File:Haskell-Logo.svg cheers daniel Am 6/25/11 8:18 AM, schrieb Michael Xavier: I wondered if anyone knew the legalities of using the haskell logo, in particular, this one: http://media.nokrev.com/junk/haskell-logos/logo1.png on a website, a personal blog in particular. While I am not yet a primarily haskell coder, I'm using it more and more. I find this logo in particular to be quite beautiful and would probably modify it a bit to emphasize the lambda, which has broader application to computer science beyond 1 language. I can't find any information on what the license is for this image. Could anyone offer any advice on this? -- Michael Xavier http://www.michaelxavier.net ___ 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] Iteratee IO examples
From: Eric Rasmussen > > Hi, > > Examples are very helpful to me too -- thank you for sharing. I'm > especially > curious to see if there are any examples that allow you to use or convert > non-iteratee-based functions. I have only just begun reading about > iteratees > and might be missing the point, but it seems like many of the examples so > far rely on explicit recursion or special functions from one of the > iteratee > modules. > You might be interested in the attoparsec-enumerator and attoparsec-iteratee packages, which adapt attoparsec parsers to work with iteratees. They're small, self-contained, and quite readable. Since attoparsec works with partial parses, it's a natural fit for iteratees. Honestly I'm quite dis-satisfied with the current state of code which depends on iteratee/enumerator. It's nearly all written in a very low-level style, i.e. directly writing 'liftI step', or 'case x of Yield -> ...'. This is exactly what I would hope users could avoid, by using the functions in e.g. Data.Iteratee.ListLike. I've recently added more functions to iteratee which greatly reduce the need for this type of code. I don't know about enumerator, but I expect it isn't rich enough since most user code I've seen is pretty low-level. For some other iteratee examples, you can 'darcs get http://www.tiresiaspress.us/haskell/sndfile-enumerators/' and look at the examples directory (or browse online, of course). > > Is there a way to take a simple function (example below) and use an > enumerator to feed it a ByteString from a file, or do you have to write > functions explicitly to work with a given iteratee implementation? > >import qualified Data.ByteString.Char8 as B >sortLines = B.unlines . sort . B.lines > For this case, there's no point to using iteratees at all. Just read the file in directly to a strict bytestring. Since you're sorting, you'll need to see all the lines before results can be returned. If the file is too big to fit into memory, you'd need a more sophisticated algorithm for which you could use iteratees. In the general case, you need to write for a given iteratee implementation, but in many specific cases it's not necessary. If you want to transform each line of a file, for instance (with iteratee): import Data.ByteString.Char8 as B import Data.Iteratee as I import Data.Iteratee.Char import System.IO import Control.Monad.IO.Class transform :: (ByteString -> ByteString) -> FilePath -> Iteratee [ByteString] IO () transform tFunc oFile = do h <- liftIO $ openFile oFile WriteMode joinI $ rigidMapStream tFunc $ I.mapM_ (B.hPutStrLn h) liftIO $ hClose h rewriteFile :: (ByteString -> ByteString) -> FilePath -> FilePath -> IO () rewriteFile tFunc iFile oFile = fileDriver (joinI $ enumLinesBS (transform tFunc oFile)) iFile An unfolding version would be possible too, which would take a parameter tFunc :: (s -> ByteString -> (s, ByteString)) Maybe I'll add these as utilities in the next version of iteratee. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Software patents covered in GHC?
Manuel M T Chakravarty wrote: > That's right, but it doesn't help any of us anything. The > costs of defending against a patent claim (even if the claim > can eventually be overturned) are much to high to bear for > anybody, but major corporations. In other words, it doesn't > matter if you are right or wrong if you can't pay the legal > bill. This is not just theory as a fair number of mobile app > developer recently found out: > > > http://fosspatents.blogspot.com/2011/05/lodsys-sues-7-app-developers-in-eastern.html Yep, patents are a bitch for small independant developers stuck between Apple's onerous AppStore conditions and patent trolls like Lodsys. However, for open source projects like GHC, there are a number of organisations like the Software Freedom Law Center: http://www.softwarefreedom.org/ that provide (at least some) patent defense for open source projects. Its also possible for open source projects to 'design around' patent issues. For instance there was a patent on the VFAT file format implementaion in the Linux kernel that was avoided by careful reading of the patent and working around the patents specifics: http://lwn.net/Articles/338981/ Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe