From grdvnl at gmail.com Sun Oct 1 01:36:11 2017 From: grdvnl at gmail.com (Guru Devanla) Date: Sat, 30 Sep 2017 18:36:11 -0700 Subject: [Haskell-beginners] Loading a ~200 column CSV file in Haskell into a Record structure Message-ID: Hello All, I am in the process of replicating some code in Python in Haskell. In Python, I load a couple of csv files, each file having more than 100 columns into a Pandas' data frame. Panda's data-frame, in short is a tabular structure which lets me performs on bunch of joins, and filter out data. I generated different shapes of reports using these operations. Of course, I would love some type checking to help me with these merge, join operations as I create different reports. I am not looking to replicate the Pandas data-frame functionality in Haskell. First thing I want to do is reach out to the 'record' data structure. Here are some ideas I have: 1. I need to declare all these 100+ columns into multiple record structures. 2. Some of the columns can have NULL/NaN values. Therefore, some of the attributes of the record structure would be 'MayBe' values. Now, I could drop some columns during load and cut down the number of attributes i created per record structure. 3. Create a dictionary of each record structure which will help me index into into them.' I would like some feedback on the first 2 points. Seems like there is a lot of boiler plate code I have to generate for creating 100s of record attributes. Is this the only sane way to do this? What other patterns should I consider while solving such a problem. Also, I do not want to add too many dependencies into the project, but open to suggestions. Any input/advice on this would be very helpful. Thank you for the time! -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Mon Oct 2 09:28:18 2017 From: aquagnu at gmail.com (Baa) Date: Mon, 2 Oct 2017 12:28:18 +0300 Subject: [Haskell-beginners] Export of names only for testing Message-ID: <20171002122818.50bd85d0@Pavel> Hello, All! What is the standard Haskell convenience about export of module names for testing? As I understand, I should export all of them which looks like abstraction leak, but without this I can't test them, right? === Best regards, Paul From toad3k at gmail.com Mon Oct 2 10:39:31 2017 From: toad3k at gmail.com (David McBride) Date: Mon, 2 Oct 2017 06:39:31 -0400 Subject: [Haskell-beginners] Export of names only for testing In-Reply-To: <20171002122818.50bd85d0@Pavel> References: <20171002122818.50bd85d0@Pavel> Message-ID: It is common to export an Foo.Internal module that has the internals of your library in it, with a doc at the top that this is meant for internal use. It can be used both for testing and sometimes the user of your library can do something with it you didn't think of if he has access to the internals. On Mon, Oct 2, 2017 at 5:28 AM, Baa wrote: > Hello, All! > > What is the standard Haskell convenience about export of module names for > testing? As I understand, I should export all of them which looks like > abstraction leak, but without this I can't test them, right? > > === > Best regards, Paul > _______________________________________________ > 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 aquagnu at gmail.com Mon Oct 2 10:49:07 2017 From: aquagnu at gmail.com (Baa) Date: Mon, 2 Oct 2017 13:49:07 +0300 Subject: [Haskell-beginners] Export of names only for testing In-Reply-To: References: <20171002122818.50bd85d0@Pavel> Message-ID: <20171002134907.130b5d75@Pavel> > It is common to export an Foo.Internal module that has the internals > of your library in it, with a doc at the top that this is meant for > internal use. It can be used both for testing and sometimes the user > of your library can do something with it you didn't think of if he > has access to the internals. Hm, but if I have 10 modules in src/ (m1.hs, ..., m10.hs) I must create, for example 10 folders like src/m1/, ..., src/m10/ and their individual M*.Internal module, right? So, `m1`, for example, becomes: src/ m1/ Internal.hs All.hs ? And `All.hs` imports and re-exports module (or its part only) `Internal.hs`? Something like this? === Best regards, Paul From toad3k at gmail.com Mon Oct 2 11:12:40 2017 From: toad3k at gmail.com (David McBride) Date: Mon, 2 Oct 2017 07:12:40 -0400 Subject: [Haskell-beginners] Export of names only for testing In-Reply-To: <20171002134907.130b5d75@Pavel> References: <20171002122818.50bd85d0@Pavel> <20171002134907.130b5d75@Pavel> Message-ID: All I can give are examples. These have single Internal modules. https://hackage.haskell.org/package/text-1.2.2.2/docs/Data-Text-Internal.html https://hackage.haskell.org/package/aeson-1.2.2.0/docs/Data-Aeson-Internal.html https://hackage.haskell.org/package/pipes-4.3.5/docs/Pipes-Internal.html https://hackage.haskell.org/package/reflex-0.4.0/docs/Reflex-Spider-Internal.html whereas opaleye for example has an entire Internal hierarchy. https://hackage.haskell.org/package/opaleye-0.6.0.0 On Mon, Oct 2, 2017 at 6:49 AM, Baa wrote: > > It is common to export an Foo.Internal module that has the internals > > of your library in it, with a doc at the top that this is meant for > > internal use. It can be used both for testing and sometimes the user > > of your library can do something with it you didn't think of if he > > has access to the internals. > > Hm, but if I have 10 modules in src/ (m1.hs, ..., m10.hs) I must create, > for example 10 folders like src/m1/, ..., src/m10/ and their individual > M*.Internal module, right? So, `m1`, for example, becomes: > > src/ > m1/ > Internal.hs > All.hs > ? > > And `All.hs` imports and re-exports module (or its part only) > `Internal.hs`? Something like this? > > > === > Best regards, Paul > _______________________________________________ > 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 aquagnu at gmail.com Mon Oct 2 12:56:43 2017 From: aquagnu at gmail.com (Baa) Date: Mon, 2 Oct 2017 15:56:43 +0300 Subject: [Haskell-beginners] Export of names only for testing In-Reply-To: References: <20171002122818.50bd85d0@Pavel> <20171002134907.130b5d75@Pavel> Message-ID: <20171002155643.42e155fb@Pavel> Thank you, David! > All I can give are examples. These have single Internal modules. > > https://hackage.haskell.org/package/text-1.2.2.2/docs/Data-Text-Internal.html > https://hackage.haskell.org/package/aeson-1.2.2.0/docs/Data-Aeson-Internal.html > https://hackage.haskell.org/package/pipes-4.3.5/docs/Pipes-Internal.html > https://hackage.haskell.org/package/reflex-0.4.0/docs/Reflex-Spider-Internal.html > > whereas opaleye for example has an entire Internal hierarchy. > > https://hackage.haskell.org/package/opaleye-0.6.0.0 > > On Mon, Oct 2, 2017 at 6:49 AM, Baa wrote: > > > > It is common to export an Foo.Internal module that has the > > > internals of your library in it, with a doc at the top that this > > > is meant for internal use. It can be used both for testing and > > > sometimes the user of your library can do something with it you > > > didn't think of if he has access to the internals. > > > > Hm, but if I have 10 modules in src/ (m1.hs, ..., m10.hs) I must > > create, for example 10 folders like src/m1/, ..., src/m10/ and > > their individual M*.Internal module, right? So, `m1`, for example, > > becomes: > > > > src/ > > m1/ > > Internal.hs > > All.hs > > ? > > > > And `All.hs` imports and re-exports module (or its part only) > > `Internal.hs`? Something like this? > > > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From patrick.browne at dit.ie Tue Oct 3 13:07:01 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Tue, 3 Oct 2017 14:07:01 +0100 Subject: [Haskell-beginners] Lifting Numbers Message-ID: Hi, I am trying to compile, run, and understand the following code from [1]. type Moving v = Time -> v class Number a where (+), (-), (*) :: a -> a -> a sqr, sqrt :: a -> a sqr a = a * a instance Number v => Number (Moving v) where (+) a b = \t -> (a t) + (b t) (-) a b = \t -> (a t) - (b t) (*) a b = \t -> (a t) * (b t) sqrt a = \t -> sqrt (a t) I followed the compiler advice to produce the following version which compiles: {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} module MovingPoint where type Time = Float -- Type synonym assumed, could it be data type?? type Moving v = Time -> v class Number a where (+), (-), (*) :: a -> a -> a sqr :: a -> a sqrt :: a -> a instance (Floating v) => Number (Moving v) where (+) a b = \t -> (a t) Prelude.+ (b t) (-) a b = \t -> (a t) Prelude.- (b t) (*) a b = \t -> (a t) Prelude.* (b t) sqr a = \t -> (a t) Prelude.* (a t) sqrt a = \t -> Prelude.sqrt (a t) I do not know how to invoke any of the operations. In general I do know how to execute lambdas. I do not understand the bracketed pairs e.g. (a t). Any help on understanding and running the program would be appreciated. Thanks, Pat [1] Ontology for Spatio-temporal Databases http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113.9804&rep=rep1&type=pdf -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Oct 3 14:01:52 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 3 Oct 2017 10:01:52 -0400 Subject: [Haskell-beginners] Lifting Numbers In-Reply-To: References: Message-ID: You can get some intuition for how this works by replacing "Moving v" with its definition "Time -> v". Let's look at the + operation. class Number a where (+) :: a -> a -> a instance Number v => Number (Moving v) instance Number v => Number (Time -> v) (+) :: Number v => (Time -> v) -> (Time -> v) -> (Time -> v) So each argument of + must take a Time, the end result must also take a Time, and whatever each argument returns must be a Number (and thus has + defined for it). So you can sort of see how it works. + for a Moving v takes a time, then passes that time to each of its arguments, then adds the result. (+) a b = \t -> (a t) Prelude.+ (b t) data Time = Time Double -- For example. Then you can make formulas that are rooted in time. For example (contrived) if you are throwing a ball, the distance of the ball from you at time f could be something like the following: balldistance :: Moving Double balldistance (Time f) = f * 1.2 ball1 :: Moving Double ball1 = balldistance ball2 :: Moving Double ball2 = balldistance -- the combined distance of both balls at time f bothballs :: Moving Double bothballs = ball1 + ball2 Then you can get the combined distance of both balls after 12 seconds, for example. test :: Double test = bothballs (Time 12.0) On Tue, Oct 3, 2017 at 9:07 AM, PATRICK BROWNE wrote: > Hi, > I am trying to compile, run, and understand the following code from [1]. > > type Moving v = Time -> v > > class Number a where > (+), (-), (*) :: a -> a -> a > sqr, sqrt :: a -> a > sqr a = a * a > > instance Number v => Number (Moving v) where > (+) a b = \t -> (a t) + (b t) > (-) a b = \t -> (a t) - (b t) > (*) a b = \t -> (a t) * (b t) > sqrt a = \t -> sqrt (a t) > > I followed the compiler advice to produce the following version which > compiles: > > {-# LANGUAGE FlexibleInstances #-} > {-# LANGUAGE TypeSynonymInstances #-} > module MovingPoint where > type Time = Float -- Type synonym assumed, could it be data type?? > type Moving v = Time -> v > > class Number a where > (+), (-), (*) :: a -> a -> a > sqr :: a -> a > sqrt :: a -> a > > instance (Floating v) => Number (Moving v) where > (+) a b = \t -> (a t) Prelude.+ (b t) > (-) a b = \t -> (a t) Prelude.- (b t) > (*) a b = \t -> (a t) Prelude.* (b t) > sqr a = \t -> (a t) Prelude.* (a t) > sqrt a = \t -> Prelude.sqrt (a t) > > I do not know how to invoke any of the operations. In general I do know > how to execute lambdas. > I do not understand the bracketed pairs e.g. (a t). > Any help on understanding and running the program would be appreciated. > Thanks, > Pat > > > [1] Ontology for Spatio-temporal Databases > http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1. > 113.9804&rep=rep1&type=pdf > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any action > based on the contents of this email or attachments is prohibited. > www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa > ríomhphost nó sna hiatáin seo. www.dit.ie > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > > _______________________________________________ > 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 patrick.browne at dit.ie Tue Oct 3 19:15:37 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Tue, 3 Oct 2017 20:15:37 +0100 Subject: [Haskell-beginners] Lifting Numbers In-Reply-To: References: Message-ID: David, Thank you for you informative and helpful reply. I think that are two issues impeding my understanding of the original code. 1. The use of lambda 2. The structure of the class and instance 1. The use of lambda Is seems that the arguments to (+!) , below ,must be functions. I was trying to use values data Time = Time Double type Moving v = Time -> v (+!) a b = \t -> (a t) Prelude.+ (b t) b :: Moving Double b (Time x) = x * 1.5 test = (b +! b) (Time 10.0) Is my take on this correct? 2. The structure of the class and instance. Recall the original code: type Moving v = Time -> v class Number a where (+), (-), (*) :: a -> a -> a sqr, sqrt :: a -> a sqr a = a * a instance Number v => Number (Moving v) where (+) a b = \t -> (a t) + (b t) (-) a b = \t -> (a t) - (b t) (*) a b = \t -> (a t) * (b t) sqrt a = \t -> sqrt (a t) I believe that this would have to be changed to avoid a clash with the Prelude definitions. Is the following structuring reasonable? module MovingPoint where data Time = Time Double type Moving v = Time -> v class Number a where (+), (-), (*) :: a -> a -> a sqr :: a -> a sqrt :: a -> a instance (Floating v) => Number (Moving v) where (+) a b = \t -> (a t) Prelude.+ (b t) (-) a b = \t -> (a t) Prelude.- (b t) (*) a b = \t -> (a t) Prelude.* (b t) sqr a = \t -> (a t) Prelude.* (a t) sqrt a = \t -> Prelude.sqrt (a t) b :: Moving Double b (Time x) = x Prelude.* 1.5 test = (b MovingPoint.+ b) (Time 10.0) Thanks, Pat On 3 October 2017 at 15:01, David McBride wrote: > You can get some intuition for how this works by replacing "Moving v" with > its definition "Time -> v". Let's look at the + operation. > > class Number a where > (+) :: a -> a -> a > instance Number v => Number (Moving v) > instance Number v => Number (Time -> v) > (+) :: Number v => (Time -> v) -> (Time -> v) -> (Time -> v) > > So each argument of + must take a Time, the end result must also take a > Time, and whatever each argument returns must be a Number (and thus has + > defined for it). So you can sort of see how it works. + for a Moving v > takes a time, then passes that time to each of its arguments, then adds the > result. > > (+) a b = \t -> (a t) Prelude.+ (b t) > > data Time = Time Double -- For example. > > Then you can make formulas that are rooted in time. For example > (contrived) if you are throwing a ball, the distance of the ball from you > at time f could be something like the following: > > balldistance :: Moving Double > balldistance (Time f) = f * 1.2 > > ball1 :: Moving Double > ball1 = balldistance > > ball2 :: Moving Double > ball2 = balldistance > > -- the combined distance of both balls at time f > bothballs :: Moving Double > bothballs = ball1 + ball2 > > Then you can get the combined distance of both balls after 12 seconds, for > example. > > test :: Double > test = bothballs (Time 12.0) > > > > > > On Tue, Oct 3, 2017 at 9:07 AM, PATRICK BROWNE > wrote: > >> Hi, >> I am trying to compile, run, and understand the following code from [1]. >> >> type Moving v = Time -> v >> >> class Number a where >> (+), (-), (*) :: a -> a -> a >> sqr, sqrt :: a -> a >> sqr a = a * a >> >> instance Number v => Number (Moving v) where >> (+) a b = \t -> (a t) + (b t) >> (-) a b = \t -> (a t) - (b t) >> (*) a b = \t -> (a t) * (b t) >> sqrt a = \t -> sqrt (a t) >> >> I followed the compiler advice to produce the following version which >> compiles: >> >> {-# LANGUAGE FlexibleInstances #-} >> {-# LANGUAGE TypeSynonymInstances #-} >> module MovingPoint where >> type Time = Float -- Type synonym assumed, could it be data type?? >> type Moving v = Time -> v >> >> class Number a where >> (+), (-), (*) :: a -> a -> a >> sqr :: a -> a >> sqrt :: a -> a >> >> instance (Floating v) => Number (Moving v) where >> (+) a b = \t -> (a t) Prelude.+ (b t) >> (-) a b = \t -> (a t) Prelude.- (b t) >> (*) a b = \t -> (a t) Prelude.* (b t) >> sqr a = \t -> (a t) Prelude.* (a t) >> sqrt a = \t -> Prelude.sqrt (a t) >> >> I do not know how to invoke any of the operations. In general I do know >> how to execute lambdas. >> I do not understand the bracketed pairs e.g. (a t). >> Any help on understanding and running the program would be appreciated. >> Thanks, >> Pat >> >> >> [1] Ontology for Spatio-temporal Databases >> http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113 >> .9804&rep=rep1&type=pdf >> >> This email originated from DIT. If you received this email in error, >> please delete it from your system. Please note that if you are not the >> named addressee, disclosing, copying, distributing or taking any action >> based on the contents of this email or attachments is prohibited. >> www.dit.ie >> >> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí >> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an >> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon >> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa >> ríomhphost nó sna hiatáin seo. www.dit.ie >> >> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to >> Grangegorman >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Oct 3 20:53:13 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 3 Oct 2017 16:53:13 -0400 Subject: [Haskell-beginners] Lifting Numbers In-Reply-To: References: Message-ID: 1) Yes, you are correct. 2) Yes, that is fine. Sometimes people will use operators that don't conflict with prelude such as (+:), (-:) and (*:) to avoid these clashes. On Tue, Oct 3, 2017 at 3:15 PM, PATRICK BROWNE wrote: > David, > Thank you for you informative and helpful reply. > I think that are two issues impeding my understanding of the original code. > 1. The use of lambda > 2. The structure of the class and instance > > 1. The use of lambda > Is seems that the arguments to (+!) , below ,must be functions. I was > trying to use values > data Time = Time Double > > type Moving v = Time -> v > > (+!) a b = \t -> (a t) Prelude.+ (b t) > > b :: Moving Double > > b (Time x) = x * 1.5 > > test = (b +! b) (Time 10.0) > > Is my take on this correct? > > > 2. The structure of the class and instance. > Recall the original code: > > type Moving v = Time -> v > > class Number a where > (+), (-), (*) :: a -> a -> a > sqr, sqrt :: a -> a > sqr a = a * a > > instance Number v => Number (Moving v) where > (+) a b = \t -> (a t) + (b t) > (-) a b = \t -> (a t) - (b t) > (*) a b = \t -> (a t) * (b t) > sqrt a = \t -> sqrt (a t) > > I believe that this would have to be changed to avoid a clash with the > Prelude definitions. > Is the following structuring reasonable? > > module MovingPoint where > data Time = Time Double > type Moving v = Time -> v > > class Number a where > (+), (-), (*) :: a -> a -> a > sqr :: a -> a > sqrt :: a -> a > > instance (Floating v) => Number (Moving v) where > (+) a b = \t -> (a t) Prelude.+ (b t) > (-) a b = \t -> (a t) Prelude.- (b t) > (*) a b = \t -> (a t) Prelude.* (b t) > sqr a = \t -> (a t) Prelude.* (a t) > sqrt a = \t -> Prelude.sqrt (a t) > > b :: Moving Double > b (Time x) = x Prelude.* 1.5 > test = (b MovingPoint.+ b) (Time 10.0) > > Thanks, > Pat > > > > > > > On 3 October 2017 at 15:01, David McBride wrote: > >> You can get some intuition for how this works by replacing "Moving v" >> with its definition "Time -> v". Let's look at the + operation. >> >> class Number a where >> (+) :: a -> a -> a >> instance Number v => Number (Moving v) >> instance Number v => Number (Time -> v) >> (+) :: Number v => (Time -> v) -> (Time -> v) -> (Time -> v) >> >> So each argument of + must take a Time, the end result must also take a >> Time, and whatever each argument returns must be a Number (and thus has + >> defined for it). So you can sort of see how it works. + for a Moving v >> takes a time, then passes that time to each of its arguments, then adds the >> result. >> >> (+) a b = \t -> (a t) Prelude.+ (b t) >> >> data Time = Time Double -- For example. >> >> Then you can make formulas that are rooted in time. For example >> (contrived) if you are throwing a ball, the distance of the ball from you >> at time f could be something like the following: >> >> balldistance :: Moving Double >> balldistance (Time f) = f * 1.2 >> >> ball1 :: Moving Double >> ball1 = balldistance >> >> ball2 :: Moving Double >> ball2 = balldistance >> >> -- the combined distance of both balls at time f >> bothballs :: Moving Double >> bothballs = ball1 + ball2 >> >> Then you can get the combined distance of both balls after 12 seconds, >> for example. >> >> test :: Double >> test = bothballs (Time 12.0) >> >> >> >> >> >> On Tue, Oct 3, 2017 at 9:07 AM, PATRICK BROWNE >> wrote: >> >>> Hi, >>> I am trying to compile, run, and understand the following code from [1]. >>> >>> type Moving v = Time -> v >>> >>> class Number a where >>> (+), (-), (*) :: a -> a -> a >>> sqr, sqrt :: a -> a >>> sqr a = a * a >>> >>> instance Number v => Number (Moving v) where >>> (+) a b = \t -> (a t) + (b t) >>> (-) a b = \t -> (a t) - (b t) >>> (*) a b = \t -> (a t) * (b t) >>> sqrt a = \t -> sqrt (a t) >>> >>> I followed the compiler advice to produce the following version which >>> compiles: >>> >>> {-# LANGUAGE FlexibleInstances #-} >>> {-# LANGUAGE TypeSynonymInstances #-} >>> module MovingPoint where >>> type Time = Float -- Type synonym assumed, could it be data type?? >>> type Moving v = Time -> v >>> >>> class Number a where >>> (+), (-), (*) :: a -> a -> a >>> sqr :: a -> a >>> sqrt :: a -> a >>> >>> instance (Floating v) => Number (Moving v) where >>> (+) a b = \t -> (a t) Prelude.+ (b t) >>> (-) a b = \t -> (a t) Prelude.- (b t) >>> (*) a b = \t -> (a t) Prelude.* (b t) >>> sqr a = \t -> (a t) Prelude.* (a t) >>> sqrt a = \t -> Prelude.sqrt (a t) >>> >>> I do not know how to invoke any of the operations. In general I do know >>> how to execute lambdas. >>> I do not understand the bracketed pairs e.g. (a t). >>> Any help on understanding and running the program would be appreciated. >>> Thanks, >>> Pat >>> >>> >>> [1] Ontology for Spatio-temporal Databases >>> http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113 >>> .9804&rep=rep1&type=pdf >>> >>> This email originated from DIT. If you received this email in error, >>> please delete it from your system. Please note that if you are not the >>> named addressee, disclosing, copying, distributing or taking any action >>> based on the contents of this email or attachments is prohibited. >>> www.dit.ie >>> >>> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo >>> trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an >>> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon >>> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa >>> ríomhphost nó sna hiatáin seo. www.dit.ie >>> >>> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to >>> Grangegorman >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any action > based on the contents of this email or attachments is prohibited. > www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa > ríomhphost nó sna hiatáin seo. www.dit.ie > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Wed Oct 4 07:59:26 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 4 Oct 2017 10:59:26 +0300 Subject: [Haskell-beginners] Coverage percents - BUG? Message-ID: <20171004105926.34636c02@Pavel> Hello, all! Currently I'm trying to add coverage report to my application tests, and I see such line in the HPC report: .. 100% boolean coverage (0/0) .. but 0/0 =/= 100% (an undefined limit ;) IMHO better is to be reported as 0. Is it a bug in HPC? === Best regards, Paul From saikyun at gmail.com Wed Oct 4 08:52:57 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Wed, 4 Oct 2017 10:52:57 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: Dear mailing list, I want to create a text editor, preferably using open gl to render text. Are there any easy to use libraries for this? I like the gloss library, but the functions for rendering text seems quite basic. I could add upon this, but I figured I should ask here first; are there any existing libraries suitable for rendering text? Kind regards, Jona -------------- next part -------------- An HTML attachment was scrubbed... URL: From steffenomak at gmail.com Wed Oct 4 10:48:43 2017 From: steffenomak at gmail.com (Stefan Risberg) Date: Wed, 4 Oct 2017 12:48:43 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: Wouldn't pango with Cairo be good combination? On 4 Oct 2017 10:53 AM, "Jona Ekenberg" wrote: > Dear mailing list, > > I want to create a text editor, preferably using open gl to render text. > Are there any easy to use libraries for this? I like the gloss library, but > the functions for rendering text seems quite basic. I could add upon this, > but I figured I should ask here first; are there any existing libraries > suitable for rendering text? > > Kind regards, > Jona > > _______________________________________________ > 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 saikyun at gmail.com Wed Oct 4 11:45:44 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Wed, 4 Oct 2017 13:45:44 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: Thanks for your reply Stefan. When I look for cairo bindings for Haskell I find several different ones. Is there any one considered "the best" or most current? It does seem like a suitable combination. Den 4 okt. 2017 12:49 em skrev "Stefan Risberg" : Wouldn't pango with Cairo be good combination? On 4 Oct 2017 10:53 AM, "Jona Ekenberg" wrote: > Dear mailing list, > > I want to create a text editor, preferably using open gl to render text. > Are there any easy to use libraries for this? I like the gloss library, but > the functions for rendering text seems quite basic. I could add upon this, > but I figured I should ask here first; are there any existing libraries > suitable for rendering text? > > Kind regards, > Jona > > _______________________________________________ > 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 michael at orlitzky.com Wed Oct 4 12:32:20 2017 From: michael at orlitzky.com (Michael Orlitzky) Date: Wed, 4 Oct 2017 08:32:20 -0400 Subject: [Haskell-beginners] Coverage percents - BUG? In-Reply-To: <20171004105926.34636c02@Pavel> References: <20171004105926.34636c02@Pavel> Message-ID: <130d1805-2433-e149-8be8-28b79a25b133@orlitzky.com> On 10/04/2017 03:59 AM, Baa wrote: > > .. > 100% boolean coverage (0/0) > .. > > but 0/0 =/= 100% (an undefined limit ;) IMHO better is to be > reported as 0. Is it a bug in HPC? > For all tests t, t passed -- vacuous truth to the rescue! Or, 100% of zero is zero. Don't think too hard about it =) >From a practical standpoint, you probably don't want your integration tests to reject a commit because you have 0% coverage on something that doesn't exist. For that reason, a "success" result is better when you have no coverage of no things. From sylvain at haskus.fr Wed Oct 4 12:55:35 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Wed, 4 Oct 2017 14:55:35 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: FontyFruity with Rasterific could also be a good native Haskell alternative. I've used it to write a little terminal demo with haskus-system: https://www.youtube.com/watch?v=Dg9KyMk2n5E Regards, Sylvain On 04/10/2017 12:48, Stefan Risberg wrote: > Wouldn't pango with Cairo be good combination? > > On 4 Oct 2017 10:53 AM, "Jona Ekenberg" > wrote: > > Dear mailing list, > > I want to create a text editor, preferably using open gl to render > text. Are there any easy to use libraries for this? I like the > gloss library, but the functions for rendering text seems quite > basic. I could add upon this, but I figured I should ask here > first; are there any existing libraries suitable for rendering text? > > Kind regards, > Jona > > _______________________________________________ > 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 steffenomak at gmail.com Wed Oct 4 13:32:36 2017 From: steffenomak at gmail.com (Stefan Risberg) Date: Wed, 4 Oct 2017 15:32:36 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: You have Cairo and gi-cairo, I think that gi-cairo are autogenerated and from my experience a bit of a pain to set up. It also depends on if you use stack, cabal or nix of course for your project. But I think both are mostly equal On 4 Oct 2017 13:46, "Jona Ekenberg" wrote: > Thanks for your reply Stefan. > > When I look for cairo bindings for Haskell I find several different ones. > Is there any one considered "the best" or most current? It does seem like a > suitable combination. > > Den 4 okt. 2017 12:49 em skrev "Stefan Risberg" : > > Wouldn't pango with Cairo be good combination? > > On 4 Oct 2017 10:53 AM, "Jona Ekenberg" wrote: > >> Dear mailing list, >> >> I want to create a text editor, preferably using open gl to render text. >> Are there any easy to use libraries for this? I like the gloss library, but >> the functions for rendering text seems quite basic. I could add upon this, >> but I figured I should ask here first; are there any existing libraries >> suitable for rendering text? >> >> Kind regards, >> Jona >> >> _______________________________________________ >> 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 > > > > _______________________________________________ > 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 aquagnu at gmail.com Wed Oct 4 16:36:43 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 4 Oct 2017 19:36:43 +0300 Subject: [Haskell-beginners] Coverage percents - BUG? In-Reply-To: <130d1805-2433-e149-8be8-28b79a25b133@orlitzky.com> References: <20171004105926.34636c02@Pavel> <130d1805-2433-e149-8be8-28b79a25b133@orlitzky.com> Message-ID: <20171004193643.7e904b6a@Pavel> Hello, Michael. > From a practical standpoint, you probably don't want your integration > tests to reject a commit because you have 0% coverage on something > that doesn't exist. For that reason, a "success" result is better > when you have no coverage of no things. absolutely make sense :) Thanks! > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From mihai.maruseac at gmail.com Fri Oct 6 02:17:10 2017 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Thu, 5 Oct 2017 19:17:10 -0700 Subject: [Haskell-beginners] [Call for Contributions] Haskell Communities and Activities Report, November 2017 edition (33rd edition) Message-ID: Dear all, We would like to collect contributions for the 33rd edition of the ============================================================ Haskell Communities & Activities Report http://www.haskell.org/haskellwiki/Haskell_Communities_and_Activities_Report Submission deadline: 5 November 2017 (please send your contributions to hcar at haskell.org, in plain text or LaTeX format, both are equally accepted) ============================================================ This is the short story: * If you are working on any project that is in some way related to Haskell, please write a short entry and submit it. Even if the project is very small or unfinished or you think it is not important enough --- please reconsider and submit an entry anyway! * If you are interested in an existing project related to Haskell that has not previously been mentioned in the HCAR, please tell us, so that we can contact the project leaders and ask them to submit an entry. * If you are working on a project that is looking for contributors, please write a short entry and submit it, mentioning that your are looking for contributors. * Feel free to pass on this call for contributions to others that might be interested. More detailed information: The Haskell Communities & Activities Report is a bi-annual overview of the state of Haskell as well as Haskell-related projects over the last, and possibly the upcoming six months. If you have only recently been exposed to Haskell, it might be a good idea to browse the previous edition --- you will find interesting projects described as well as several starting points and links that may provide answers to many questions. Contributions will be collected until the submission deadline. They will then be compiled into a coherent report that is published online as soon as it is ready. As always, this is a great opportunity to update your webpages, make new releases, announce or even start new projects, or to talk about developments you want every Haskeller to know about! Looking forward to your contributions, Mihai Maruseac FAQ: Q: What format should I write in? A: The usual format is a LaTeX source file, adhering to the template that is available at: http://haskell.org/communities/11-2017/template.tex There is also a LaTeX style file at http://haskell.org/communities/11-2017/hcar.sty that you can use to preview your entry. If you do not know LaTeX or don't want to use it or don't have time to translate your entry into it, then please use plain text, it is better to have an entry in plain-text which we will translate than not have it at all. If you modify an old entry that you have written for an earlier edition of the report, you should soon receive your old entry as a template (provided we have your valid email address). Please modify that template, rather than using your own version of the old entry as a template. Q: Can I include Haskell code? A: Yes. Please use lhs2tex syntax (http://www.andres-loeh.de/lhs2tex/). The report is compiled in mode polycode.fmt. Q: Can I include images? A: Yes, you are even encouraged to do so. Please use .jpg or .png format, then. PNG is preferred for simplicity. Q: Should I send files in .zip archives or similar? A: No, plain file attachments are the way. Q: How much should I write? A: Authors are asked to limit entries to about one column of text. A general introduction is helpful. Apart from that, you should focus on recent or upcoming developments. Pointers to online content can be given for more comprehensive or "historic" overviews of a project. Images do not count towards the length limit, so you may want to use this opportunity to pep up entries. There is no minimum length of an entry! The report aims for being as complete as possible, so please consider writing an entry, even if it is only a few lines long. Q: Which topics are relevant? A: All topics which are related to Haskell in some way are relevant. We usually had reports from users of Haskell (private, academic, or commercial), from authors or contributors to projects related to Haskell, from people working on the Haskell language, libraries, on language extensions or variants. We also like reports about distributions of Haskell software, Haskell infrastructure, books and tutorials on Haskell. Reports on past and upcoming events related to Haskell are also relevant. Finally, there might be new topics we do not even think about. As a rule of thumb: if in doubt, then it probably is relevant and has a place in the HCAR. You can also simply ask us. Q: Is unfinished work relevant? Are ideas for projects relevant? A: Yes! You can use the HCAR to talk about projects you are currently working on. You can use it to look for other developers that might help you. You can use HCAR to ask for more contributors to your project, it is a good way to gain visibility and traction. Q: If I do not update my entry, but want to keep it in the report, what should I do? A: Tell us that there are no changes. The old entry will typically be reused in this case, but it might be dropped if it is older than a year, to give more room and more attention to projects that change a lot. Do not resend complete entries if you have not changed them. Q: Will I get confirmation if I send an entry? How do I know whether my email has even reached its destination, and not ended up in a spam folder? A: Prior to publication of the final report, we will send a draft to all contributors, for possible corrections. So if you do not hear from us within two weeks after the deadline, it is safer to send another mail and check whether your first one was received. -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya From aquagnu at gmail.com Fri Oct 6 07:51:49 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 6 Oct 2017 10:51:49 +0300 Subject: [Haskell-beginners] Automatically "deducing" of wrappers Message-ID: <20171006105149.328cb041@Pavel> Hello, List! This is a little bit theoretical question but not only... Let's suppose I have a lot of functions like: llfunc :: A -> B -> C -> D -> C and I have types C and HLC and "constructor" of HLC from C: makeHLC :: C -> Maybe HLC -- or Either String HLC and I want to create "automatically" (i.e. with minimal coding!) functions like: hlfunc :: A -> B -> HLC -> D -> HLC -- see llfunc i.e. for each ll* (low-level) to create hl* (high-level). For example, I can have even HLC -> C function. I may have a lot of llfunc's. Idea is to replace a coding of hlfunc's with some automatically or semi-automatically deduce/creating of them. For example, C may be `FilePath`, HLC may be some kind of `Path a` (wrapper for paths). And I have a lot of FilePath-based legacy functions. I suppose it's possible to solve such problem in D language (I made somthing similar several years ago). And possible it's easy in Nim (Nimrod) because of them: a) types exist b) meta-programming features. IMHO should be a way to do similar in Haskell, but it does not look easy. IMHO I can code arguments + return types with Generic, and next step may be type class with custom methods C -> HLC/HLC -> C and default method like `perform` which will get Generic and automatically makes instance of this type class or... And how will it look like? Is it even possible in Haskell? === Best regards, Paul From saikyun at gmail.com Fri Oct 6 09:35:24 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Fri, 6 Oct 2017 11:35:24 +0200 Subject: [Haskell-beginners] Library for rendering text In-Reply-To: References: Message-ID: Thanks, I will try these out. 2017-10-04 15:32 GMT+02:00 Stefan Risberg : > You have Cairo and gi-cairo, I think that gi-cairo are autogenerated and > from my experience a bit of a pain to set up. > > It also depends on if you use stack, cabal or nix of course for your > project. But I think both are mostly equal > > On 4 Oct 2017 13:46, "Jona Ekenberg" wrote: > >> Thanks for your reply Stefan. >> >> When I look for cairo bindings for Haskell I find several different ones. >> Is there any one considered "the best" or most current? It does seem like a >> suitable combination. >> >> Den 4 okt. 2017 12:49 em skrev "Stefan Risberg" : >> >> Wouldn't pango with Cairo be good combination? >> >> On 4 Oct 2017 10:53 AM, "Jona Ekenberg" wrote: >> >>> Dear mailing list, >>> >>> I want to create a text editor, preferably using open gl to render text. >>> Are there any easy to use libraries for this? I like the gloss library, but >>> the functions for rendering text seems quite basic. I could add upon this, >>> but I figured I should ask here first; are there any existing libraries >>> suitable for rendering text? >>> >>> Kind regards, >>> Jona >>> >>> _______________________________________________ >>> 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 >> >> >> >> _______________________________________________ >> 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 patrick.browne at dit.ie Sat Oct 7 12:07:43 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Sat, 7 Oct 2017 13:07:43 +0100 Subject: [Haskell-beginners] Return type from class method Message-ID: Hi, Is there a way rewriting the definition of (+) so that testPlusArg returns a (Moving Double). My current intuition is that the signature [(+) :: a -> a -> a] says that the type should be the same as the arguments. And indeed (:t testPlus) confirms this. But the type of testPlusArg is a Double. Can I make it (Moving Double) ? Thanks, Pat {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} module Moving where data Time = Time Double type Moving v = Time -> v class Number a where (+) :: a -> a -> a instance Number (Moving Double) where (+) a b = \t -> ((a t) Prelude.+ (b t)) a,b :: Moving Double a (Time x) = 2.0 b (Time x) = 2.0 testPlus ::(Moving Double) testPlus = (a Moving.+ b) testPlusArg = (a Moving.+ b) (Time 2.0) -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Sat Oct 7 22:30:27 2017 From: tjakway at nyu.edu (Thomas Jakway) Date: Sat, 7 Oct 2017 15:30:27 -0700 Subject: [Haskell-beginners] Return type from class method In-Reply-To: References: Message-ID: You could hide Prelude and define it yourself in a different module but that would be a pretty bad idea. Everyone who wanted to use it would have to import your module qualified and refer to it as MyModule.+, which defeats the point of making it (+) and not `myAdditionFunction` in the first place. Haskell deliberately doesn't allow overloading. Having (+) return something other than Num would be extremely confusing. On 10/07/2017 05:07 AM, PATRICK BROWNE wrote: > Hi, > Is there a way rewriting the definition of (+) so that testPlusArg > returns a (Moving Double). My current intuition is that the signature > [(+) :: a -> a -> a] says that the type should be the same as the > arguments. And indeed (:t testPlus) confirms this. But the type of > testPlusArg is a Double. > Can I make it (Moving Double) ? > Thanks, > Pat > > {-# LANGUAGE FlexibleInstances #-} > {-# LANGUAGE TypeSynonymInstances #-} > module Moving where > data Time = Time Double > type Moving v = Time -> v > > class Number a where > (+) :: a -> a -> a > > instance Number (Moving Double) where > (+) a b = \t -> ((a t) Prelude.+ (b t)) > > a,b :: Moving Double > a (Time x) = 2.0 > b (Time x) = 2.0 > testPlus ::(Moving Double) > testPlus = (a Moving.+ b) > testPlusArg = (a Moving.+ b) (Time 2.0) > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any > action based on the contents of this email or attachments is > prohibited. www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo > trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura > tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon > chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an > ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie > > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > > > > _______________________________________________ > 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 patrick.browne at dit.ie Sun Oct 8 05:24:06 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Sun, 8 Oct 2017 06:24:06 +0100 Subject: [Haskell-beginners] Return type from class method In-Reply-To: References: Message-ID: Thomas, Thanks for your response. I agree that using (+) in this manner leads to name clashes. My question is prompted by a research paper [1] where a form of lifting is attempted using type classes. I think that the original code in paper (below) is intended to be illustrative rather than practical. I have edited the code to compile and run (after a fashion, see below). But I cannot get the functions to return the lifted type. Also I have a problem compiling the lines with two lambdas, e.g. (np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t)) Regards, Pat --------------------------------------------------------------------------------------------- Original code [1]: ------------------------------------------------------------------------------------------ class Number a where (+), (-), (*) :: a -> a -> a sqr, sqrt :: a -> a sqr a = a * a type Moving v = Time -> v instance Number v => Number (Moving v) where (+) a b = \t -> (a t) + (b t) (-) a b = \t -> (a t) - (b t) (*) a b = \t -> (a t) * (b t) sqrt a = \t -> sqrt (a t) class Number s => Points p s where x, y :: p s -> s xy :: s -> s -> p s dist :: p s -> p s -> s dist a b = sqrt (sqr ((x a) - (x b)) + sqr ((y a) - (y b))) data Point f = Point f f instance Number v => Points Point v where x (Point x1 y1) = x1 y (Point x1 y1) = y1 xy x1 y1 = Point x1 y1 instance Number v => (Point v) where (+) a b = xy (x a + x b) (y a + y b) (-) a b = xy (x a - x b) (y a - y b) np1, np2 :: Point (Moving Float) np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t) np2 = xy (\t -> 0.0 + 1.0 * t) (\t -> 0.0 - 1.0 * t) movingDist_1_2 = dist np1 np2 dist_at_1 = movingDist_1_2 1.0 ---------------------------------------------------------------------------------------------- My attempt at getting above code to run: ----------------------------------------------------------------------------------------------- {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} module Moving where data Time = Time Double type Moving v = Time -> v data Point v = Point v v deriving Show class Number a where (+),(-),(*) :: a -> a -> a sqrt :: a -> a instance (Fractional a,Floating a) => Number (Moving a) where (+) a b = \t -> ((a t) Prelude.+ (b t)) (-) a b = \t -> ((a t) Prelude.- (b t)) (*) a b = \t -> ((a t) Prelude.* (b t)) sqrt a = \t -> Prelude.sqrt (a t) a,b :: Moving Double a (Time x) = 4.0 b (Time x) = 4.0 testPlus ::(Moving Double) testPlus = (a Moving.+ b) testPlusArg = (a Moving.+ b) (Time 2.0) testSqrt = (Moving.sqrt a) (Time 2.0) class (Number s) => Points p s where x, y :: p s -> s xy :: s -> s -> p s dist :: p s -> p s -> s dist a b = Moving.sqrt (sqr ((x a) Moving.- (x b)) Moving.+ sqr ((y a) Moving.- (y b))) where sqr z = z Moving.* z -- instance (Floating v,Number v) => Points Point v where instance (Number s) => Points Point s where x (Point x1 y1) = x1 y (Point x1 y1) = y1 xy x1 y1 = Point x1 y1 instance Number v => Number (Point v) where (+) a b = xy (x a Moving.+ x b) (y a Moving.+ y b) (-) a b = xy (x a Moving.- x b) (y a Moving.- y b) md1,md2,md3,md4 :: Moving Double md1 (Time x) = 0.0 md2 (Time x) = 0.0 md3 (Time x) = 10.0 md4 (Time x) = 10.0 testMD1 = (md1 (Time 2.0)) testX = x (Point md1 md2) (Time 2.0) testY = y (Point md1 md2) (Time 2.0) testXY = (xy md1 md2)::(Point (Moving Double)) testX' = x testXY (Time 1.0) testD = dist (Point md1 md2) (Point md3 md4) (Time 1.0) --- I cannot get the rest to work [1] Ontology for Spatio-temporal Databases http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113.9804&rep=rep1&type=pdf On 7 October 2017 at 23:30, Thomas Jakway wrote: > You could hide Prelude and define it yourself in a different module but > that would be a pretty bad idea. Everyone who wanted to use it would have > to import your module qualified and refer to it as MyModule.+, which > defeats the point of making it (+) and not `myAdditionFunction` in the > first place. > > Haskell deliberately doesn't allow overloading. Having (+) return > something other than Num would be extremely confusing. > > On 10/07/2017 05:07 AM, PATRICK BROWNE wrote: > > Hi, > Is there a way rewriting the definition of (+) so that testPlusArg returns > a (Moving Double). My current intuition is that the signature [(+) :: a > -> a -> a] says that the type should be the same as the arguments. And > indeed (:t testPlus) confirms this. But the type of testPlusArg is a > Double. > Can I make it (Moving Double) ? > Thanks, > Pat > > > {-# LANGUAGE FlexibleInstances #-} > {-# LANGUAGE TypeSynonymInstances #-} > module Moving where > data Time = Time Double > type Moving v = Time -> v > > class Number a where > (+) :: a -> a -> a > > instance Number (Moving Double) where > (+) a b = \t -> ((a t) Prelude.+ (b t)) > > a,b :: Moving Double > a (Time x) = 2.0 > b (Time x) = 2.0 > testPlus ::(Moving Double) > testPlus = (a Moving.+ b) > testPlusArg = (a Moving.+ b) (Time 2.0) > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any action > based on the contents of this email or attachments is prohibited. > www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa > ríomhphost nó sna hiatáin seo. www.dit.ie > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Mon Oct 9 12:21:21 2017 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Mon, 9 Oct 2017 15:21:21 +0300 Subject: [Haskell-beginners] Kyiv Haskell Learning Group Meetups Message-ID: Hi! We're starting a Haskell Learning Group in Kyiv, Ukraine. First Meetup will be at 17 October (Tuesday) and will continue on weekly basis at the Institute of Mathematics. See full info about the first meetup at https://www.meetup.com/Kyiv-Haskell-Learning-Group/events/243945548/ Info about the course itself (in Ukrainian): https://github.com/KyivHaskell/haskell-study-startup See you there! -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Oct 9 12:53:39 2017 From: toad3k at gmail.com (David McBride) Date: Mon, 9 Oct 2017 08:53:39 -0400 Subject: [Haskell-beginners] Return type from class method In-Reply-To: References: Message-ID: Here's a direct translation of the original code. What is missing is an instance for Number for Prelude.Float. That is because it is using 4.0 + 0.5 * (t :: Time), where Time must be a P.Float, or else if it is a data type it must having instances for Fractional, Num, and Floating, so that it can be represented as a floating point literal (ie. 4.0). It might be easier in the long run if you got rid of the Number class and just used Prelude's Num class instead. You would have to do some slightly different handling to deal with sqrt. Admittedly that might be difficult. {-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FlexibleInstances #-} import qualified Prelude as P ((+), (-), (*), sqrt, Float) class Number a where (+), (-), (*) :: a -> a -> a sqr, sqrt :: a -> a sqr a = a * a type Time = P.Float type Moving v = Time -> v instance Number P.Float where (+) = (P.+) (-) = (P.-) (*) = (P.*) sqrt = P.sqrt instance Number v => Number (Moving v) where (+) a b = \t -> (a t) + (b t) (-) a b = \t -> (a t) - (b t) (*) a b = \t -> (a t) * (b t) sqrt a = \t -> sqrt (a t) class Number s => Points p s where x, y :: p s -> s xy :: s -> s -> p s dist :: p s -> p s -> s dist a b = sqrt (sqr ((x a) - (x b)) + sqr ((y a) - (y b))) data Point f = Point f f instance Number v => Points Point v where x (Point x1 y1) = x1 y (Point x1 y1) = y1 xy x1 y1 = Point x1 y1 instance Number v => Number (Point v) where a + b = xy (x a + x b) (y a + y b) a - b = xy (x a - x b) (y a - y b) np1 :: Point (Moving P.Float) np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t) np2 = xy (\t -> 0.0 + 1.0 * t) (\t -> 0.0 - 1.0 * t) movingDist_1_2 = dist np1 np2 dist_at_1 = movingDist_1_2 1.0 On Sun, Oct 8, 2017 at 1:24 AM, PATRICK BROWNE wrote: > Thomas, > Thanks for your response. I agree that using (+) in this manner leads to > name clashes. > My question is prompted by a research paper [1] where a form of lifting is > attempted using type classes. > I think that the original code in paper (below) is intended to be > illustrative rather than practical. > I have edited the code to compile and run (after a fashion, see below). > But I cannot get the functions to return the lifted type. > Also I have a problem compiling the lines with two lambdas, e.g. (np1 = xy > (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t)) > Regards, > Pat > ------------------------------------------------------------ > --------------------------------- > Original code [1]: > ------------------------------------------------------------ > ------------------------------ > class Number a where > (+), (-), (*) :: a -> a -> a > sqr, sqrt :: a -> a > sqr a = a * a > > type Moving v = Time -> v > > instance Number v => Number (Moving v) where > (+) a b = \t -> (a t) + (b t) > (-) a b = \t -> (a t) - (b t) > (*) a b = \t -> (a t) * (b t) > sqrt a = \t -> sqrt (a t) > > class Number s => Points p s where > x, y :: p s -> s > xy :: s -> s -> p s > dist :: p s -> p s -> s > dist a b = sqrt (sqr ((x a) - (x b)) + > sqr ((y a) - (y b))) > > data Point f = Point f f > > instance Number v => Points Point v where > x (Point x1 y1) = x1 > y (Point x1 y1) = y1 > xy x1 y1 = Point x1 y1 > > instance Number v => (Point v) where > (+) a b = xy (x a + x b) (y a + y b) > (-) a b = xy (x a - x b) (y a - y b) > > > np1, np2 :: Point (Moving Float) > np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t) > np2 = xy (\t -> 0.0 + 1.0 * t) (\t -> 0.0 - 1.0 * t) > movingDist_1_2 = dist np1 np2 > dist_at_1 = movingDist_1_2 1.0 > > > ------------------------------------------------------------ > ---------------------------------- > My attempt at getting above code to run: > ------------------------------------------------------------ > ----------------------------------- > {-# LANGUAGE MultiParamTypeClasses #-} > {-# LANGUAGE FlexibleInstances #-} > {-# LANGUAGE TypeSynonymInstances #-} > module Moving where > data Time = Time Double > type Moving v = Time -> v > data Point v = Point v v deriving Show > > class Number a where > (+),(-),(*) :: a -> a -> a > sqrt :: a -> a > > > instance (Fractional a,Floating a) => Number (Moving a) where > (+) a b = \t -> ((a t) Prelude.+ (b t)) > (-) a b = \t -> ((a t) Prelude.- (b t)) > (*) a b = \t -> ((a t) Prelude.* (b t)) > sqrt a = \t -> Prelude.sqrt (a t) > > a,b :: Moving Double > a (Time x) = 4.0 > b (Time x) = 4.0 > testPlus ::(Moving Double) > testPlus = (a Moving.+ b) > testPlusArg = (a Moving.+ b) (Time 2.0) > testSqrt = (Moving.sqrt a) (Time 2.0) > > > > class (Number s) => Points p s where > x, y :: p s -> s > xy :: s -> s -> p s > dist :: p s -> p s -> s > dist a b = Moving.sqrt (sqr ((x a) Moving.- (x b)) Moving.+ sqr ((y a) > Moving.- (y b))) > where sqr z = z Moving.* z > > > > -- instance (Floating v,Number v) => Points Point v where > instance (Number s) => Points Point s where > x (Point x1 y1) = x1 > y (Point x1 y1) = y1 > xy x1 y1 = Point x1 y1 > > instance Number v => Number (Point v) where > (+) a b = xy (x a Moving.+ x b) (y a Moving.+ y b) > (-) a b = xy (x a Moving.- x b) (y a Moving.- y b) > > > md1,md2,md3,md4 :: Moving Double > md1 (Time x) = 0.0 > md2 (Time x) = 0.0 > md3 (Time x) = 10.0 > md4 (Time x) = 10.0 > testMD1 = (md1 (Time 2.0)) > testX = x (Point md1 md2) (Time 2.0) > testY = y (Point md1 md2) (Time 2.0) > testXY = (xy md1 md2)::(Point (Moving Double)) > testX' = x testXY (Time 1.0) > testD = dist (Point md1 md2) (Point md3 md4) (Time 1.0) > > --- I cannot get the rest to work > > [1] Ontology for Spatio-temporal Databases > http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113 > .9804&rep=rep1&type=pdf > > On 7 October 2017 at 23:30, Thomas Jakway wrote: > >> You could hide Prelude and define it yourself in a different module but >> that would be a pretty bad idea. Everyone who wanted to use it would have >> to import your module qualified and refer to it as MyModule.+, which >> defeats the point of making it (+) and not `myAdditionFunction` in the >> first place. >> >> Haskell deliberately doesn't allow overloading. Having (+) return >> something other than Num would be extremely confusing. >> >> On 10/07/2017 05:07 AM, PATRICK BROWNE wrote: >> >> Hi, >> Is there a way rewriting the definition of (+) so that testPlusArg >> returns a (Moving Double). My current intuition is that the signature [(+) >> :: a -> a -> a] says that the type should be the same as the arguments. >> And indeed (:t testPlus) confirms this. But the type of testPlusArg is a >> Double. >> Can I make it (Moving Double) ? >> Thanks, >> Pat >> >> >> {-# LANGUAGE FlexibleInstances #-} >> {-# LANGUAGE TypeSynonymInstances #-} >> module Moving where >> data Time = Time Double >> type Moving v = Time -> v >> >> class Number a where >> (+) :: a -> a -> a >> >> instance Number (Moving Double) where >> (+) a b = \t -> ((a t) Prelude.+ (b t)) >> >> a,b :: Moving Double >> a (Time x) = 2.0 >> b (Time x) = 2.0 >> testPlus ::(Moving Double) >> testPlus = (a Moving.+ b) >> testPlusArg = (a Moving.+ b) (Time 2.0) >> >> This email originated from DIT. If you received this email in error, >> please delete it from your system. Please note that if you are not the >> named addressee, disclosing, copying, distributing or taking any action >> based on the contents of this email or attachments is prohibited. >> www.dit.ie >> >> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí >> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an >> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon >> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa >> ríomhphost nó sna hiatáin seo. www.dit.ie >> >> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to >> Grangegorman >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any action > based on the contents of this email or attachments is prohibited. > www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa > ríomhphost nó sna hiatáin seo. www.dit.ie > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > > _______________________________________________ > 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 patrick.browne at dit.ie Mon Oct 9 15:53:42 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Mon, 9 Oct 2017 16:53:42 +0100 Subject: [Haskell-beginners] Return type from class method In-Reply-To: References: Message-ID: David, Thanks very much for clarifying my confusion. I would never have thought of the rather subtle import nor the instance Number P.Float. Your help is greatly appreciated, Pat On 9 October 2017 at 13:53, David McBride wrote: > Here's a direct translation of the original code. What is missing is an > instance for Number for Prelude.Float. That is because it is using 4.0 + > 0.5 * (t :: Time), where Time must be a P.Float, or else if it is a data > type it must having instances for Fractional, Num, and Floating, so that it > can be represented as a floating point literal (ie. 4.0). > > It might be easier in the long run if you got rid of the Number class and > just used Prelude's Num class instead. You would have to do some slightly > different handling to deal with sqrt. Admittedly that might be difficult. > > {-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FlexibleInstances > #-} > > import qualified Prelude as P ((+), (-), (*), sqrt, Float) > > class Number a where > (+), (-), (*) :: a -> a -> a > sqr, sqrt :: a -> a > sqr a = a * a > > type Time = P.Float > > type Moving v = Time -> v > > instance Number P.Float where > (+) = (P.+) > (-) = (P.-) > (*) = (P.*) > sqrt = P.sqrt > > > instance Number v => Number (Moving v) where > (+) a b = \t -> (a t) + (b t) > (-) a b = \t -> (a t) - (b t) > (*) a b = \t -> (a t) * (b t) > sqrt a = \t -> sqrt (a t) > > class Number s => Points p s where > x, y :: p s -> s > xy :: s -> s -> p s > dist :: p s -> p s -> s > dist a b = sqrt (sqr ((x a) - (x b)) + sqr ((y a) - (y b))) > > data Point f = Point f f > > instance Number v => Points Point v where > x (Point x1 y1) = x1 > y (Point x1 y1) = y1 > xy x1 y1 = Point x1 y1 > > instance Number v => Number (Point v) where > a + b = xy (x a + x b) (y a + y b) > a - b = xy (x a - x b) (y a - y b) > > > np1 :: Point (Moving P.Float) > np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t) > np2 = xy (\t -> 0.0 + 1.0 * t) (\t -> 0.0 - 1.0 * t) > movingDist_1_2 = dist np1 np2 > dist_at_1 = movingDist_1_2 1.0 > > > On Sun, Oct 8, 2017 at 1:24 AM, PATRICK BROWNE > wrote: > >> Thomas, >> Thanks for your response. I agree that using (+) in this manner leads to >> name clashes. >> My question is prompted by a research paper [1] where a form of lifting >> is attempted using type classes. >> I think that the original code in paper (below) is intended to be >> illustrative rather than practical. >> I have edited the code to compile and run (after a fashion, see below). >> But I cannot get the functions to return the lifted type. >> Also I have a problem compiling the lines with two lambdas, e.g. (np1 = >> xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t)) >> Regards, >> Pat >> ------------------------------------------------------------ >> --------------------------------- >> Original code [1]: >> ------------------------------------------------------------ >> ------------------------------ >> class Number a where >> (+), (-), (*) :: a -> a -> a >> sqr, sqrt :: a -> a >> sqr a = a * a >> >> type Moving v = Time -> v >> >> instance Number v => Number (Moving v) where >> (+) a b = \t -> (a t) + (b t) >> (-) a b = \t -> (a t) - (b t) >> (*) a b = \t -> (a t) * (b t) >> sqrt a = \t -> sqrt (a t) >> >> class Number s => Points p s where >> x, y :: p s -> s >> xy :: s -> s -> p s >> dist :: p s -> p s -> s >> dist a b = sqrt (sqr ((x a) - (x b)) + >> sqr ((y a) - (y b))) >> >> data Point f = Point f f >> >> instance Number v => Points Point v where >> x (Point x1 y1) = x1 >> y (Point x1 y1) = y1 >> xy x1 y1 = Point x1 y1 >> >> instance Number v => (Point v) where >> (+) a b = xy (x a + x b) (y a + y b) >> (-) a b = xy (x a - x b) (y a - y b) >> >> >> np1, np2 :: Point (Moving Float) >> np1 = xy (\t -> 4.0 + 0.5 * t) (\t -> 4.0 - 0.5 * t) >> np2 = xy (\t -> 0.0 + 1.0 * t) (\t -> 0.0 - 1.0 * t) >> movingDist_1_2 = dist np1 np2 >> dist_at_1 = movingDist_1_2 1.0 >> >> >> ------------------------------------------------------------ >> ---------------------------------- >> My attempt at getting above code to run: >> ------------------------------------------------------------ >> ----------------------------------- >> {-# LANGUAGE MultiParamTypeClasses #-} >> {-# LANGUAGE FlexibleInstances #-} >> {-# LANGUAGE TypeSynonymInstances #-} >> module Moving where >> data Time = Time Double >> type Moving v = Time -> v >> data Point v = Point v v deriving Show >> >> class Number a where >> (+),(-),(*) :: a -> a -> a >> sqrt :: a -> a >> >> >> instance (Fractional a,Floating a) => Number (Moving a) where >> (+) a b = \t -> ((a t) Prelude.+ (b t)) >> (-) a b = \t -> ((a t) Prelude.- (b t)) >> (*) a b = \t -> ((a t) Prelude.* (b t)) >> sqrt a = \t -> Prelude.sqrt (a t) >> >> a,b :: Moving Double >> a (Time x) = 4.0 >> b (Time x) = 4.0 >> testPlus ::(Moving Double) >> testPlus = (a Moving.+ b) >> testPlusArg = (a Moving.+ b) (Time 2.0) >> testSqrt = (Moving.sqrt a) (Time 2.0) >> >> >> >> class (Number s) => Points p s where >> x, y :: p s -> s >> xy :: s -> s -> p s >> dist :: p s -> p s -> s >> dist a b = Moving.sqrt (sqr ((x a) Moving.- (x b)) Moving.+ sqr ((y a) >> Moving.- (y b))) >> where sqr z = z Moving.* z >> >> >> >> -- instance (Floating v,Number v) => Points Point v where >> instance (Number s) => Points Point s where >> x (Point x1 y1) = x1 >> y (Point x1 y1) = y1 >> xy x1 y1 = Point x1 y1 >> >> instance Number v => Number (Point v) where >> (+) a b = xy (x a Moving.+ x b) (y a Moving.+ y b) >> (-) a b = xy (x a Moving.- x b) (y a Moving.- y b) >> >> >> md1,md2,md3,md4 :: Moving Double >> md1 (Time x) = 0.0 >> md2 (Time x) = 0.0 >> md3 (Time x) = 10.0 >> md4 (Time x) = 10.0 >> testMD1 = (md1 (Time 2.0)) >> testX = x (Point md1 md2) (Time 2.0) >> testY = y (Point md1 md2) (Time 2.0) >> testXY = (xy md1 md2)::(Point (Moving Double)) >> testX' = x testXY (Time 1.0) >> testD = dist (Point md1 md2) (Point md3 md4) (Time 1.0) >> >> --- I cannot get the rest to work >> >> [1] Ontology for Spatio-temporal Databases >> http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113 >> .9804&rep=rep1&type=pdf >> >> On 7 October 2017 at 23:30, Thomas Jakway wrote: >> >>> You could hide Prelude and define it yourself in a different module but >>> that would be a pretty bad idea. Everyone who wanted to use it would have >>> to import your module qualified and refer to it as MyModule.+, which >>> defeats the point of making it (+) and not `myAdditionFunction` in the >>> first place. >>> >>> Haskell deliberately doesn't allow overloading. Having (+) return >>> something other than Num would be extremely confusing. >>> >>> On 10/07/2017 05:07 AM, PATRICK BROWNE wrote: >>> >>> Hi, >>> Is there a way rewriting the definition of (+) so that testPlusArg >>> returns a (Moving Double). My current intuition is that the signature [(+) >>> :: a -> a -> a] says that the type should be the same as the arguments. >>> And indeed (:t testPlus) confirms this. But the type of testPlusArg is a >>> Double. >>> Can I make it (Moving Double) ? >>> Thanks, >>> Pat >>> >>> >>> {-# LANGUAGE FlexibleInstances #-} >>> {-# LANGUAGE TypeSynonymInstances #-} >>> module Moving where >>> data Time = Time Double >>> type Moving v = Time -> v >>> >>> class Number a where >>> (+) :: a -> a -> a >>> >>> instance Number (Moving Double) where >>> (+) a b = \t -> ((a t) Prelude.+ (b t)) >>> >>> a,b :: Moving Double >>> a (Time x) = 2.0 >>> b (Time x) = 2.0 >>> testPlus ::(Moving Double) >>> testPlus = (a Moving.+ b) >>> testPlusArg = (a Moving.+ b) (Time 2.0) >>> >>> This email originated from DIT. If you received this email in error, >>> please delete it from your system. Please note that if you are not the >>> named addressee, disclosing, copying, distributing or taking any action >>> based on the contents of this email or attachments is prohibited. >>> www.dit.ie >>> >>> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo >>> trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an >>> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon >>> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa >>> ríomhphost nó sna hiatáin seo. www.dit.ie >>> >>> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to >>> Grangegorman >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> This email originated from DIT. If you received this email in error, >> please delete it from your system. Please note that if you are not the >> named addressee, disclosing, copying, distributing or taking any action >> based on the contents of this email or attachments is prohibited. >> www.dit.ie >> >> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí >> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an >> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon >> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa >> ríomhphost nó sna hiatáin seo. www.dit.ie >> >> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to >> Grangegorman >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Fri Oct 13 18:15:23 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Fri, 13 Oct 2017 19:15:23 +0100 Subject: [Haskell-beginners] monad question Message-ID: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> I have cap :: String -> String cap = toUpper rev :: String -> String rev = reverse then I make tupled :: String -> (String, String) tupled = do r <- rev c <- cap return (r, c) and to be honest, yes it’s been a long day at work, and this is coding at home rather than coding (java) at work but I’m not sure how tupled works!!! My first shot was supplying a param s like this tupled :: String -> (String, String) tupled s = do r <- rev s c <- cap s return (r, c) which doesn’t compile. But how does the first version work? How does the string to be processed get into the rev and cap functions?? Thanks Mike From toad3k at gmail.com Fri Oct 13 18:35:22 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 13 Oct 2017 14:35:22 -0400 Subject: [Haskell-beginners] monad question In-Reply-To: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> References: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> Message-ID: Functions are Monads. :i Monad class Applicative m => Monad (m :: * -> *) where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a ... instance Monad (Either e) -- Defined in ‘Data.Either’ instance Monad [] -- Defined in ‘GHC.Base’ ... instance Monad ((->) r) -- Defined in ‘GHC.Base’ That last instance means if I have a function whose first argument is type r, that is a monad. And if you fill in the types of the various monad functions you would get something like this (>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b) (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified return :: a -> (r -> a) So in the same way that (IO String) is a Monad and can use do notation, (a -> String) is also a Monad, and can also use do notation. Hopefully that made sense. On Fri, Oct 13, 2017 at 2:15 PM, mike h wrote: > > I have > > cap :: String -> String > cap = toUpper > > rev :: String -> String > rev = reverse > > then I make > > tupled :: String -> (String, String) > tupled = do > r <- rev > c <- cap > return (r, c) > > and to be honest, yes it’s been a long day at work, and this is coding at > home rather than coding (java) at work but > I’m not sure how tupled works!!! > My first shot was supplying a param s like this > > tupled :: String -> (String, String) > tupled s = do > r <- rev s > c <- cap s > return (r, c) > > which doesn’t compile. But how does the first version work? How does the > string to be processed get into the rev and cap functions?? > > Thanks > > Mike > > > > > _______________________________________________ > 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 mike_k_houghton at yahoo.co.uk Fri Oct 13 19:05:28 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Fri, 13 Oct 2017 20:05:28 +0100 Subject: [Haskell-beginners] monad question In-Reply-To: References: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> Message-ID: <04D773AF-E78B-494D-9FD6-F81EBDE71790@yahoo.co.uk> That certainly helps me David, thanks. How then would you write > tupled :: String -> (String, String) with the parameter written explicitly? i.e. tupled s = do … or does the question not make sense in light of your earlier reply? Thanks Mike > On 13 Oct 2017, at 19:35, David McBride wrote: > > Functions are Monads. > > :i Monad > class Applicative m => Monad (m :: * -> *) where > (>>=) :: m a -> (a -> m b) -> m b > (>>) :: m a -> m b -> m b > return :: a -> m a > ... > instance Monad (Either e) -- Defined in ‘Data.Either’ > instance Monad [] -- Defined in ‘GHC.Base’ > ... > instance Monad ((->) r) -- Defined in ‘GHC.Base’ > > That last instance means if I have a function whose first argument is type r, that is a monad. And if you fill in the types of the various monad functions you would get something like this > > (>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b) > (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified > return :: a -> (r -> a) > > So in the same way that (IO String) is a Monad and can use do notation, (a -> String) is also a Monad, and can also use do notation. Hopefully that made sense. > > On Fri, Oct 13, 2017 at 2:15 PM, mike h > wrote: > > I have > > cap :: String -> String > cap = toUpper > > rev :: String -> String > rev = reverse > > then I make > > tupled :: String -> (String, String) > tupled = do > r <- rev > c <- cap > return (r, c) > > and to be honest, yes it’s been a long day at work, and this is coding at home rather than coding (java) at work but > I’m not sure how tupled works!!! > My first shot was supplying a param s like this > > tupled :: String -> (String, String) > tupled s = do > r <- rev s > c <- cap s > return (r, c) > > which doesn’t compile. But how does the first version work? How does the string to be processed get into the rev and cap functions?? > > Thanks > > Mike > > > > > _______________________________________________ > 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 toad3k at gmail.com Fri Oct 13 19:13:31 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 13 Oct 2017 15:13:31 -0400 Subject: [Haskell-beginners] monad question In-Reply-To: <04D773AF-E78B-494D-9FD6-F81EBDE71790@yahoo.co.uk> References: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> <04D773AF-E78B-494D-9FD6-F81EBDE71790@yahoo.co.uk> Message-ID: If you are using do notation, you can't. If you aren't you can write tupled s = (rev s, cap s) Your old tupled is equivalent to this tupled = rev >>= \s -> cap >>= \c -> return (s, c) which is quite different. On Fri, Oct 13, 2017 at 3:05 PM, mike h wrote: > That certainly helps me David, thanks. > How then would you write > > tupled :: String -> (String, String) > > > > with the parameter written explicitly? i.e. > > tupled s = do … > > or does the question not make sense in light of your earlier reply? > > Thanks > > Mike > > > > > On 13 Oct 2017, at 19:35, David McBride wrote: > > Functions are Monads. > > :i Monad > class Applicative m => Monad (m :: * -> *) where > (>>=) :: m a -> (a -> m b) -> m b > (>>) :: m a -> m b -> m b > return :: a -> m a > ... > instance Monad (Either e) -- Defined in ‘Data.Either’ > instance Monad [] -- Defined in ‘GHC.Base’ > ... > instance Monad ((->) r) -- Defined in ‘GHC.Base’ > > That last instance means if I have a function whose first argument is type > r, that is a monad. And if you fill in the types of the various monad > functions you would get something like this > > (>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b) > (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified > return :: a -> (r -> a) > > So in the same way that (IO String) is a Monad and can use do notation, (a > -> String) is also a Monad, and can also use do notation. Hopefully that > made sense. > > On Fri, Oct 13, 2017 at 2:15 PM, mike h > wrote: > >> >> I have >> >> cap :: String -> String >> cap = toUpper >> >> rev :: String -> String >> rev = reverse >> >> then I make >> >> tupled :: String -> (String, String) >> tupled = do >> r <- rev >> c <- cap >> return (r, c) >> >> and to be honest, yes it’s been a long day at work, and this is coding at >> home rather than coding (java) at work but >> I’m not sure how tupled works!!! >> My first shot was supplying a param s like this >> >> tupled :: String -> (String, String) >> tupled s = do >> r <- rev s >> c <- cap s >> return (r, c) >> >> which doesn’t compile. But how does the first version work? How does the >> string to be processed get into the rev and cap functions?? >> >> Thanks >> >> Mike >> >> >> >> >> _______________________________________________ >> 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 > > > > _______________________________________________ > 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 mike_k_houghton at yahoo.co.uk Sat Oct 14 18:37:49 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Sat, 14 Oct 2017 19:37:49 +0100 Subject: [Haskell-beginners] monad question In-Reply-To: References: <513B83F7-B469-4967-8DEB-9CF281E6D6A0@yahoo.co.uk> <04D773AF-E78B-494D-9FD6-F81EBDE71790@yahoo.co.uk> Message-ID: <43F9E6C6-0E4E-4EA4-9443-EE1D58916C47@yahoo.co.uk> Thanks David. > On 13 Oct 2017, at 20:13, David McBride wrote: > > If you are using do notation, you can't. If you aren't you can write > > tupled s = (rev s, cap s) > > Your old tupled is equivalent to this > > tupled = rev >>= \s -> cap >>= \c -> return (s, c) > > which is quite different. > > On Fri, Oct 13, 2017 at 3:05 PM, mike h > wrote: > That certainly helps me David, thanks. > How then would you write >> tupled :: String -> (String, String) > > > with the parameter written explicitly? i.e. > > tupled s = do … > > or does the question not make sense in light of your earlier reply? > > Thanks > > Mike > > > > >> On 13 Oct 2017, at 19:35, David McBride > wrote: >> >> Functions are Monads. >> >> :i Monad >> class Applicative m => Monad (m :: * -> *) where >> (>>=) :: m a -> (a -> m b) -> m b >> (>>) :: m a -> m b -> m b >> return :: a -> m a >> ... >> instance Monad (Either e) -- Defined in ‘Data.Either’ >> instance Monad [] -- Defined in ‘GHC.Base’ >> ... >> instance Monad ((->) r) -- Defined in ‘GHC.Base’ >> >> That last instance means if I have a function whose first argument is type r, that is a monad. And if you fill in the types of the various monad functions you would get something like this >> >> (>>=) :: ((->) r) a -> (a -> ((-> r) b) -> ((-> r) b) >> (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b) -- simplified >> return :: a -> (r -> a) >> >> So in the same way that (IO String) is a Monad and can use do notation, (a -> String) is also a Monad, and can also use do notation. Hopefully that made sense. >> >> On Fri, Oct 13, 2017 at 2:15 PM, mike h > wrote: >> >> I have >> >> cap :: String -> String >> cap = toUpper >> >> rev :: String -> String >> rev = reverse >> >> then I make >> >> tupled :: String -> (String, String) >> tupled = do >> r <- rev >> c <- cap >> return (r, c) >> >> and to be honest, yes it’s been a long day at work, and this is coding at home rather than coding (java) at work but >> I’m not sure how tupled works!!! >> My first shot was supplying a param s like this >> >> tupled :: String -> (String, String) >> tupled s = do >> r <- rev s >> c <- cap s >> return (r, c) >> >> which doesn’t compile. But how does the first version work? How does the string to be processed get into the rev and cap functions?? >> >> Thanks >> >> Mike >> >> >> >> >> _______________________________________________ >> 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 > > > _______________________________________________ > 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 sumitraja at gmail.com Mon Oct 16 11:34:48 2017 From: sumitraja at gmail.com (Sumit Raja) Date: Mon, 16 Oct 2017 22:34:48 +1100 Subject: [Haskell-beginners] Safe TCP accept loop Message-ID: <59e4995b.0947620a.72c1d.9b14@mx.google.com> Hello, I’ve looked at https://wiki.haskell.org/Concurrency_demos/Graceful_exit and used(2) Using throwTo without the use of block and unblock. It runs on 8.2.1 with my limited testing. I can’t find out much about what the > 7.x GHC replacement for block/unblock is other than mask. What does the unblock do in acceptConnections'? Does this method of handling an accept loop still need masking of async exceptions ? If so where does this need to be done? Thanks Sumit -------------- next part -------------- An HTML attachment was scrubbed... URL: From wink at saville.com Tue Oct 17 17:28:20 2017 From: wink at saville.com (Wink Saville) Date: Tue, 17 Oct 2017 17:28:20 +0000 Subject: [Haskell-beginners] Multiple parameters vs anonymous syntax Message-ID: I'm going through "Haskell Programming from first principles" and in section 7.3 Anonymous Functions there is an exercise on converting multiple parameters to anonymous functions, and it asks: 1. Which (two or more) of the following are equivalent? mTh1 x y z = x * y * z mTh2 x y = \z -> x * y * z mTh3 x = \y -> \z -> x * y * z mTh4 = \x -> \y -> \z -> x * y * z So I created a file, anon.hs (attached): module Anon where mTh1 x y z = x * y * z mTh2 x y = \z -> x * y * z mTh3 x = \y -> \z -> x * y * z mTh4 = \x -> \y -> \z -> x * y * z I load that into ghci and check the function types: $ ghci anon.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Anon ( anon.hs, interpreted ) Ok, 1 module loaded. *Anon> :t mTh1 mTh1 :: Num a => a -> a -> a -> a *Anon> :t mTh2 mTh2 :: Num a => a -> a -> a -> a *Anon> :t mTh3 mTh3 :: Num a => a -> a -> a -> a *Anon> :t mTh4 mTh4 :: Integer -> Integer -> Integer -> Integer Why is mTh4 different from the rest? On the flip side If I enter "mTh4 = \x -> \y -> \z -> x * y * z" directly in ghci command line then it has same type as the others: $ ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Prelude> mTh4 = \x -> \y -> \z -> x * y * z Prelude> :t mTh4 mTh4 :: Num a => a -> a -> a -> a -- Wink -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: anon.hs Type: text/x-haskell Size: 135 bytes Desc: not available URL: From toad3k at gmail.com Tue Oct 17 17:52:48 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 17 Oct 2017 13:52:48 -0400 Subject: [Haskell-beginners] Multiple parameters vs anonymous syntax In-Reply-To: References: Message-ID: It is because of NoMomomorphismRestriction >let mTh4 = \x -> \y -> \z -> x * y * z >:t mTh4 mTh4 :: Integer -> Integer -> Integer -> Integer >:set -XNoMonomorphismRestriction >let mTh4 = \x -> \y -> \z -> x * y * z >:t mTh4 mTh4 :: Num a => a -> a -> a -> a I'm not going into it too deeply, as it is somewhat involved and you can read about it but I believe when a function "takes no arguments", it is allowed to specialize polymorphic variables to defaults, and due to the Num constraint it chooses Integer. On Tue, Oct 17, 2017 at 1:28 PM, Wink Saville wrote: > I'm going through "Haskell Programming from first principles" and in > section 7.3 Anonymous Functions there is an exercise on converting multiple > parameters to anonymous functions, and it asks: > > 1. Which (two or more) of the following are equivalent? > > mTh1 x y z = x * y * z > mTh2 x y = \z -> x * y * z > mTh3 x = \y -> \z -> x * y * z > mTh4 = \x -> \y -> \z -> x * y * z > > So I created a file, anon.hs (attached): > > module Anon where > > mTh1 x y z = x * y * z > mTh2 x y = \z -> x * y * z > mTh3 x = \y -> \z -> x * y * z > mTh4 = \x -> \y -> \z -> x * y * z > > I load that into ghci and check the function types: > > $ ghci anon.hs > GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help > [1 of 1] Compiling Anon ( anon.hs, interpreted ) > Ok, 1 module loaded. > *Anon> :t mTh1 > mTh1 :: Num a => a -> a -> a -> a > *Anon> :t mTh2 > mTh2 :: Num a => a -> a -> a -> a > *Anon> :t mTh3 > mTh3 :: Num a => a -> a -> a -> a > *Anon> :t mTh4 > mTh4 :: Integer -> Integer -> Integer -> Integer > > Why is mTh4 different from the rest? > > > On the flip side If I enter "mTh4 = \x -> \y -> \z -> x * y * z" directly > in ghci command line then it has same type as the others: > > $ ghci > GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help > Prelude> mTh4 = \x -> \y -> \z -> x * y * z > Prelude> :t mTh4 > mTh4 :: Num a => a -> a -> a -> a > > > -- Wink > > > _______________________________________________ > 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 wink at saville.com Tue Oct 17 18:30:11 2017 From: wink at saville.com (Wink Saville) Date: Tue, 17 Oct 2017 18:30:11 +0000 Subject: [Haskell-beginners] Multiple parameters vs anonymous syntax In-Reply-To: References: Message-ID: Thank you, my head's spinning just starting to read [1] :) BTW, you led me to find the answer to why ghci was different in the interactive mode vs loading. I discovered there are two sets of options used for ghci which are controlled by ":set" and ":seti", [2]. And in the interactive mode we see -XNoMonomorphismRestriction is in effect: Prelude> :seti base language is: Haskell2010 with the following modifiers: -XExtendedDefaultRules -XNoMonomorphismRestriction -XNondecreasingIndentation GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fimplicit-import-qualified warning settings: But it's not in the "non-interactive" mode: Prelude> :set options currently set: none. base language is: Haskell2010 with the following modifiers: -XNondecreasingIndentation GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fimplicit-import-qualified warning settings: [1]: https://wiki.haskell.org/Monomorphism_restriction [2]: https://downloads.haskell.org/~ghc/7.8.4/docs/html/users_guide/ghci-set.html On Tue, Oct 17, 2017 at 10:53 AM David McBride wrote: > It is because of NoMomomorphismRestriction > > >let mTh4 = \x -> \y -> \z -> x * y * z > > >:t mTh4 > mTh4 :: Integer -> Integer -> Integer -> Integer > >:set -XNoMonomorphismRestriction > >let mTh4 = \x -> \y -> \z -> x * y * z > > >:t mTh4 > mTh4 :: Num a => a -> a -> a -> a > > I'm not going into it too deeply, as it is somewhat involved and you can > read about it but I believe when a function "takes no arguments", it is > allowed to specialize polymorphic variables to defaults, and due to the Num > constraint it chooses Integer. > > On Tue, Oct 17, 2017 at 1:28 PM, Wink Saville wrote: > >> I'm going through "Haskell Programming from first principles" and in >> section 7.3 Anonymous Functions there is an exercise on converting multiple >> parameters to anonymous functions, and it asks: >> >> 1. Which (two or more) of the following are equivalent? >> >> mTh1 x y z = x * y * z >> mTh2 x y = \z -> x * y * z >> mTh3 x = \y -> \z -> x * y * z >> mTh4 = \x -> \y -> \z -> x * y * z >> >> So I created a file, anon.hs (attached): >> >> module Anon where >> >> mTh1 x y z = x * y * z >> mTh2 x y = \z -> x * y * z >> mTh3 x = \y -> \z -> x * y * z >> mTh4 = \x -> \y -> \z -> x * y * z >> >> I load that into ghci and check the function types: >> >> $ ghci anon.hs >> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >> [1 of 1] Compiling Anon ( anon.hs, interpreted ) >> Ok, 1 module loaded. >> *Anon> :t mTh1 >> mTh1 :: Num a => a -> a -> a -> a >> *Anon> :t mTh2 >> mTh2 :: Num a => a -> a -> a -> a >> *Anon> :t mTh3 >> mTh3 :: Num a => a -> a -> a -> a >> *Anon> :t mTh4 >> mTh4 :: Integer -> Integer -> Integer -> Integer >> >> Why is mTh4 different from the rest? >> >> >> On the flip side If I enter "mTh4 = \x -> \y -> \z -> x * y * z" directly >> in ghci command line then it has same type as the others: >> >> $ ghci >> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >> Prelude> mTh4 = \x -> \y -> \z -> x * y * z >> Prelude> :t mTh4 >> mTh4 :: Num a => a -> a -> a -> a >> >> >> -- Wink >> >> >> _______________________________________________ >> 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 aquagnu at gmail.com Wed Oct 18 10:08:13 2017 From: aquagnu at gmail.com (PY) Date: Wed, 18 Oct 2017 13:08:13 +0300 Subject: [Haskell-beginners] Dispatch on implemented instances Message-ID: Hello, everyone! I want to call one function (or the same but with a special argument, no matter) if a type instantiates some type-class or another - if not. I know that it's easy in languages like D, Java, possible C++ - we can specialize templates more generic or less generic and to restrict its parameters with class/interface implementation/extending (there are special keywords/type operators for it, used in generics/templates signatures). So, I suppose Haskell can do the same. But as it turned out, this is not so easy for Haskell :( I found these useful links: * https://stackoverflow.com/questions/26303353/can-multiple-dispatch-be-achieved-in-haskell-with-pattern-matching-on-type-class * https://wiki.haskell.org/GHC/AdvancedOverlap So, I wrote something like this (this example is compiling and works as I expect, you need `mustache` and `network-uri` packages). Goal is to substitute type in special way for HTML template and for text template if type implements a special interface (for deterministic substitution). Otherwise default substitution will be used. Actually, this code allows usage of not only HTML/text templates... OK, here it is: {-# LANGUAGE EmptyDataDecls         #-} {-# LANGUAGE FlexibleInstances      #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses  #-} {-# LANGUAGE OverloadedStrings      #-} {-# LANGUAGE ScopedTypeVariables    #-} {-# LANGUAGE TypeFamilies           #-} {-# LANGUAGE UndecidableInstances   #-} import           Data.Semigroup      ((<>)) import qualified Data.Text           as T import           Network.URI import qualified Text.Mustache.Types as MUT type Link = (T.Text, URI) -- caption and URL, for example -- |Converts a type to substitutable to Mustache template entity based on 'SubTo' template selector. -- @sub@ must be ignored in implementation class ToMustaches sub a where   toMustaches :: sub -> a -> SubTo -> MUT.Value -- |Substituted to HTML either to text data SubTo = ToHtml | ToText -- |Deterministic substitution data DetSub -- |Universal substitution data UniSub -- |Substitution predicate: it's determined uniquely for type class SubPred a sub | a -> sub -- TODO rename ToMustaches' (ToMustaches' ?) class ToMustaches' a where   toMustaches' :: a -> SubTo -> MUT.Value instance (SubPred a sub, ToMustaches sub a) => ToMustaches' a where   toMustaches' a to = toMustaches (undefined::sub) a to -- See: -- * https://stackoverflow.com/questions/36913922/how-to-resolve-overlapping-instance -- * https://stackoverflow.com/questions/26303353/can-multiple-dispatch-be-achieved-in-haskell-with-pattern-matching-on-type-class instance {-# OVERLAPS #-} (sub ~ UniSub) => SubPred a sub -- 'Link' can be substituted deterministically instance SubPred Link DetSub instance ToMustaches DetSub Link where   toMustaches _ (_, url)   ToText = MUT.String $ T.pack $ show url   toMustaches _ (cap, url) ToHtml = MUT.String (" (T.pack $ show url) <> "\">" <> cap <> "") -- |All other types which does not implements 'ToMustaches' default instance transforms them to string w/ 'Show' instance Show a => ToMustaches UniSub a where   toMustaches _ a _ = MUT.String $ T.pack $ show a ------------------------------------------------------------------- main :: IO () main = do   let     uri = URI "http:" (Just $ URIAuth "" "wikipedia.org" "") "" "" ""     lnk = ("wikipedia", uri)::Link     txt = "Hello world"::T.Text     n = 444::Int   print $ toMustaches' lnk ToText   print $ toMustaches' lnk ToHtml   print $ toMustaches' txt ToHtml   print $ toMustaches' n ToText I don't know am I understand correctly the Haskell solution but this looks close to explained in the Haskell Wiki (case 1). But in all cases I see problem: always I need not only to implement this special interface but to "say" that a type implements special (deterministic) substitution, see: instance SubPred Link DetSub This means that clients of this code must "implements" 2 instances: 1) of ToMustaches and 2) of SubPred (with DetSub as last type param). This is terrible and no such thing  in other languages! So, my question is: is a simple way to avoid it? === Best regards, Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From gints.dreimanis at serokell.io Wed Oct 18 15:49:57 2017 From: gints.dreimanis at serokell.io (Gints Dreimanis) Date: Wed, 18 Oct 2017 18:49:57 +0300 Subject: [Haskell-beginners] =?utf-8?b?SGFjayDigJxJbXBvcnRpZnnigJ0gYnkg?= =?utf-8?q?Serokell_During_=23Hacktoberfest!?= Message-ID: All of us love to read explicit import lists (especially in an unknown module), but we all hate to write and maintain them. >From our point of view, it is obligatory for any code that goes into production to have only explicit imports. That way, the code is easier to comprehend – no one is confused about the location of a stray type or identifier, even when reading from GitHub or a simple editor. There are, however, usability and maintainability issues with explicit imports, which make enforcing explicit imports in style guides a topic for discussion. To enjoy the benefits of explicit imports while keeping the drawbacks in check, we have implemented *Importify*. *Importify* is a tool developed by Serokell tooling team led by Dmitry Kovalnikov. It is a refactoring tool that helps import management in Haskell code. We’re getting close to releasing it on Hackage, but it requires some polishing. You can contribute to Importify and Serokell’s own custom Prelude Universum during Hacktoberfest . *Importify* is all about decluttering the import blocks. It can remove: - unused symbols in explicit import lists - unused qualified imports - unused implicit imports - unnecessarily hidden symbols Highlights of the functionality of *Importify* are that it works deeply with explicit import lists (it can, for instance, remove unused constructors), and it works with hiding imports. The latter feature isn’t present in any open-source refactoring tool that is known to us. It is also compatible with autoexporter . *Importify *works extremely well with large Haskell projects — we use it to great success to clean up Cardano SL . Importify only parses source code instead of building projects. For a project of the size of Cardano SL it takes only two minutes to build Importify cache while building it would take forty minutes on the same machine. In the future, we plan for *Importify *to be able to add used symbols to imports automatically. To speed up *Importify *runs, we will implement a cache server that caches each Hackage package. You will be able to upload caches for your projects there as well. Next on the roadmap is functionality to convert imports between *implicit* and *explicit*, and between *qualified* and *unqualified* forms. Finally, we will be adding functionality to resolve merge conflicts in import section automatically. If you notice that managing imports becomes a slog, feel free to try this tool out yourself. Spotted a bug? Contact us. To those, who are in the mood for some hacking this Autumn, we’re looking forward to your #Hacktoberfest contributions! -------------- next part -------------- An HTML attachment was scrubbed... URL: From wink at saville.com Fri Oct 20 00:13:43 2017 From: wink at saville.com (Wink Saville) Date: Fri, 20 Oct 2017 00:13:43 +0000 Subject: [Haskell-beginners] Where clause indentation Message-ID: I created a file with the dividedBy example from Chapter 8.5 of "Haskell Programming from first principles" : dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) I get the following error when I load into ghci: $ ghci chapter8_5-IntegralDivision.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/wink/.ghci [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, interpreted ) chapter8_5-IntegralDivision.hs:4:7: error: parse error (possibly incorrect indentation or mismatched brackets) | 4 | | n < d = (count, n) | ^ Failed, 0 modules loaded. λ> But if I put the "go" function on its own line: dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) It does compile: $ ghci chapter8_5-IntegralDivision.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/wink/.ghci [1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.hs, interpreted ) Ok, 1 module loaded. Or I can put the "where" on the previous line: dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) it also compiles: $ ghci chapter8_5-IntegralDivision.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/wink/.ghci [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, interpreted ) Ok, 1 module loaded. λ> Can someone shed light on what I've done wrong? -- Wink -------------- next part -------------- An HTML attachment was scrubbed... URL: From rebecca.li at kittyhawk.aero Fri Oct 20 00:33:46 2017 From: rebecca.li at kittyhawk.aero (Rebecca Li) Date: Thu, 19 Oct 2017 17:33:46 -0700 Subject: [Haskell-beginners] Where clause indentation In-Reply-To: References: Message-ID: I believe for where (as well as with let, or any other special phrasing), if you're putting something on the same line with it, the subsequent lines have to begin after the end of the indentation of the word "where" or "let". A version I got ghc to accept: dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) A similar example with let would be the following, where b lines up with a let a = blah b = blah' but this would not work since b is only one level indented, not matching a. let a = blah b = blah Hopefully the formatting goes through email.. On Thu, Oct 19, 2017 at 5:13 PM, Wink Saville wrote: > I created a file with the dividedBy example from Chapter 8.5 of "Haskell > Programming from first principles" : > > dividedBy :: Integral a => a -> a -> (a, a) > dividedBy num denom = go num denom 0 > where go n d count > | n < d = (count, n) > | otherwise = go (n - d) d (count + 1) > > > I get the following error when I load into ghci: > > $ ghci chapter8_5-IntegralDivision.hs > GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help > Loaded GHCi configuration from /home/wink/.ghci > [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, > interpreted ) > > chapter8_5-IntegralDivision.hs:4:7: error: > parse error (possibly incorrect indentation or mismatched brackets) > | > 4 | | n < d = (count, n) > | ^ > Failed, 0 modules loaded. > λ> > > > But if I put the "go" function on its own line: > > dividedBy :: Integral a => a -> a -> (a, a) > dividedBy num denom = go num denom 0 > where > go n d count > | n < d = (count, n) > | otherwise = go (n - d) d (count + 1) > > > It does compile: > > $ ghci chapter8_5-IntegralDivision.hs > GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help > Loaded GHCi configuration from /home/wink/.ghci > [1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.hs, > interpreted ) > Ok, 1 module loaded. > > > Or I can put the "where" on the previous line: > > dividedBy :: Integral a => a -> a -> (a, a) > dividedBy num denom = go num denom 0 where > go n d count > | n < d = (count, n) > | otherwise = go (n - d) d (count + 1) > > > it also compiles: > > $ ghci chapter8_5-IntegralDivision.hs > GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help > Loaded GHCi configuration from /home/wink/.ghci > [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, > interpreted ) > Ok, 1 module loaded. > λ> > > > Can someone shed light on what I've done wrong? > > -- Wink > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Rebecca Li rebecca.li at kittyhawk.aero 617-899-2036 -------------- next part -------------- An HTML attachment was scrubbed... URL: From brodyberg at gmail.com Fri Oct 20 01:00:10 2017 From: brodyberg at gmail.com (Brody Berg) Date: Fri, 20 Oct 2017 01:00:10 +0000 Subject: [Haskell-beginners] Where clause indentation In-Reply-To: References: Message-ID: I believe this is all covered starting on page 40 of the latest edition with examples just like Rebecca has shared. On Thu, Oct 19, 2017 at 17:35 Rebecca Li wrote: > I believe for where (as well as with let, or any other special phrasing), > if you're putting something on the same line with it, the subsequent lines > have to begin after the end of the indentation of the word "where" or > "let". > > A version I got ghc to accept: > > dividedBy :: Integral a => a -> a -> (a, a) > dividedBy num denom = go num denom 0 > where go n d count > | n < d = (count, n) > | otherwise = go (n - d) d (count + 1) > > A similar example with let would be the following, where b lines up with a > let a = blah > b = blah' > > but this would not work since b is only one level indented, not matching > a. > let a = blah > b = blah > > Hopefully the formatting goes through email.. > > > > On Thu, Oct 19, 2017 at 5:13 PM, Wink Saville wrote: > >> I created a file with the dividedBy example from Chapter 8.5 of "Haskell >> Programming from first principles" : >> >> dividedBy :: Integral a => a -> a -> (a, a) >> dividedBy num denom = go num denom 0 >> where go n d count >> | n < d = (count, n) >> | otherwise = go (n - d) d (count + 1) >> >> >> I get the following error when I load into ghci: >> >> $ ghci chapter8_5-IntegralDivision.hs >> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >> Loaded GHCi configuration from /home/wink/.ghci >> [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, >> interpreted ) >> >> chapter8_5-IntegralDivision.hs:4:7: error: >> parse error (possibly incorrect indentation or mismatched brackets) >> | >> 4 | | n < d = (count, n) >> | ^ >> Failed, 0 modules loaded. >> λ> >> >> >> But if I put the "go" function on its own line: >> >> dividedBy :: Integral a => a -> a -> (a, a) >> dividedBy num denom = go num denom 0 >> where >> go n d count >> | n < d = (count, n) >> | otherwise = go (n - d) d (count + 1) >> >> >> It does compile: >> >> $ ghci chapter8_5-IntegralDivision.hs >> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >> Loaded GHCi configuration from /home/wink/.ghci >> [1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.hs, >> interpreted ) >> Ok, 1 module loaded. >> >> >> Or I can put the "where" on the previous line: >> >> dividedBy :: Integral a => a -> a -> (a, a) >> dividedBy num denom = go num denom 0 where >> go n d count >> | n < d = (count, n) >> | otherwise = go (n - d) d (count + 1) >> >> >> it also compiles: >> >> $ ghci chapter8_5-IntegralDivision.hs >> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >> Loaded GHCi configuration from /home/wink/.ghci >> [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, >> interpreted ) >> Ok, 1 module loaded. >> λ> >> >> >> Can someone shed light on what I've done wrong? >> >> -- Wink >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Rebecca Li > rebecca.li at kittyhawk.aero > 617-899-2036 > _______________________________________________ > 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 wink at saville.com Sat Oct 21 00:19:04 2017 From: wink at saville.com (Wink Saville) Date: Sat, 21 Oct 2017 00:19:04 +0000 Subject: [Haskell-beginners] Where clause indentation In-Reply-To: References: Message-ID: Thanks Rebecca and Brody, I did some additional experimentation and, of course indenting to under the "o" in "go" worked: dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) But under or before the "g" doesn't: dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) Oh and both the following work, at least for me on 8.2.1. Again the critical part was the "|" past the "g" in "go", but the "body" of "where" and "let" can be indented as little as one space, although it would be bad form. dividedBy :: Integral a => a -> a -> (a, a) dividedBy num denom = go num denom 0 where go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) dividedBy' :: Integral a => a -> a -> (a, a) dividedBy' num denom = let numerator = num denominator = denom go n d count | n < d = (count, n) | otherwise = go (n - d) d (count + 1) in go numerator denominator 0 So this make having to indent the "|" in a function seem doubly weird to me, but so be it :) Oh, and on the lastest version I have, haskell-programming-1.0RC2-ereader.pdf, the section Brody mentioned on page 40 seems to be on page 59 in the subsection titled "Troubleshooting" underneath section 2.7 "Declaring Variables. For other novices the haskell wiki indenation page is helpful: https://en.wikibooks.org/wiki/Haskell/Indentation There is even has an example that shows it's not always necessary to indent, just that things need to be aligned. On Thu, Oct 19, 2017 at 6:01 PM Brody Berg wrote: > I believe this is all covered starting on page 40 of the latest edition > with examples just like Rebecca has shared. > > On Thu, Oct 19, 2017 at 17:35 Rebecca Li > wrote: > >> I believe for where (as well as with let, or any other special phrasing), >> if you're putting something on the same line with it, the subsequent lines >> have to begin after the end of the indentation of the word "where" or >> "let". >> >> A version I got ghc to accept: >> >> dividedBy :: Integral a => a -> a -> (a, a) >> dividedBy num denom = go num denom 0 >> where go n d count >> | n < d = (count, n) >> | otherwise = go (n - d) d (count + 1) >> >> A similar example with let would be the following, where b lines up with >> a >> let a = blah >> b = blah' >> >> but this would not work since b is only one level indented, not matching >> a. >> let a = blah >> b = blah >> >> Hopefully the formatting goes through email.. >> >> >> >> On Thu, Oct 19, 2017 at 5:13 PM, Wink Saville wrote: >> >>> I created a file with the dividedBy example from Chapter 8.5 of "Haskell >>> Programming from first principles" : >>> >>> dividedBy :: Integral a => a -> a -> (a, a) >>> dividedBy num denom = go num denom 0 >>> where go n d count >>> | n < d = (count, n) >>> | otherwise = go (n - d) d (count + 1) >>> >>> >>> I get the following error when I load into ghci: >>> >>> $ ghci chapter8_5-IntegralDivision.hs >>> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >>> Loaded GHCi configuration from /home/wink/.ghci >>> [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, >>> interpreted ) >>> >>> chapter8_5-IntegralDivision.hs:4:7: error: >>> parse error (possibly incorrect indentation or mismatched brackets) >>> | >>> 4 | | n < d = (count, n) >>> | ^ >>> Failed, 0 modules loaded. >>> λ> >>> >>> >>> But if I put the "go" function on its own line: >>> >>> dividedBy :: Integral a => a -> a -> (a, a) >>> dividedBy num denom = go num denom 0 >>> where >>> go n d count >>> | n < d = (count, n) >>> | otherwise = go (n - d) d (count + 1) >>> >>> >>> It does compile: >>> >>> $ ghci chapter8_5-IntegralDivision.hs >>> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >>> Loaded GHCi configuration from /home/wink/.ghci >>> [1 of 1] Compiling IntegralDivision ( chapter8_5-IntegralDivision.hs, >>> interpreted ) >>> Ok, 1 module loaded. >>> >>> >>> Or I can put the "where" on the previous line: >>> >>> dividedBy :: Integral a => a -> a -> (a, a) >>> dividedBy num denom = go num denom 0 where >>> go n d count >>> | n < d = (count, n) >>> | otherwise = go (n - d) d (count + 1) >>> >>> >>> it also compiles: >>> >>> $ ghci chapter8_5-IntegralDivision.hs >>> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help >>> Loaded GHCi configuration from /home/wink/.ghci >>> [1 of 1] Compiling Main ( chapter8_5-IntegralDivision.hs, >>> interpreted ) >>> Ok, 1 module loaded. >>> λ> >>> >>> >>> Can someone shed light on what I've done wrong? >>> >>> -- Wink >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> -- >> Rebecca Li >> rebecca.li at kittyhawk.aero >> 617-899-2036 <(617)%20899-2036> >> _______________________________________________ >> 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 50295 at web.de Tue Oct 24 09:17:46 2017 From: 50295 at web.de (Olumide) Date: Tue, 24 Oct 2017 10:17:46 +0100 Subject: [Haskell-beginners] runState (liftM (+100) pop) [1, 2, 3, 4] (Example from LYH) Message-ID: <095d7fe8-6da4-f1ed-19f9-b7b879fbb1ae@web.de> Dear List, Apologies for the awkward question title -- its the best I can do ATM. I'm still working my way through chapter 13 of LYH (title for a few monads more) and I came across the following two beasts ghci> runState (liftM (+100) pop) [1,2,3,4] (101,[2,3,4]) ghci> runState (fmap (+100) pop) [1,2,3,4] (101,[2,3,4]) See http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions Even though I'm still struggling to wrap my mind around monads, I sort of understand what's going on here. The problem is that I can't explain why the function (+100) is applied to _only_ the value 1 in (1,[2,3,4]). Regards, - Olumide From fa-ml at ariis.it Tue Oct 24 09:32:53 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 24 Oct 2017 11:32:53 +0200 Subject: [Haskell-beginners] runState (liftM (+100) pop) [1, 2, 3, 4] (Example from LYH) In-Reply-To: <095d7fe8-6da4-f1ed-19f9-b7b879fbb1ae@web.de> References: <095d7fe8-6da4-f1ed-19f9-b7b879fbb1ae@web.de> Message-ID: <20171024093253.7ssjplja3bxlrbn7@x60s.casa> On Tue, Oct 24, 2017 at 10:17:46AM +0100, Olumide wrote: > ghci> runState (fmap (+100) pop) [1,2,3,4] > (101,[2,3,4]) > > Even though I'm still struggling to wrap my mind around monads, I sort of > understand what's going on here. The problem is that I can't explain why the > function (+100) is applied to _only_ the value 1 in (1,[2,3,4]). Hello Olumide, if we look at the instance of `fmap` for State we'll find (more or less): fmap :: (a -> b) -> State s a -> State s b So fmap modifies the *result*, not the *state* itself. If we also recall that `State s a` is nothing but `\s -> (a, s)` then it is easy to see that only the first element of the tuple (the so called result, `a`) will be modified. Does this clear your doubts? From martin.drautzburg at web.de Tue Oct 24 10:18:10 2017 From: martin.drautzburg at web.de (martin) Date: Tue, 24 Oct 2017 12:18:10 +0200 Subject: [Haskell-beginners] Manipulate list, one element at a time Message-ID: <59EF1362.1020902@web.de> Hello all, How can I do something to each element of a list, but only modify one element at at time, so the result is a list of lists, where each sublist is the original list with one element altered. Something like type Each a = (a->a) -> [a] -> [[a]] I came up with: each :: Each a each f [] = [] each f (x:xs) = (f x : xs) : (map (x:) $ each f xs) λ> each (*10) [1..3] [[10,2,3],[1,20,3],[1,2,30]] but I wonder if there is a more standard way of doing this From raabe at froglogic.com Tue Oct 24 10:59:57 2017 From: raabe at froglogic.com (Frerich Raabe) Date: Tue, 24 Oct 2017 12:59:57 +0200 Subject: [Haskell-beginners] Manipulate list, one element at a time In-Reply-To: <59EF1362.1020902@web.de> References: <59EF1362.1020902@web.de> Message-ID: <8303af7029808d9b437e649409beca98@froglogic.com> On 2017-10-24 12:18, martin wrote: > How can I do something to each element of a list, but only modify one > element at at time, so the result is a list of > lists, where each sublist is the original list with one element altered. > > Something like [..] > λ> each (*10) [1..3] > [[10,2,3],[1,20,3],[1,2,30]] You could make use of the 'inits' and 'tails' functions from Data.List: λ: inits [1..3] [[],[1],[1,2],[1,2,3]] λ: tails [1..3] [[1,2,3],[2,3],[3],[]] Using this, you could build a little list comprehension which takes every head and every tail and produces a list in which the two are concatenated, except that the first element of the tail has some function applied to it: λ: let each f xs = [i ++ f t:ts | (i, t:ts) <- zip (inits xs) (tails xs)] λ: :t each each :: (a -> a) -> [a] -> [[a]] λ: each (*10) [1..3] [[10,2,3],[1,20,3],[1,2,30]] -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From aquagnu at gmail.com Wed Oct 25 10:56:31 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 25 Oct 2017 13:56:31 +0300 Subject: [Haskell-beginners] Is it possible such Monad? Message-ID: <20171025135631.1f9913d2@Pavel> Hello All! Is it possible to write Monad for such type: data Allpass w m a = Nopass (m a) w | Allpass (m a) w I can write (>>=), IMHO such type can not be Monad due to `w` is not under `m` monad, right? === Best regards, Paul From traqueofziche at gmail.com Thu Oct 26 02:07:39 2017 From: traqueofziche at gmail.com (=?UTF-8?B?6bKN5Yev5paH?=) Date: Thu, 26 Oct 2017 02:07:39 +0000 Subject: [Haskell-beginners] Is it possible such Monad? (Baa) In-Reply-To: References: Message-ID: Hi, 1. I think your data type is isomorphic to data Allpass w m a = Pass Bool (m a) w 2. Maybe first try to write a Functor instance? Then you can find out what constraints are necessary for 'w' and 'm' to write it. 3. What does this data type intend to represent? Best, toz On Wed, Oct 25, 2017 at 5:32 AM wrote: > Send Beginners mailing list submissions to > beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > or, via email, send a message with subject or body 'help' to > beginners-request at haskell.org > > You can reach the person managing the list at > beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > > Today's Topics: > > 1. Is it possible such Monad? (Baa) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 25 Oct 2017 13:56:31 +0300 > From: Baa > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: [Haskell-beginners] Is it possible such Monad? > Message-ID: <20171025135631.1f9913d2 at Pavel> > Content-Type: text/plain; charset=US-ASCII > > Hello All! > > Is it possible to write Monad for such type: > > data Allpass w m a = Nopass (m a) w | Allpass (m a) w > > I can write (>>=), IMHO such type can not be Monad due to `w` is not > under `m` monad, right? > > > === > Best regards, Paul > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 112, Issue 22 > ****************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Thu Oct 26 07:54:04 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 26 Oct 2017 10:54:04 +0300 Subject: [Haskell-beginners] Is it possible such Monad? (Baa) In-Reply-To: References: Message-ID: <20171026105404.15f6bd24@Pavel> Primary idea was to keep error messages. OK, I done it with `State` monad :) Thank you! > Hi, > > 1. I think your data type is isomorphic to > > data Allpass w m a = Pass Bool (m a) w > > 2. Maybe first try to write a Functor instance? Then you can find out > what constraints are necessary for 'w' and 'm' to write it. > > 3. What does this data type intend to represent? > > Best, > > toz > > On Wed, Oct 25, 2017 at 5:32 AM wrote: > > > Send Beginners mailing list submissions to > > beginners at haskell.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > or, via email, send a message with subject or body 'help' to > > beginners-request at haskell.org > > > > You can reach the person managing the list at > > beginners-owner at haskell.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Beginners digest..." > > > > > > Today's Topics: > > > > 1. Is it possible such Monad? (Baa) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Wed, 25 Oct 2017 13:56:31 +0300 > > From: Baa > > To: The Haskell-Beginners Mailing List - Discussion of primarily > > beginner-level topics related to Haskell > > Subject: [Haskell-beginners] Is it possible > > such Monad? Message-ID: <20171025135631.1f9913d2 at Pavel> > > Content-Type: text/plain; charset=US-ASCII > > > > Hello All! > > > > Is it possible to write Monad for such type: > > > > data Allpass w m a = Nopass (m a) w | Allpass (m a) w > > > > I can write (>>=), IMHO such type can not be Monad due to `w` is not > > under `m` monad, right? > > > > > > === > > Best regards, Paul > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > ------------------------------ > > > > End of Beginners Digest, Vol 112, Issue 22 > > ****************************************** > > From aquagnu at gmail.com Thu Oct 26 10:03:56 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 26 Oct 2017 13:03:56 +0300 Subject: [Haskell-beginners] What's wrong with Haddock?! Message-ID: <20171026130356.0a802023@Pavel> I often hit such errors: parse error on input ‘-- ^ my doc-string is here’ when generate Haddock documentation. This happens on line like: instance Something UTCTime where some a = blahBlah -- ^ my doc-string is here Sometimes such doc-strings are passing, sometimes - not. I can understand what is the reason. Is there some rule how to format such kind of doc-strings? === Cheers, Paul From fa-ml at ariis.it Thu Oct 26 10:25:52 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 26 Oct 2017 12:25:52 +0200 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026130356.0a802023@Pavel> References: <20171026130356.0a802023@Pavel> Message-ID: <20171026102552.qu3hglm2gy74nu35@x60s.casa> On Thu, Oct 26, 2017 at 01:03:56PM +0300, Baa wrote: > Sometimes such doc-strings are passing, sometimes - not. I can > understand what is the reason. Is there some rule how to format such > kind of doc-strings? Hello Paul, can you provide an example of a docstring which makes Haddock choke? From sylvain at haskus.fr Thu Oct 26 10:31:58 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Thu, 26 Oct 2017 12:31:58 +0200 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026130356.0a802023@Pavel> References: <20171026130356.0a802023@Pavel> Message-ID: <2bc9ddbb-c603-c9a9-d8d5-115cd14fb82b@haskus.fr> Just remove the `^` character. `|` and `^` (attaching the comment to the next/previous entity) can't be used everywhere. On 26/10/2017 12:03, Baa wrote: > I often hit such errors: > > parse error on input ‘-- ^ my doc-string is here’ > > when generate Haddock documentation. This happens on line like: > > instance Something UTCTime where > some a = blahBlah -- ^ my doc-string is here > > Sometimes such doc-strings are passing, sometimes - not. I can > understand what is the reason. Is there some rule how to format such > kind of doc-strings? > > > === > Cheers, Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Thu Oct 26 11:11:10 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 26 Oct 2017 14:11:10 +0300 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026102552.qu3hglm2gy74nu35@x60s.casa> References: <20171026130356.0a802023@Pavel> <20171026102552.qu3hglm2gy74nu35@x60s.casa> Message-ID: <20171026141110.4647a635@Pavel> @Francesco Ariis: instance Conversion UTCTime where aspS a = round $ 1E12 * utcTimeToPOSIXSeconds a -- ^as time period from 1970-1-1 frompS a = posixSecondsToUTCTime $ fromInteger $ (round $ d/1E12) -- ^from time period from 1970-1-1 where d = fromInteger a :: Double @Sylvain: sure I can remove "^", but in this case in will be comment, not doc-string; am I right, or? I want to add this string to Haddock generated documentation. So, I see that sometimes no problem with "^..."-style docstrings (attached? or how is it called correctly?). But sometimes their lead to errors. > On Thu, Oct 26, 2017 at 01:03:56PM +0300, Baa wrote: > > Sometimes such doc-strings are passing, sometimes - not. I can > > understand what is the reason. Is there some rule how to format such > > kind of doc-strings? > > Hello Paul, can you provide an example of a docstring which makes > Haddock choke? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fa-ml at ariis.it Thu Oct 26 11:34:38 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 26 Oct 2017 13:34:38 +0200 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026141110.4647a635@Pavel> References: <20171026130356.0a802023@Pavel> <20171026102552.qu3hglm2gy74nu35@x60s.casa> <20171026141110.4647a635@Pavel> Message-ID: <20171026113438.p3o2ihbyeofal4xb@x60s.casa> On Thu, Oct 26, 2017 at 02:11:10PM +0300, Baa wrote: > @Francesco Ariis: > > instance Conversion UTCTime where > aspS a = round $ 1E12 * utcTimeToPOSIXSeconds a -- ^as time period from 1970-1-1 > frompS a = posixSecondsToUTCTime $ fromInteger $ (round $ d/1E12) -- ^from time period from 1970-1-1 > where d = fromInteger a :: Double -- ^ is meant to be put after a function *declaration* iirc. Try to add signatures to your instance as instance Foo Bar where fa :: Int -> a -- ^ some comment fa x = undefined fb :: String -> a -- ^ some more comment fb x = undefined and let us know if it fixed the problem. From aquagnu at gmail.com Thu Oct 26 11:58:43 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 26 Oct 2017 14:58:43 +0300 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026113438.p3o2ihbyeofal4xb@x60s.casa> References: <20171026130356.0a802023@Pavel> <20171026102552.qu3hglm2gy74nu35@x60s.casa> <20171026141110.4647a635@Pavel> <20171026113438.p3o2ihbyeofal4xb@x60s.casa> Message-ID: <20171026145843.189f798c@Pavel> @Francesco: I tried it (added extension InstanceSigs, added "^.."-style docstring), nothing changed. So, may be docstrings in instances are impossible at whole? May be it makes sense... May be they should be documented in its classes instead? > On Thu, Oct 26, 2017 at 02:11:10PM +0300, Baa wrote: > > @Francesco Ariis: > > > > instance Conversion UTCTime where > > aspS a = round $ 1E12 * utcTimeToPOSIXSeconds a -- ^as time > > period from 1970-1-1 frompS a = posixSecondsToUTCTime $ fromInteger > > $ (round $ d/1E12) -- ^from time period from 1970-1-1 where d = > > fromInteger a :: Double > > -- ^ is meant to be put after a function *declaration* iirc. Try to > add signatures to your instance as > > instance Foo Bar where > fa :: Int -> a -- ^ some comment > fa x = undefined > fb :: String -> a -- ^ some more comment > fb x = undefined > > and let us know if it fixed the problem. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fa-ml at ariis.it Thu Oct 26 12:32:10 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 26 Oct 2017 14:32:10 +0200 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026145843.189f798c@Pavel> References: <20171026130356.0a802023@Pavel> <20171026102552.qu3hglm2gy74nu35@x60s.casa> <20171026141110.4647a635@Pavel> <20171026113438.p3o2ihbyeofal4xb@x60s.casa> <20171026145843.189f798c@Pavel> Message-ID: <20171026123210.dgj3ctgoygxi7p2b@x60s.casa> On Thu, Oct 26, 2017 at 02:58:43PM +0300, Baa wrote: > @Francesco: > > I tried it (added extension InstanceSigs, added "^.."-style docstring), > nothing changed. So, may be docstrings in instances are impossible at > whole? May be it makes sense... May be they should be documented in its > classes instead? Mhhh indeed you are correct, I tried to replicate and while haddock doesn't complain, it doesn't output anything for the implemented functions. Maybe a workaround could be: -- | Prova instance Fun Foo where fun :: a fun = undefined This will put text on the right of the /instance declaration/. From aquagnu at gmail.com Thu Oct 26 13:02:44 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 26 Oct 2017 16:02:44 +0300 Subject: [Haskell-beginners] What's wrong with Haddock?! In-Reply-To: <20171026123210.dgj3ctgoygxi7p2b@x60s.casa> References: <20171026130356.0a802023@Pavel> <20171026102552.qu3hglm2gy74nu35@x60s.casa> <20171026141110.4647a635@Pavel> <20171026113438.p3o2ihbyeofal4xb@x60s.casa> <20171026145843.189f798c@Pavel> <20171026123210.dgj3ctgoygxi7p2b@x60s.casa> Message-ID: <20171026160244.2e84e551@Pavel> @Francesco: yes, it is. OK, it's a workaround :) Thank you! > On Thu, Oct 26, 2017 at 02:58:43PM +0300, Baa wrote: > > @Francesco: > > > > I tried it (added extension InstanceSigs, added "^.."-style > > docstring), nothing changed. So, may be docstrings in instances are > > impossible at whole? May be it makes sense... May be they should be > > documented in its classes instead? > > Mhhh indeed you are correct, I tried to replicate and while haddock > doesn't complain, it doesn't output anything for the implemented > functions. > > Maybe a workaround could be: > > -- | Prova > instance Fun Foo where > fun :: a > fun = undefined > > This will put text on the right of the /instance declaration/. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners