From alexander at chenjia.nl Fri Apr 17 07:19:50 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Fri, 17 Apr 2020 09:19:50 +0200 (CEST) Subject: [Haskell-beginners] '/' instead use 'DIV'. why? Message-ID: <477560727.1425642.1587107989976@ichabod.co-bxl> Hi,  Prelude> :t (/) (/) :: Fractional a => a -> a -> a Prelude> :t div div :: Integral a => a -> a -> a Prelude> 6 / length [23,34,45] error  Prelude> 6 / 3 2.0 Could somebody explain to me why this is? thanks, Alexander Chen -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Fri Apr 17 08:10:46 2020 From: utprimum at gmail.com (Ut Primum) Date: Fri, 17 Apr 2020 10:10:46 +0200 Subject: [Haskell-beginners] '/' instead use 'DIV'. why? In-Reply-To: <477560727.1425642.1587107989976@ichabod.co-bxl> References: <477560727.1425642.1587107989976@ichabod.co-bxl> Message-ID: Hi, as you said, the operator (/) takes arguments that belong to the class *Fractional* (instances of this class are the types *Double* and *Float*). The function length has type: Prelude> :t length length :: Foldable t => t a -> Int this means that it takes a list and returns something of type Int, In fact Prelude> :t (length [23,34,45]) (length [23,34,45]) :: Int Since Int is *not* an instance of the class Fractional, you can't use (/). Instead Int is an instance of the class Integral, so you can use div with arguments of type Int. The example 6/3 works because you didn't assign any type to those numbers, so they are seen as belonging to the class Num. Prelude> x=6 Prelude> :t x x :: Num p => p This means that they can be seen both as Integral and Fractional and you can use them with both functions that take Integral arguments and functions that take Fractional arguments. If you specify that for example 6 is an Int you can't use (/) any more: Prelude> x::Int; x=6; Prelude> x/3 :20:1: error: • No instance for (Fractional Int) arising from a use of ‘/’ >From the error message you can see that the problem is as I said before that Int is not an instace of the class Fractional. Hope is clear Best, Ut Il ven 17 apr 2020, 09:20 Alexander Chen ha scritto: > Hi, > > > Prelude> :t (/) > (/) :: *Fractional* a => a -> a -> a > > Prelude> :t div > div :: *Integral* a => a -> a -> a > > > Prelude> 6 / length [23,34,45] > error > > Prelude> 6 / 3 > 2.0 > > Could somebody explain to me why this is? > > thanks, > > Alexander Chen > > > > _______________________________________________ > 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 amindfv at gmail.com Fri Apr 17 19:42:46 2020 From: amindfv at gmail.com (amindfv at gmail.com) Date: Fri, 17 Apr 2020 15:42:46 -0400 Subject: [Haskell-beginners] '/' instead use 'DIV'. why? In-Reply-To: <477560727.1425642.1587107989976@ichabod.co-bxl> References: <477560727.1425642.1587107989976@ichabod.co-bxl> Message-ID: <8A974EAD-B22E-44E3-9974-FF16B19F7A6D@gmail.com> It might help to imagine if you flip your arguments: length [23, 34, 45] / 6 :: Int How do you represent 3/6 as an Int? > El 17 abr 2020, a las 03:19, Alexander Chen escribió: > > Hi, > > > Prelude> :t (/) > (/) :: Fractional a => a -> a -> a > > Prelude> :t div > div :: Integral a => a -> a -> a > > > Prelude> 6 / length [23,34,45] > error > > Prelude> 6 / 3 > 2.0 > > Could somebody explain to me why this is? > > thanks, > > Alexander Chen > > > > _______________________________________________ > 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 alexander at chenjia.nl Fri Apr 17 19:56:16 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Fri, 17 Apr 2020 21:56:16 +0200 (CEST) Subject: [Haskell-beginners] Why the compiler does not commit to a type class? Message-ID: <1426914449.1477761.1587153376296@ichabod.co-bxl> hi, Prelude> u = undefined Prelude> k :: (Ord a, Num b) => a -> b -> a; k = u Prelude> :t k 1 2  k 1 2 :: (Ord a, Num a) => a Prelude> :t k (1 :: Integer) 2 k (1 :: Integer) 2 :: Integer In the first version the compiler is not really pushed so it simply gives back the type class constriction it has to adhere to. While in the second it is pushed to give an more specific answer and thus the :: Integer. Question: Is this train of thought correct?  -------------- next part -------------- An HTML attachment was scrubbed... URL: From jasonsychau at gmail.com Fri Apr 17 20:00:28 2020 From: jasonsychau at gmail.com (Jason Chau) Date: Fri, 17 Apr 2020 13:00:28 -0700 Subject: [Haskell-beginners] Why the compiler does not commit to a type class? In-Reply-To: <1426914449.1477761.1587153376296@ichabod.co-bxl> References: <1426914449.1477761.1587153376296@ichabod.co-bxl> Message-ID: Yes - if you look at the number types, you will find different number types and not integer types are providing support that’s not in Integer, so compiler is giving safest assumption. Sent from my iPhone > On Apr 17, 2020, at 12:56 PM, Alexander Chen wrote: > >  > hi, > > Prelude> u = undefined > Prelude> k :: (Ord a, Num b) => a -> b -> a; k = u > > Prelude> :t k 1 2 > k 1 2 :: (Ord a, Num a) => a > > Prelude> :t k (1 :: Integer) 2 > k (1 :: Integer) 2 :: Integer > > In the first version the compiler is not really pushed so it simply gives back the type class constriction it has to adhere to. While in the second it is pushed to give an more specific answer and thus the :: Integer. > > Question: > Is this train of thought correct? > > > > _______________________________________________ > 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 dekudekuplex at yahoo.com Sat Apr 18 15:58:47 2020 From: dekudekuplex at yahoo.com (Benjamin L. Russell) Date: Sat, 18 Apr 2020 15:58:47 +0000 (UTC) Subject: [Haskell-beginners] [ANN] Haskell Beginners WT.Social Community: "Haskell: The Haskell-Beginners Community" References: <1834775399.2757836.1587225527048.ref@mail.yahoo.com> Message-ID: <1834775399.2757836.1587225527048@mail.yahoo.com> Twenty-eight days ago (on March 23, 2020 JST), I created a new Haskell beginners WT.Social community, "Haskell: The Haskell-Beginners Community" (see https://pashpost.com/group/haskell-the-haskell-beginners-community), and migrated a substantial portion of the posts originally from my former corresponding pashPOST (since renamed to "theTUNDRA") community of the same name thereto (sansposts with missing links or irrelevant content). Feel free to join and contribute! -- Benjamin L. Russell -- Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com http://dekude kuplex.wordpress.com/ Computer Science Document Translator/Editor "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander at chenjia.nl Wed Apr 22 18:10:23 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Wed, 22 Apr 2020 20:10:23 +0200 (CEST) Subject: [Haskell-beginners] instance Message-ID: <2038347538.89633.1587579022984@ichabod.co-bxl> Hi, data TisanInteger = Tisan Integer instance Eq (Tisan Integer) where (Tisan v) == (Tisan v') = v == v' prelude> Instance_testen.hs:7:14: error:     Not in scope: type constructor or class ‘Tisan’     A data constructor of that name is in scope; did you mean DataKinds?   | 7 | instance Eq (Tisan Integer) where (Tisan v) == (Tisan v') = v == v'   |              ^^^^^ [1 of 1] Compiling Main             ( Instance_testen.hs, interpreted ) Failed, no modules loaded. what am i doing wrong? best, -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Wed Apr 22 18:20:57 2020 From: utprimum at gmail.com (Ut Primum) Date: Wed, 22 Apr 2020 20:20:57 +0200 Subject: [Haskell-beginners] instance In-Reply-To: <2038347538.89633.1587579022984@ichabod.co-bxl> References: <2038347538.89633.1587579022984@ichabod.co-bxl> Message-ID: Hi, data TisanInteger = Tisan Integer instance Eq (*Tisan Integer*) where (Tisan v) == (Tisan v') = v == v' I think the part in red is the error: you should write *TisanInteger* instead (with no space between Tisan and Integer): This is because there you should put the name of the data, not its definition. Best, Ut Il giorno mer 22 apr 2020 alle ore 20:11 Alexander Chen < alexander at chenjia.nl> ha scritto: > Hi, > > > *data TisanInteger = Tisan Integer* > > *instance Eq (Tisan Integer) where (Tisan v) == (Tisan v') = v == v'* > > *prelude>* > *Instance_testen.hs:7:14: error:* > * Not in scope: type constructor or class ‘Tisan’* > * A data constructor of that name is in scope; did you mean DataKinds?* > * |* > *7 | instance Eq (Tisan Integer) where (Tisan v) == (Tisan v') = v == v' > | ^^^^^* > *[1 of 1] Compiling Main ( Instance_testen.hs, interpreted )* > *Failed, no modules loaded.* > > > > what am i doing wrong? > > best, > > _______________________________________________ > 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 alexander at chenjia.nl Wed Apr 22 19:13:58 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Wed, 22 Apr 2020 21:13:58 +0200 (CEST) Subject: [Haskell-beginners] instance 2 Message-ID: <340361797.93178.1587582838047@ichabod.co-bxl> hi, data StringOrInt = TisanInt Int | TisAString String instance Eq (StringOrInt) where  (==) (TisanInt v) (TisanInt v') = v == v' (==) (TisAString s) (TisAString s') = s == s' prelude> Instance_testen.hs:4:37: error:     Ambiguous occurrence ‘==’     It could refer to either ‘Prelude.==’,                              imported from ‘Prelude’ at Instance_testen.hs:1:1                              (and originally defined in ‘GHC.Classes’)                           or ‘Main.==’, defined at Instance_testen.hs:4:1   | 4 | (==) (TisanInt v) (TisanInt v') = v == v'   |                                     ^^ Instance_testen.hs:5:41: error:     Ambiguous occurrence ‘==’     It could refer to either ‘Prelude.==’,                              imported from ‘Prelude’ at Instance_testen.hs:1:1                              (and originally defined in ‘GHC.Classes’)                           or ‘Main.==’, defined at Instance_testen.hs:4:1   | 5 | (==) (TisAString s) (TisAString s') = s == s'    |                                         ^^ [1 of 1] Compiling Main             ( Instance_testen.hs, interpreted ) Failed, no modules loaded. what gives? -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Wed Apr 22 19:49:46 2020 From: utprimum at gmail.com (Ut Primum) Date: Wed, 22 Apr 2020 21:49:46 +0200 Subject: [Haskell-beginners] instance 2 In-Reply-To: <340361797.93178.1587582838047@ichabod.co-bxl> References: <340361797.93178.1587582838047@ichabod.co-bxl> Message-ID: Hi, I think the problem is indentation. Write the code this way: data StringOrInt = TisanInt Integer | TisAString String instance Eq (StringOrInt) where (==) (TisanInt v) (TisanInt v') = v == v' (==) (TisAString s) (TisAString s') = s==s' where the red lines are indented (it means you have to leave two white spaces at the beginning of those lines). Ut Il giorno mer 22 apr 2020 alle ore 21:14 Alexander Chen < alexander at chenjia.nl> ha scritto: > hi, > > *data StringOrInt = TisanInt Int | TisAString String* > > *instance Eq (StringOrInt) where * > *(==) (TisanInt v) (TisanInt v') = v == v'* > *(==) (TisAString s) (TisAString s') = s == s'* > > > *prelude>* > > *Instance_testen.hs:4:37: error:* > * Ambiguous occurrence ‘==’* > * It could refer to either ‘Prelude.==’,* > * imported from ‘Prelude’ at > Instance_testen.hs:1:1* > * (and originally defined in ‘GHC.Classes’)* > * or ‘Main.==’, defined at Instance_testen.hs:4:1* > * |* > *4 | (==) (TisanInt v) (TisanInt v') = v == v' | > ^^* > > *Instance_testen.hs:5:41: error:* > * Ambiguous occurrence ‘==’* > * It could refer to either ‘Prelude.==’,* > * imported from ‘Prelude’ at > Instance_testen.hs:1:1* > * (and originally defined in ‘GHC.Classes’)* > * or ‘Main.==’, defined at Instance_testen.hs:4:1* > * |* > *5 | (==) (TisAString s) (TisAString s') = s == s' * > * | ^^* > *[1 of 1] Compiling Main ( Instance_testen.hs, interpreted )* > *Failed, no modules loaded.* > > > > *what gives?* > _______________________________________________ > 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 ken.overton at gmail.com Sun Apr 26 12:50:20 2020 From: ken.overton at gmail.com (Ken Overton) Date: Sun, 26 Apr 2020 08:50:20 -0400 Subject: [Haskell-beginners] List comprehensions with multiple generators Message-ID: Hello all, I recently came across this function which made me realize I don't understand list comprehensions well. I hope someone can help me understand them better by understanding this example better. The function takes a list of Eq and returns the list of unique elements from it: unique :: Eq a => [a] -> [a] unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)] It's using a list comprehension with multiple 'generators' (hope I have the term correctly). My understanding of multiple generators in a list comprehension is that they refine the results of the previous generator. So the first generator should produce [(Eq,Int)] as input to the second generator? And the second generator should produce [Bool]? My understanding must be wrong though; how do we end up with just the items where the second generator produced True? Thanks, -- Ken Overton (917) 863-3937 ken.overton at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Sun Apr 26 13:35:55 2020 From: utprimum at gmail.com (Ut Primum) Date: Sun, 26 Apr 2020 15:35:55 +0200 Subject: [Haskell-beginners] List comprehensions with multiple generators In-Reply-To: References: Message-ID: Hi, I'll try to explain the meaning of different parts of the comprehension:: unique xs = [x | *(x,y) <- zip xs [0..]*, x `notElem` (take y xs)] *this* part means: consider the couples (x,y) that are output of zip xs [0..] for example if xs = [10,20,10,30,30], you are taking [(10,0),(20,1),(10,2),(30,3),(30,4)] unique xs = [x | (x,y) <- zip xs [0..], *x `notElem` (take y xs)*] *this* part means: among the things you considered before (i.e. all the couples obtained before), consider only those that satisfy the property that the first element of (x,y) is not an alement of a certain list (take y xs, i.e. the first y elements of xs). So in the example above: is 10 an element of (take 0 xs)=[ ] ? No ----> we consider (10,0) is 20 an element of (take 1 xs)=[10]? No ----> we consider (20,1) is 10 an element of (take 2 xs)=[10,20]? Yes ----> we DON'T consider (10,2) is 30 an element of (take 3 xs)=[10,20,10]? No ----> we consider (30,3) is 30 an element of (take 4 xs)=[10,20,10,30]? Yes ----> we DON'T consider (30,4) So we are considering only [(10,0),(20,1),(30,3)] So as you said this is a refinement of the elements generated by the first generator. A refinement means that some of the elements generated before are (possibly) discarded, so you don't obtain a [Bool], but something of the same type of what was generated before, i.e. another [(Eq,Int)] possibly shorter than the previous one. Finally unique xs =* [x |* (x,y) <- zip xs [0..], x `notElem` (take y xs)] *this* part says that, of each couple produced and refined before, you take the first element (that was called x). So in the example you get [10,20,30] Hope this is clear, Ut Il giorno dom 26 apr 2020 alle ore 14:51 Ken Overton ha scritto: > Hello all, > > I recently came across this function which made me realize I don't > understand list comprehensions well. I hope someone can help me understand > them better by understanding this example better. The function takes a list > of Eq and returns the list of unique elements from it: > > unique :: Eq a => [a] -> [a] > unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)] > > It's using a list comprehension with multiple 'generators' (hope I have > the term correctly). My understanding of multiple generators in a list > comprehension is that they refine the results of the previous generator. > > So the first generator should produce [(Eq,Int)] as input to the second > generator? And the second generator should produce [Bool]? > > My understanding must be wrong though; how do we end up with just the > items where the second generator produced True? > > Thanks, > > > -- > Ken Overton > (917) 863-3937 > ken.overton at gmail.com > > _______________________________________________ > 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 Sun Apr 26 13:39:13 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Apr 2020 15:39:13 +0200 Subject: [Haskell-beginners] List comprehensions with multiple generators In-Reply-To: References: Message-ID: <20200426133913.GA25630@extensa> Hello Ken, On Sun, Apr 26, 2020 at 08:50:20AM -0400, Ken Overton wrote: > I recently came across this function which made me realize I don't > understand list comprehensions well. I hope someone can help me understand > them better by understanding this example better. The function takes a list > of Eq and returns the list of unique elements from it: > > unique :: Eq a => [a] -> [a] > unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)] > > > [...] > > So the first generator should produce [(Eq,Int)] as input to the second > generator? And the second generator should produce [Bool]? 1. (x,y) <- zip xs [0..] -- generates a list of pairs. 2. x `notElem` (take y xs) -- acts like a guard to 1., so only the `x`s which are not in the first `y` elements of `xs` (in other words, the previous elements of `xs`) will be returned. The examples on the wiki [1] show more way of using list comprehensions. [1] https://wiki.haskell.org/List_comprehension#Examples From ken.overton at gmail.com Sun Apr 26 14:26:48 2020 From: ken.overton at gmail.com (Ken Overton) Date: Sun, 26 Apr 2020 10:26:48 -0400 Subject: [Haskell-beginners] List comprehensions with multiple generators In-Reply-To: <20200426133913.GA25630@extensa> References: <20200426133913.GA25630@extensa> Message-ID: I see now, thanks to both of you; I think I was thrown off by the term 'generators' -- the 'refinement' provided by the second generator is more like filter rather than map. I guess if I actually wanted the case all the pairs were evaluated and resulted in [Bool] where the first occurrence of an item were True, rather than multiple generators I would have two nested list comprehensions? Thanks everyone, On Sun, Apr 26, 2020 at 9:39 AM Francesco Ariis wrote: > Hello Ken, > > On Sun, Apr 26, 2020 at 08:50:20AM -0400, Ken Overton wrote: > > I recently came across this function which made me realize I don't > > understand list comprehensions well. I hope someone can help me > understand > > them better by understanding this example better. The function takes a > list > > of Eq and returns the list of unique elements from it: > > > > unique :: Eq a => [a] -> [a] > > unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)] > > > > > > [...] > > > > So the first generator should produce [(Eq,Int)] as input to the second > > generator? And the second generator should produce [Bool]? > > 1. (x,y) <- zip xs [0..] -- generates a list of pairs. > 2. x `notElem` (take y xs) -- acts like a guard to 1., so only the `x`s > which are not in the first `y` elements of `xs` (in other words, the > previous elements of `xs`) will be returned. > > The examples on the wiki [1] show more way of using list > comprehensions. > > [1] https://wiki.haskell.org/List_comprehension#Examples > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Ken Overton (917) 863-3937 ken.overton at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Apr 27 02:18:07 2020 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 27 Apr 2020 04:18:07 +0200 Subject: [Haskell-beginners] List comprehensions with multiple generators In-Reply-To: References: <20200426133913.GA25630@extensa> Message-ID: <20200427021807.GA21809@extensa> On Sun, Apr 26, 2020 at 10:26:48AM -0400, Ken Overton wrote: > I guess if I actually wanted the case all the pairs were evaluated and > resulted in [Bool] where the first occurrence of an item were True, rather > than multiple generators I would have two nested list comprehensions? I am not sure I understand what you are trying to achieve, but there is always the possibility of bringing the `y` and the "filter" before the guard: uniqueInternal :: Eq a => [a] -> [(a, Int, Bool)] uniqueInternal xs = [(x,y, x `notElem` take y xs) | (x,y) <- zip xs [0..]] From cledbetter1 at yahoo.com Mon Apr 27 12:08:45 2020 From: cledbetter1 at yahoo.com (Christopher Ledbetter) Date: Mon, 27 Apr 2020 08:08:45 -0400 Subject: [Haskell-beginners] Unsubscribe References: <0F16EC3F-F6D8-4CA9-9149-8CDD19C0DB73.ref@yahoo.com> Message-ID: <0F16EC3F-F6D8-4CA9-9149-8CDD19C0DB73@yahoo.com> Unsubscribe Sent from my iPad > On Apr 26, 2020, at 8:51 AM, Ken Overton wrote: > >  > Hello all, > > I recently came across this function which made me realize I don't understand list comprehensions well. I hope someone can help me understand them better by understanding this example better. The function takes a list of Eq and returns the list of unique elements from it: > > unique :: Eq a => [a] -> [a] > unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)] > > It's using a list comprehension with multiple 'generators' (hope I have the term correctly). My understanding of multiple generators in a list comprehension is that they refine the results of the previous generator. > > So the first generator should produce [(Eq,Int)] as input to the second generator? And the second generator should produce [Bool]? > > My understanding must be wrong though; how do we end up with just the items where the second generator produced True? > > Thanks, > > > -- > Ken Overton > (917) 863-3937 > ken.overton at gmail.com > > _______________________________________________ > 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 alexander at chenjia.nl Tue Apr 28 19:21:16 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Tue, 28 Apr 2020 21:21:16 +0200 (CEST) Subject: [Haskell-beginners] It needs a binder? Message-ID: <349773461.111559.1588101675973@ichabod.co-bxl> Hi, binder.hs i:: Num a => a prelude>:l binder.hs typed_checked.hs:1:1: error:     The type signature for ‘i’ lacks an accompanying binding   | 1 | i:: Num a=> a   | ^ binder.hs i:: Num a => a i = 2 prelude>:l binder.hs [1 of 1] Compiling Main              Ok, one module loaded. Why does it need a binder to make it work? -------------- next part -------------- An HTML attachment was scrubbed... URL: From exitconsole at gmail.com Wed Apr 29 08:46:13 2020 From: exitconsole at gmail.com (=?UTF-8?B?RMOhbmllbCBBcmF0w7M=?=) Date: Wed, 29 Apr 2020 10:46:13 +0200 Subject: [Haskell-beginners] It needs a binder? In-Reply-To: <349773461.111559.1588101675973@ichabod.co-bxl> References: <349773461.111559.1588101675973@ichabod.co-bxl> Message-ID: Using classic C/C++/Java terms what you're doing in the first version is analogous to _declaring_ a function but not _defining_ it, e.g. // binding_incorrect.c int i(); // No definition leads to an error // binding_correct.c int i() { return 0; } The error message says that you have declared the type of i to be Num a => a, but no corresponding definition was found. That's the reason your second version compiles fine On Tue, 28 Apr 2020 at 21:22, Alexander Chen wrote: > Hi, > > binder.hs > > i:: Num a => a > > *prelude>*:l binder.hs > typed_checked.hs:1:1: error: > The type signature for ‘i’ lacks an accompanying binding > | > 1 | i:: Num a=> a | ^ > > > binder.hs > > i:: Num a => a > i = 2 > > *prelude>*:l binder.hs > [1 of 1] Compiling Main > Ok, one module loaded. > > > Why does it need a binder to make it work? > > > > _______________________________________________ > 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 alexander at chenjia.nl Wed Apr 29 19:34:35 2020 From: alexander at chenjia.nl (Alexander Chen) Date: Wed, 29 Apr 2020 21:34:35 +0200 (CEST) Subject: [Haskell-beginners] why does the superclass not work? Message-ID: <120272377.203134.1588188875803@ichabod.co-bxl> Hi, superclass.hs myX = 1 :: Int sigmund  :: Int -> Int  sigmund x = myX prelude> :l superclass.hs [1 of 1] Compiling Main  Ok, one module loaded. ================================================================================== superclass.hs myX = 1 :: Int sigmund  :: Num -> Num  sigmund x = myX prelude> :l superclass.hs typed_checked.hs:3:13: error:     • Expecting one more argument to ‘Num’       Expected a type, but ‘Num’ has kind ‘* -> Constraint’     • In the type signature: sigmund :: Num -> Num   | 3 | sigmund  :: Num -> Num    |             ^^^ typed_checked.hs:3:20: error:     • Expecting one more argument to ‘Num’       Expected a type, but ‘Num’ has kind ‘* -> Constraint’     • In the type signature: sigmund :: Num -> Num =================================================================================== I would think since Num is a superclass of Int defining the type in the superclass would be OK, also in the error message it refers to (see black) what does that refer to? thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mihai.maruseac at gmail.com Wed Apr 29 20:11:54 2020 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Wed, 29 Apr 2020 13:11:54 -0700 Subject: [Haskell-beginners] why does the superclass not work? In-Reply-To: <120272377.203134.1588188875803@ichabod.co-bxl> References: <120272377.203134.1588188875803@ichabod.co-bxl> Message-ID: Hi. Num is not a superclass of Int. Int is a type whereas Num is a type of a type. The fix would be sigmund :: Num a => a -> a ... This signature means "sigmund has type a to a where a is constrained to be a type variable of type Num" (so Num is the type of the type variable a) On Wed, Apr 29, 2020 at 12:41 PM Alexander Chen wrote: > > Hi, > > superclass.hs > > myX = 1 :: Int > > sigmund :: Int -> Int > sigmund x = myX > > > prelude> :l superclass.hs > [1 of 1] Compiling Main > Ok, one module loaded. > > ================================================================================== > > superclass.hs > > myX = 1 :: Int > > sigmund :: Num -> Num > sigmund x = myX > > prelude> :l superclass.hs > typed_checked.hs:3:13: error: > • Expecting one more argument to ‘Num’ > Expected a type, but ‘Num’ has kind ‘* -> Constraint’ > • In the type signature: sigmund :: Num -> Num > | > 3 | sigmund :: Num -> Num | ^^^ > > typed_checked.hs:3:20: error: > • Expecting one more argument to ‘Num’ > Expected a type, but ‘Num’ has kind ‘* -> Constraint’ > • In the type signature: sigmund :: Num -> Num > > > =================================================================================== > > I would think since Num is a superclass of Int defining the type in the superclass would be OK, also in the error message it refers to (see black) what does that refer to? > > thanks! > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya