From austinzhu666 at gmail.com Fri Aug 7 14:11:43 2020 From: austinzhu666 at gmail.com (Austin Zhu) Date: Fri, 7 Aug 2020 23:11:43 +0900 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a Message-ID: Hello! I'm learning Haskell and I found an interesting implementation of init using foldr. However I have difficulty understand how it works. *init' xs = foldr f (const []) xs id* * where f x g h = h $ g (x:)* Consider I have a input of *[1,2,3]*, then is would become *f 1 (f 2 ( f 3 (const []))) id* I substitute those parameters into f and the innermost one becomes *h $ (const []) (1:)*, which is simply *h []*. However when I want to reduce the expression further, I found it's hard to grasp. The next one becomes *f 2 (h [])* , which is *h $ (h []) (2:)* if it works like that. This looks confusing to me. To match the type of *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of type *[a]*, which isn't applicable to *(2:)*. I also thought it in another way that *f x g* returns a function of type *([a] -> [a]) -> [a],* this kinda makes sense considering applying *id* afterwards. But then I realized I still don't know what this *h* is doing here. It looks like *h* conveys *g (x:)* from last time into the next application. Did I miss something when I think about doing fold with function as accumulator? I'd really appreciate if anyone could help me with this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Sat Aug 8 05:24:57 2020 From: bob at redivi.com (Bob Ippolito) Date: Fri, 7 Aug 2020 22:24:57 -0700 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: References: Message-ID: I think the part that is confusing is that there are two steps here, there is the *foldr*, and then there is the application of *id* to the result of the *foldr*. *foldr* is of type *(a -> b -> b) -> b -> [a] -> b*, and in your example the type for *a* is *Integer* (probably not precisely Integer, but let's just say it is for simplicity) and the type for *b* is *[Integer] -> [Integer]*. It would be better to think of it as *(foldr f (const []) xs) id*. Another way to think of it is that *foldr* replaces the list *:* constructor with the function (*f*) and the *[]* constructor with the given *b* (*id*). Here's how I would think about the computation. In Haskell it's usually best to start with the outside and work in, due to the non-strict evaluation. At the end I've removed the bold from the terms that are already completely reduced. *init' [1, 2, 3]* *(foldr f (const []) (1 : 2 : 3 : [])) id* *(1 `f` (2 `f` (3 `f` const []))) id* *id ((2 `f` (3 `f` const [])) (1:))* *(2 `f` (3 `f` const [])) (1:)* 1 :* ((3 `f` const []) (2:))* 1 : 2 :* (const [] (3:))* 1 : 2 : [] On Fri, Aug 7, 2020 at 7:12 AM Austin Zhu wrote: > Hello! > > I'm learning Haskell and I found an interesting implementation of init > using foldr. However I have difficulty understand how it works. > > *init' xs = foldr f (const []) xs id* > * where f x g h = h $ g (x:)* > > Consider I have a input of *[1,2,3]*, then is would become > > *f 1 (f 2 ( f 3 (const []))) id* > > I substitute those parameters into f and the innermost one becomes *h $ > (const []) (1:)*, which is simply *h []*. However when I want to reduce > the expression further, I found it's hard to grasp. The next one becomes *f > 2 (h [])* , which is > > *h $ (h []) (2:)* > > if it works like that. This looks confusing to me. To match the type of > *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of > type *[a]*, which isn't applicable to *(2:)*. > > I also thought it in another way that *f x g* returns a function of type *([a] > -> [a]) -> [a],* this kinda makes sense considering applying *id* > afterwards. But then I realized I still don't know what this *h* is doing > here. It looks like *h* conveys *g (x:)* from last time into the next > application. > Did I miss something when I think about doing fold with function as > accumulator? > > I'd really appreciate if anyone could help me with this. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sat Aug 8 11:24:37 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Aug 2020 13:24:37 +0200 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: References: Message-ID: <20200808112437.GA15774@extensa> +1 Il 07 agosto 2020 alle 22:24 Bob Ippolito ha scritto: > I think the part that is confusing is that there are two steps here, there > is the *foldr*, and then there is the application of *id* to the result of > the *foldr*. *foldr* is of type *(a -> b -> b) -> b -> [a] -> b*, and in > your example the type for *a* is *Integer* (probably not precisely Integer, > but let's just say it is for simplicity) and the type for *b* is *[Integer] > -> [Integer]*. It would be better to think of it as *(foldr f (const []) > xs) id*. Another way to think of it is that *foldr* replaces the list *:* > constructor with the function (*f*) and the *[]* constructor with the given > *b* (*id*). Here's how I would think about the computation. In Haskell it's > usually best to start with the outside and work in, due to the non-strict > evaluation. At the end I've removed the bold from the terms that are > already completely reduced. > > *init' [1, 2, 3]* > *(foldr f (const []) (1 : 2 : 3 : [])) id* > *(1 `f` (2 `f` (3 `f` const []))) id* > *id ((2 `f` (3 `f` const [])) (1:))* > > *(2 `f` (3 `f` const [])) (1:)* > 1 :* ((3 `f` const []) (2:))* > 1 : 2 :* (const [] (3:))* > 1 : 2 : [] > > > On Fri, Aug 7, 2020 at 7:12 AM Austin Zhu wrote: > > > Hello! > > > > I'm learning Haskell and I found an interesting implementation of init > > using foldr. However I have difficulty understand how it works. > > > > *init' xs = foldr f (const []) xs id* > > * where f x g h = h $ g (x:)* > > > > Consider I have a input of *[1,2,3]*, then is would become > > > > *f 1 (f 2 ( f 3 (const []))) id* > > > > I substitute those parameters into f and the innermost one becomes *h $ > > (const []) (1:)*, which is simply *h []*. However when I want to reduce > > the expression further, I found it's hard to grasp. The next one becomes *f > > 2 (h [])* , which is > > > > *h $ (h []) (2:)* > > > > if it works like that. This looks confusing to me. To match the type of > > *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of > > type *[a]*, which isn't applicable to *(2:)*. > > > > I also thought it in another way that *f x g* returns a function of type *([a] > > -> [a]) -> [a],* this kinda makes sense considering applying *id* > > afterwards. But then I realized I still don't know what this *h* is doing > > here. It looks like *h* conveys *g (x:)* from last time into the next > > application. > > Did I miss something when I think about doing fold with function as > > accumulator? > > > > I'd really appreciate if anyone could help me with this. > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fa-ml at ariis.it Sat Aug 8 11:37:42 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Aug 2020 13:37:42 +0200 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: <20200808112437.GA15774@extensa> References: <20200808112437.GA15774@extensa> Message-ID: <20200808113742.GA22015@extensa> Il 08 agosto 2020 alle 13:24 Francesco Ariis ha scritto: > +1 This is silly me thinking I was replying to a Discourse thread liking the post… From austinzhu666 at gmail.com Sat Aug 8 16:06:33 2020 From: austinzhu666 at gmail.com (Austin Zhu) Date: Sun, 9 Aug 2020 01:06:33 +0900 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: References: Message-ID: Thank you for replying! It becomes a lot clearer now. :-) On Sat, Aug 8, 2020, 14:25 Bob Ippolito wrote: > I think the part that is confusing is that there are two steps here, there > is the *foldr*, and then there is the application of *id* to the result > of the *foldr*. *foldr* is of type *(a -> b -> b) -> b -> [a] -> b*, and > in your example the type for *a* is *Integer* (probably not precisely > Integer, but let's just say it is for simplicity) and the type for *b* is *[Integer] > -> [Integer]*. It would be better to think of it as *(foldr f (const []) > xs) id*. Another way to think of it is that *foldr* replaces the list *:* > constructor with the function (*f*) and the *[]* constructor with the > given *b* (*id*). Here's how I would think about the computation. In > Haskell it's usually best to start with the outside and work in, due to the > non-strict evaluation. At the end I've removed the bold from the terms that > are already completely reduced. > > *init' [1, 2, 3]* > *(foldr f (const []) (1 : 2 : 3 : [])) id* > *(1 `f` (2 `f` (3 `f` const []))) id* > *id ((2 `f` (3 `f` const [])) (1:))* > > *(2 `f` (3 `f` const [])) (1:)* > 1 :* ((3 `f` const []) (2:))* > 1 : 2 :* (const [] (3:))* > 1 : 2 : [] > > > On Fri, Aug 7, 2020 at 7:12 AM Austin Zhu wrote: > >> Hello! >> >> I'm learning Haskell and I found an interesting implementation of init >> using foldr. However I have difficulty understand how it works. >> >> *init' xs = foldr f (const []) xs id* >> * where f x g h = h $ g (x:)* >> >> Consider I have a input of *[1,2,3]*, then is would become >> >> *f 1 (f 2 ( f 3 (const []))) id* >> >> I substitute those parameters into f and the innermost one becomes *h $ >> (const []) (1:)*, which is simply *h []*. However when I want to reduce >> the expression further, I found it's hard to grasp. The next one becomes *f >> 2 (h [])* , which is >> >> *h $ (h []) (2:)* >> >> if it works like that. This looks confusing to me. To match the type of >> *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of >> type *[a]*, which isn't applicable to *(2:)*. >> >> I also thought it in another way that *f x g* returns a function of type *([a] >> -> [a]) -> [a],* this kinda makes sense considering applying *id* >> afterwards. But then I realized I still don't know what this *h* is >> doing here. It looks like *h* conveys *g (x:)* from last time into the >> next application. >> Did I miss something when I think about doing fold with function as >> accumulator? >> >> I'd really appreciate if anyone could help me with this. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Aug 10 01:00:10 2020 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 10 Aug 2020 08:00:10 +0700 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: References: Message-ID: On Fri, Aug 7, 2020 at 9:12 PM Austin Zhu wrote: > Hello! > > I'm learning Haskell and I found an interesting implementation of init > using foldr. However I have difficulty understand how it works. > > *init' xs = foldr f (const []) xs id* > * where f x g h = h $ g (x:)* > > Consider I have a input of *[1,2,3]*, then is would become > > *f 1 (f 2 ( f 3 (const []))) id* > > I substitute those parameters into f and the innermost one becomes *h $ > (const []) (1:)*, which is simply *h []*. However when I want to reduce > the expression further, I found it's hard to grasp. The next one becomes *f > 2 (h [])* , which is > > *h $ (h []) (2:)* > > The last line isn’t correct because of erroneous alpha capture. Modulo certain things that aren’t relevant here, the definition of the folding function f is equivalent to the eta-expansion: f x g = \h -> h (g (x:)). Note the lambda abstraction. Try substituting that in *f 1 (f 2 ( f 3 (const []))) id* to see what you get. Hint: Note how f 3 (const []) evaluates to \h -> h (const [] (3:)) = \h -> h [] = ($ []) Next f 2 ($ []) becomes \h -> h (($ []) (2:)) = \h -> h (2:[]) = ($ (2:[])) And you can see how you end up with init’ [1,2,3] = 1:(2:[]) = [1,2]. Notice how I converted from a lambda abstraction to combinator form to prevent the named lambda variable h from obscuring what’s really going on. Another way to figure out this out is by calculating the precise type of the folding function f that is provided to foldr and hence the type to h. if it works like that. This looks confusing to me. To match the type of > *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of > type *[a]*, which isn't applicable to *(2:)*. > > I also thought it in another way that *f x g* returns a function of type *([a] > -> [a]) -> [a],* this kinda makes sense considering applying *id* > afterwards. But then I realized I still don't know what this *h* is doing > here. It looks like *h* conveys *g (x:)* from last time into the next > application. > Did I miss something when I think about doing fold with function as > accumulator? > > I'd really appreciate if anyone could help me with this. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Aug 10 01:05:59 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 10 Aug 2020 03:05:59 +0200 Subject: [Haskell-beginners] Understanding functions like f a b c = c $ b a In-Reply-To: References: Message-ID: <20200810010559.GA1732@extensa> +1 Il 10 agosto 2020 alle 08:00 Kim-Ee Yeoh ha scritto: > On Fri, Aug 7, 2020 at 9:12 PM Austin Zhu wrote: > > > Hello! > > > > I'm learning Haskell and I found an interesting implementation of init > > using foldr. However I have difficulty understand how it works. > > > > *init' xs = foldr f (const []) xs id* > > * where f x g h = h $ g (x:)* > > > > Consider I have a input of *[1,2,3]*, then is would become > > > > *f 1 (f 2 ( f 3 (const []))) id* > > > > I substitute those parameters into f and the innermost one becomes *h $ > > (const []) (1:)*, which is simply *h []*. However when I want to reduce > > the expression further, I found it's hard to grasp. The next one becomes *f > > 2 (h [])* , which is > > > > *h $ (h []) (2:)* > > > > > The last line isn’t correct because of erroneous alpha capture. > > Modulo certain things that aren’t relevant here, the definition of the > folding function f is equivalent to the eta-expansion: f x g = \h -> h (g > (x:)). Note the lambda abstraction. > > Try substituting that in > > *f 1 (f 2 ( f 3 (const []))) id* > > to see what you get. > > Hint: Note how f 3 (const []) evaluates to > > \h -> h (const [] (3:)) > = \h -> h [] > = ($ []) > > Next f 2 ($ []) becomes > > \h -> h (($ []) (2:)) > = \h -> h (2:[]) > = ($ (2:[])) > > And you can see how you end up with init’ [1,2,3] = 1:(2:[]) = [1,2]. > Notice how I converted from a lambda abstraction to combinator form to > prevent the named lambda variable h from obscuring what’s really going on. > > Another way to figure out this out is by calculating the precise type of > the folding function f that is provided to foldr and hence the type to h. > > > if it works like that. This looks confusing to me. To match the type of > > *foldr*, h should be of type *[a] -> [a]* and *h []* would just be of > > type *[a]*, which isn't applicable to *(2:)*. > > > > I also thought it in another way that *f x g* returns a function of type *([a] > > -> [a]) -> [a],* this kinda makes sense considering applying *id* > > afterwards. But then I realized I still don't know what this *h* is doing > > here. It looks like *h* conveys *g (x:)* from last time into the next > > application. > > Did I miss something when I think about doing fold with function as > > accumulator? > > > > I'd really appreciate if anyone could help me with this. > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > -- > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From alexander at chenjia.nl Thu Aug 13 11:02:19 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Thu, 13 Aug 2020 13:02:19 +0200 (CEST) Subject: [Haskell-beginners] IO operations Message-ID: <252977439.222507.1597316539010@ichabod.co-bxl> Hi, module Main where allwords :: IO Int allwords  = do     dict <- readFile "data/dict.txt"     return  $ length [x | x <- dict , not $ '-' `elem` x]      main :: IO Int main = do allwords error * Couldn't match expected type `t0 Char' with actual type `Char' * In the second argument of `elem', namely `x'   In the second argument of `($)', namely '-' `elem` x   In the expression: not $ '-' `elem` x could someone tell me what I am doing wrong? thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Aug 13 11:19:26 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 13 Aug 2020 13:19:26 +0200 Subject: [Haskell-beginners] IO operations In-Reply-To: <252977439.222507.1597316539010@ichabod.co-bxl> References: <252977439.222507.1597316539010@ichabod.co-bxl> Message-ID: <20200813111926.GC2065@extensa> Hello Alexander Il 13 agosto 2020 alle 13:02 Alexander Chen ha scritto: > allwords :: IO Int > allwords  = do >     dict <- readFile "data/dict.txt" >     return  $ length [x | x <- dict , not $ '-' `elem` x] `elem` has type: λ> :t elem elem :: Eq a => a -> [a] -> Bool -- almost You are comparing '-' (a `Char`) with `x` (another `Char`), hence you only need `==`. Does this make sense? —F From alexander at klink.name Thu Aug 13 11:24:00 2020 From: alexander at klink.name (Alexander Klink) Date: Thu, 13 Aug 2020 13:24:00 +0200 Subject: [Haskell-beginners] IO operations In-Reply-To: <252977439.222507.1597316539010@ichabod.co-bxl> References: <252977439.222507.1597316539010@ichabod.co-bxl> Message-ID: <20200813112400.GN20834@putna.0x90.eu> On Thu, Aug 13, 2020 at 01:02:19PM +0200, Alexander Chen wrote: > module Main where > > allwords :: IO Int > allwords  = do >     dict <- readFile "data/dict.txt" >     return  $ length [x | x <- dict , not $ '-' `elem` x] >      > main :: IO Int > main = do allwords > > error > > * Couldn't match expected type `t0 Char' with actual type `Char' > * In the second argument of `elem', namely `x' >   In the second argument of `($)', namely '-' `elem` x >   In the expression: not $ '-' `elem` x > > could someone tell me what I am doing wrong? dict is of type String, since it's a String containing the complete file. That's why the type complaint is that you want to check if '-' (a Char) is an element of x, which is also a Char, which cannot work. I asssume what you want is a list of lines, which you can by applying the lines function, e.g. here:     return  $ length [x | x <- lines dict , not $ '-' `elem` x] HTH, Cheers, Alex From to_br at uni-bremen.de Thu Aug 13 11:14:39 2020 From: to_br at uni-bremen.de (Tobias Brandt) Date: Thu, 13 Aug 2020 13:14:39 +0200 Subject: [Haskell-beginners] IO operations In-Reply-To: <252977439.222507.1597316539010@ichabod.co-bxl> References: <252977439.222507.1597316539010@ichabod.co-bxl> Message-ID: <778b310a-184c-f604-491d-7e74bb3dee08@uni-bremen.de> Hey Alexander, |dict| has type |String|. Therefore, |x| is of type |Char|, but |elem '-'| is of type |[Char] -> Bool| (simplified). Hence, you get a type mismatch. If you just want to count every character except |'-'|, then you could just you |'-' /= x|. Cheers Tobias On 8/13/20 1:02 PM, Alexander Chen wrote: > Hi, > > module Main where > allwords :: IO Int > allwords  = do >     dict <- readFile "data/dict.txt" >     return  $ length [x | x <- dict , not $ '-' `elem` x] > main :: IO Int > main = do allwords > > error > > * Couldn't match expected type `t0 Char' with actual type `Char' > * In the second argument of `elem', namely `x' >   In the second argument of `($)', namely '-' `elem` x >   In the expression: not $ '-' `elem` x > > > could someone tell me what I am doing wrong? > > thanks! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From traqueofziche at gmail.com Fri Aug 14 01:23:02 2020 From: traqueofziche at gmail.com (=?UTF-8?B?6bKN5Yev5paH?=) Date: Thu, 13 Aug 2020 18:23:02 -0700 Subject: [Haskell-beginners] IO operations In-Reply-To: References: Message-ID: Hi, > * Couldn't match expected type `t0 Char' with actual type `Char' > * In the second argument of `elem', namely `x' > In the second argument of `($)', namely '-' `elem` x > In the expression: not $ '-' `elem` x Hope the other answers helped. FWIW, just wanted to point out that for me these kinds of error messages sometimes used to be confusing since the type of `elem` is `(Foldable t, Eq a) => a -> t a -> Bool`, so the typechecker tells you it wants to unify `t0 Char` (where `t0` is something `Foldable`) with `Char`. As Mr. Klink wrote, it looks like you wanted `t0` to be `[]`; I used to get confused since I was only working with lists and the extra `Foldable` genericity made it harder to see that I was still just working with lists. Best, toz > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander at chenjia.nl Wed Aug 19 13:41:38 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Wed, 19 Aug 2020 15:41:38 +0200 (CEST) Subject: [Haskell-beginners] Text.Regex.Posix Message-ID: <81146234.623150.1597844498292@ichabod.co-bxl> Hi, cabal install regex-posix runs without issue. added it to cabal dependencies: name:                data-regex version:             0.1.0.0 -- synopsis: -- description: homepage:            https://github.com/githubuser/data-regex#readme license:             BSD3 license-file:        LICENSE author:              Alexander Chen maintainer:          example at example.com copyright:           2020 Alexander Chen category:            regex build-type:          Simple cabal-version:       >=1.10 extra-source-files:  README.md executable data-regex   hs-source-dirs:      src   main-is:             Main.hs   default-language:    Haskell2010   build-depends:       base >= 4.7 && < 5, regex-posix  Then I do: stack install regex-posix error> WARNING: Ignoring regex-posix's bounds on base (<0 && >=4.3 && <4.15); using base-4.13.0.0. Reason: trusting snapshot over cabal file dependency information. regex-posix> configure regex-posix> Configuring regex-posix-0.96.0.0... regex-posix> build regex-posix> Preprocessing library for regex-posix-0.96.0.0.. regex-posix> C:\Users\achen\AppData\Local\Temp\stack-e2b99a8a9eb45aea\regex-posix-0.96.0.0\Wrap.hsc:96:10: fatal error: regex.h: No such file or directory regex-posix> compilation terminated. regex-posix> compiling .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c failed (exit code 1) regex-posix> command was: C:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\../mingw/bin\gcc.exe -c .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=808 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\cbits -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\autogen -I.stack-work\dist\29cc6475\build\global-autogen -include .stack-work\dist\29cc6475\build\autogen\cabal_macros.h -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\bytestring-0.10.10.0\include -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\base-4.13.0.0\include -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\integer-gmp-1.0.2.0\include -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib/include -IC:\Users\achen\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3/lib/include/ --  While building package regex-posix-0.96.0.0 using:       C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.3.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options " -fdiagnostics-color=always"           Process exited with code: ExitFailure 1 Progress 1/2 ========================================================================================================================================================================================= I also get an error in my main(but seems related): module Main where import Text.Regex.Posix main :: IO () main = do   let str1 = "one fish two fish red fish blue fish"   let str2 = "The quick brown fox jumps over the lazy dog."   print str1 =~ "one" ::Bool What am I doing wrong? best, -------------- next part -------------- An HTML attachment was scrubbed... URL: From joshuatfriedlander at gmail.com Thu Aug 20 19:02:21 2020 From: joshuatfriedlander at gmail.com (Josh Friedlander) Date: Thu, 20 Aug 2020 22:02:21 +0300 Subject: [Haskell-beginners] Clarifying $ vs parentheses Message-ID: I understand that in general $ is a) right-associative and b) lowest-priority. But if so shouldn't these two be roughly the same? λ take (succ 10) $ cycle "hello world" "hello world" But not this? λ take $ succ 10 $ cycle "hello world" :20:8: error: • No instance for (Enum ([Char] -> Int)) arising from a use of ‘succ’ (maybe you haven't applied a function to enough arguments?) • In the expression: succ 10 In the second argument of ‘($)’, namely ‘succ 10 $ cycle "hello world"’ In the expression: take $ succ 10 $ cycle "hello world" :20:13: error: • No instance for (Num ([Char] -> Int)) arising from the literal ‘10’ (maybe you haven't applied a function to enough arguments?) • In the first argument of ‘succ’, namely ‘10’ In the expression: succ 10 In the second argument of ‘($)’, namely ‘succ 10 $ cycle "hello world"’ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Thu Aug 20 19:36:24 2020 From: bob at redivi.com (Bob Ippolito) Date: Thu, 20 Aug 2020 12:36:24 -0700 Subject: [Haskell-beginners] Clarifying $ vs parentheses In-Reply-To: References: Message-ID: Because the second one is: take (succ 10 (cycle “hello world”)) On Thu, Aug 20, 2020 at 12:03 Josh Friedlander wrote: > I understand that in general $ is a) right-associative and b) > lowest-priority. But if so shouldn't these two be roughly the same? > > λ take (succ 10) $ cycle "hello world" > "hello world" > > But not this? > λ take $ succ 10 $ cycle "hello world" > > :20:8: error: > • No instance for (Enum ([Char] -> Int)) > arising from a use of ‘succ’ > (maybe you haven't applied a function to enough arguments?) > • In the expression: succ 10 > In the second argument of ‘($)’, namely > ‘succ 10 $ cycle "hello world"’ > In the expression: take $ succ 10 $ cycle "hello world" > > :20:13: error: > • No instance for (Num ([Char] -> Int)) > arising from the literal ‘10’ > (maybe you haven't applied a function to enough arguments?) > • In the first argument of ‘succ’, namely ‘10’ > In the expression: succ 10 > In the second argument of ‘($)’, namely > ‘succ 10 $ cycle "hello world"’ > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Aug 20 19:40:31 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 20 Aug 2020 21:40:31 +0200 Subject: [Haskell-beginners] Clarifying $ vs parentheses In-Reply-To: References: Message-ID: <20200820194031.GA30551@extensa> Hello Josh, il 20 agosto 2020 alle 22:02 josh friedlander ha scritto: > i understand that in general $ is a) right-associative and b) > lowest-priority. but if so shouldn't these two be roughly the same? > > λ take (succ 10) $ cycle "hello world" > "hello world" > > But not this? > λ take $ succ 10 $ cycle "hello world" > > […] λ> :info ($) ($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’ infixr 0 $ So, since `$` is right associative, the expression take $ succ 10 $ cycle "hello world" becomes take (succ 10 (cycle "hello world")) `cycle "hello world"` makes sense, `succ 10` makes sense, `succ 10 anotherArgument` does not. Even `take someStuff` is probably not what you want, since take is usually invoked with two arguments. A useful intuition when you see ($) is `it will evaluate everything on the right of it first`. This way, `not $ xx yy zz` looks right, `take $ xx aa yy qq` less so. Does this help? —F