Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Cabal error (Ivan Hugo Guevara) 2. "Couldn't match expected type" and simple "Couldn't match type" (Ken Kawamoto) 3. cleanest way to unwrap a list? (Christopher Howard) 4. Re: cleanest way to unwrap a list? (Shakthi Kannan) 5. Re: cleanest way to unwrap a list? (Ben Kolera) 6. Re: cleanest way to unwrap a list? (Jay Sulzberger) 7. Re: cleanest way to unwrap a list? (Jay Sulzberger) 8. Re: cleanest way to unwrap a list? (Henk-Jan van Tuyl) 9. Re: cleanest way to unwrap a list? (Graham Gill) ---------------------------------------------------------------------- Message: 1 Date: Sun, 12 Aug 2012 10:36:55 -0300 From: Ivan Hugo Guevara <aivan2...@gmail.com> Subject: Re: [Haskell-beginners] Cabal error To: Gregory Guthrie <guth...@mum.edu> Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <cacu-qgk7ck8mq9ynycf8delt-j-jathn2kkgibdx_ptkxop...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 I think so.... According to this: http://hackage.haskell.org/package/regex-tdfa-1.1.8, you need 7/8 packages to make it work. -- Atte. Iv?n Guevara ------------------------------ Message: 2 Date: Mon, 13 Aug 2012 09:01:45 +0900 From: Ken Kawamoto <kentaro.kawam...@gmail.com> Subject: [Haskell-beginners] "Couldn't match expected type" and simple "Couldn't match type" To: beginners@haskell.org Message-ID: <cagbyekouytnkjyx9wykg5gruqvwoy9e-fpq3vtkqaa16czu...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi Haskellers, I found GHC sometimes complains "Couldn't match expected type X with actual type Y" , and simply "Couldn't match type X with Y" in other cases. not a big deal, but was wondering what makes this difference. -- Ken ------------------------------ Message: 3 Date: Sun, 12 Aug 2012 21:21:59 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: [Haskell-beginners] cleanest way to unwrap a list? To: Haskell Beginners <beginners@haskell.org> Message-ID: <50288ef7.4090...@frigidcode.com> Content-Type: text/plain; charset="iso-8859-1" Hi. Is the some generic, clean syntax to unwrap a nested list, modify the value, and put it back together? Say, for example, I have the list [[1,2],[3,4]] and want to add 1 to each inner element, resulting in [[2,3],[4,5]]. After reading about the list monad, I was rather excited, because I (mistakenly) thought something like this would work: code: -------- a = do b <- [[1,2],[3,4]] c <- b return (c + 1) -------- That would be awesome, because I would be able to modify the list at each level of unwrapping, while leaving the code very neat and readable. However, what the above example actually does is produce a /single/ list from the values: code: -------- *Main> a [2,3,4,5] -------- Obviously wishing won't change how the list monad works, but I thought it might be worth asking if there is some other monad or syntactic trick that does something along the lines of what I am looking for. -- frigidcode.com indicium.us -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 554 bytes Desc: OpenPGP digital signature URL: <http://www.haskell.org/pipermail/beginners/attachments/20120812/24df4551/attachment-0001.pgp> ------------------------------ Message: 4 Date: Mon, 13 Aug 2012 11:07:48 +0530 From: Shakthi Kannan <shakthim...@gmail.com> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <cabg-yt3cm9uee7q6r9oazdnxldzkm-ba52cddnjzbiazax3...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Hi, --- On Mon, Aug 13, 2012 at 10:51 AM, Christopher Howard <christopher.how...@frigidcode.com> wrote: | Say, for example, I have the list | [[1,2],[3,4]] and want to add 1 to each inner element, resulting in | [[2,3],[4,5]]. \-- Like this? ghci> let xxs = [[1,2], [3,4]] ghci> [ [ x+1 | x <- xs] | xs <- xxs ] [[2,3],[4,5]] SK -- Shakthi Kannan http://www.shakthimaan.com ------------------------------ Message: 5 Date: Mon, 13 Aug 2012 15:48:30 +1000 From: Ben Kolera <ben.kol...@gmail.com> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <fddf880c755e4e7285c43bc9495a6...@gmail.com> Content-Type: text/plain; charset="utf-8" Maybe this is overkill, but if you want a more generic way for accessing and changing nested immutable data in general, you could check this package out as it is pretty exciting (to me at least): http://hackage.haskell.org/package/lens For more information on exactly what a lens is, read here: http://dl.dropbox.com/u/7810909/media/doc/lenses.pdf Cheers, Ben On Monday, 13 August 2012 at 3:21 PM, Christopher Howard wrote: > Hi. Is the some generic, clean syntax to unwrap a nested list, modify > the value, and put it back together? Say, for example, I have the list > [[1,2],[3,4]] and want to add 1 to each inner element, resulting in > [[2,3],[4,5]]. > > After reading about the list monad, I was rather excited, because I > (mistakenly) thought something like this would work: > > code: > -------- > a = do b <- [[1,2],[3,4]] > c <- b > return (c + 1) > -------- > > That would be awesome, because I would be able to modify the list at > each level of unwrapping, while leaving the code very neat and readable. > However, what the above example actually does is produce a /single/ list > from the values: > > code: > -------- > *Main> a > [2,3,4,5] > -------- > > Obviously wishing won't change how the list monad works, but I thought > it might be worth asking if there is some other monad or syntactic trick > that does something along the lines of what I am looking for. > > -- > frigidcode.com (http://frigidcode.com) > indicium.us (http://indicium.us) > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org (mailto:Beginners@haskell.org) > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 6 Date: Mon, 13 Aug 2012 01:51:07 -0400 (EDT) From: Jay Sulzberger <j...@panix.com> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: Haskell Beginners <beginners@haskell.org> Message-ID: <pine.neb.4.64.1208130125130.9...@panix3.panix.com> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Sun, 12 Aug 2012, Christopher Howard <christopher.how...@frigidcode.com> wrote: > Hi. Is the some generic, clean syntax to unwrap a nested list, modify > the value, and put it back together? Say, for example, I have the list > [[1,2],[3,4]] and want to add 1 to each inner element, resulting in > [[2,3],[4,5]]. I think there is a forgetful functor from a part of Haskell to Scheme, and this code lies in the image of this functor: > (define map-1+ (lambda (l) (map (lambda (n) (+ 1 n)) l))) #<unspecified> > (map-1+ (list 0 1 2 3 4)) (1 2 3 4 5) > (define map-map-1+ (lambda (l-of-l-of-numbers) (map map-1+ l-of-l-of-numbers))) #<unspecified> > (map-map-1+ (list (list 1 2) (list 3 4))) ((2 3) (4 5)) > (quit) Process scheme finished Further we have for this forgetful functor, that the original Haskell code and the transformed-to-Scheme code have the "same" running behavior, and the "same" input output behavior. And under this functor the image of the object called "map" in Haskell is the object called "map" in Scheme. Haskell has map in the prelude: map :: (a -> b) -> [a] -> [b] map f xs is the list obtained by applying f to each element of xs, i.e., map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] map f [x1, x2, ...] == [f x1, f x2, ...] Above quote taken from http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html So, likely, I do not know Haskell, something like: m1 = map 1+ l m2 = map m1 l should work. Likely a bit more source code might be required for various Haskell systems. And the procedure 1+ might have to be defined, up to getting the right type of number specified, as 1+ n = (n + 1) oo--JS. > > After reading about the list monad, I was rather excited, because I > (mistakenly) thought something like this would work: > > code: > -------- > a = do b <- [[1,2],[3,4]] > c <- b > return (c + 1) > -------- > > That would be awesome, because I would be able to modify the list at > each level of unwrapping, while leaving the code very neat and readable. > However, what the above example actually does is produce a /single/ list > from the values: > > code: > -------- > *Main> a > [2,3,4,5] > -------- > > Obviously wishing won't change how the list monad works, but I thought > it might be worth asking if there is some other monad or syntactic trick > that does something along the lines of what I am looking for. > > -- > frigidcode.com > indicium.us > > ------------------------------ Message: 7 Date: Mon, 13 Aug 2012 01:55:28 -0400 (EDT) From: Jay Sulzberger <j...@panix.com> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: Haskell Beginners <beginners@haskell.org> Message-ID: <pine.neb.4.64.1208130153300.9...@panix3.panix.com> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Mon, 13 Aug 2012, Jay Sulzberger wrote: > > > On Sun, 12 Aug 2012, Christopher Howard <christopher.how...@frigidcode.com> > wrote: > >> Hi. Is the some generic, clean syntax to unwrap a nested list, modify >> the value, and put it back together? Say, for example, I have the list >> [[1,2],[3,4]] and want to add 1 to each inner element, resulting in >> [[2,3],[4,5]]. > > I think there is a forgetful functor from a part of Haskell to > Scheme, and this code lies in the image of this functor: > > > (define map-1+ > (lambda (l) > (map (lambda (n) (+ 1 n)) l))) > #<unspecified> > > (map-1+ (list 0 1 2 3 4)) > (1 2 3 4 5) > > (define map-map-1+ > (lambda (l-of-l-of-numbers) > (map map-1+ l-of-l-of-numbers))) > #<unspecified> > > (map-map-1+ (list (list 1 2) (list 3 4))) > ((2 3) (4 5)) > > (quit) > > Process scheme finished > > Further we have for this forgetful functor, that the original > Haskell code and the transformed-to-Scheme code have the "same" > running behavior, and the "same" input output behavior. And > under this functor the image of the object called "map" in > Haskell is the object called "map" in Scheme. > > Haskell has map in the prelude: > > map :: (a -> b) -> [a] -> [b] > > map f xs is the list obtained by applying f to each element of xs, i.e., > > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] > map f [x1, x2, ...] == [f x1, f x2, ...] > > Above quote taken from > > http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html > > So, likely, I do not know Haskell, something like: > > m1 = map 1+ l > m2 = map m1 l Ah, above likely wrong. OK, what about m1 l = map 1+ l m2 l = map m1 l or perhaps m1 = map 1+ m2 = map m1 oo--JS. > > should work. Likely a bit more source code might be required for > various Haskell systems. And the procedure 1+ might have to be > defined, up to getting the right type of number specified, as > > 1+ n = (n + 1) > > oo--JS. > > >> >> After reading about the list monad, I was rather excited, because I >> (mistakenly) thought something like this would work: >> >> code: >> -------- >> a = do b <- [[1,2],[3,4]] >> c <- b >> return (c + 1) >> -------- >> >> That would be awesome, because I would be able to modify the list at >> each level of unwrapping, while leaving the code very neat and readable. >> However, what the above example actually does is produce a /single/ list >> from the values: >> >> code: >> -------- >> *Main> a >> [2,3,4,5] >> -------- >> >> Obviously wishing won't change how the list monad works, but I thought >> it might be worth asking if there is some other monad or syntactic trick >> that does something along the lines of what I am looking for. >> >> -- >> frigidcode.com >> indicium.us >> >> > > ------------------------------ Message: 8 Date: Mon, 13 Aug 2012 07:58:40 +0200 From: "Henk-Jan van Tuyl" <hjgt...@chello.nl> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: "Christopher Howard" <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <op.wiytj2kspz0...@zen5.arnhem.chello.nl> Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes On Mon, 13 Aug 2012 07:37:48 +0200, Shakthi Kannan <shakthim...@gmail.com> wrote: > Hi, > > --- On Mon, Aug 13, 2012 at 10:51 AM, Christopher Howard > <christopher.how...@frigidcode.com> wrote: > | Say, for example, I have the list > | [[1,2],[3,4]] and want to add 1 to each inner element, resulting in > | [[2,3],[4,5]]. > \-- > > Like this? > > ghci> let xxs = [[1,2], [3,4]] > > ghci> [ [ x+1 | x <- xs] | xs <- xxs ] > [[2,3],[4,5]] Or this? > map (map (+ 1)) [[1,2], [3,4]] [[2,3],[4,5]] Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- ------------------------------ Message: 9 Date: Mon, 13 Aug 2012 01:59:38 -0400 From: Graham Gill <math.simp...@gmail.com> Subject: Re: [Haskell-beginners] cleanest way to unwrap a list? To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <502897ca.5010...@gmail.com> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" What about just map (map f) xxs where for your example xxs == [[1,2], [3,4]] f == (+1) Graham On 13/08/2012 1:21 AM, Christopher Howard wrote: > Hi. Is the some generic, clean syntax to unwrap a nested list, modify > the value, and put it back together? Say, for example, I have the list > [[1,2],[3,4]] and want to add 1 to each inner element, resulting in > [[2,3],[4,5]]. > > After reading about the list monad, I was rather excited, because I > (mistakenly) thought something like this would work: > > code: > -------- > a = do b <- [[1,2],[3,4]] > c <- b > return (c + 1) > -------- > > That would be awesome, because I would be able to modify the list at > each level of unwrapping, while leaving the code very neat and readable. > However, what the above example actually does is produce a /single/ list > from the values: > > code: > -------- > *Main> a > [2,3,4,5] > -------- > > Obviously wishing won't change how the list monad works, but I thought > it might be worth asking if there is some other monad or syntactic trick > that does something along the lines of what I am looking for. > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120813/6aeb8053/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 50, Issue 13 *****************************************