Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Further constraining types (Christopher Howard) 2. Re: Further constraining types (Brandon Allbery) 3. Re: Further constraining types (Christopher Howard) 4. Re: Further constraining types (Arlen Cuss) 5. Re: Further constraining types (David Virebayre) 6. repetition (Luca Ciciriello) 7. Re: repetition (Thomas Davie) 8. Re: repetition (Ozgur Akgun) 9. Re: repetition (Lyndon Maydwell) 10. Re: repetition (Lyndon Maydwell) ---------------------------------------------------------------------- Message: 1 Date: Wed, 03 Aug 2011 21:03:07 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: [Haskell-beginners] Further constraining types To: Haskell Beginners <beginners@haskell.org> Message-ID: <4e3a280b.60...@frigidcode.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Let's say I have "f", which is a function of the following type: f :: Int -> Int However, let's say f is only capable of handling positive integers. Let's say that I'm committed to making f a complete function in the sense that (1) the pattern matching of the function is always complete and (2) there are no internal aborts, like an "error" call or an "undefined" expression. Obviously I could change the type to f :: Int -> Maybe Int ...to deal with the case where a negative parameter is passed in. But it seems like what I really want is something like this: f :: Positive Int -> Int I.e., the "positiveness" is hard-coded into the parameter type. But how do I do this? I was thinking it would involve some kind of "Positive Int" type, and some kind of "constructor" function like so: positiveNum :: Int -> Positive Int However, then this constructor function must deal with the problem of receiving a negative integer, and thus I have only shifted the problem. It is still an improvement, but yet it seems like I am missing some important concept here... -- frigidcode.com theologia.indicium.us ------------------------------ Message: 2 Date: Thu, 4 Aug 2011 01:23:48 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] Further constraining types To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CAKFCL4UF6vDPXc5AiL9ZJeBDOcgPo1=3pab2+szts9kg-ba...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Thu, Aug 4, 2011 at 01:03, Christopher Howard < christopher.how...@frigidcode.com> wrote: > ...to deal with the case where a negative parameter is passed in. But it > seems like what I really want is something like this: > > f :: Positive Int -> Int > > I.e., the "positiveness" is hard-coded into the parameter type. But how > do I do this? I was thinking it would involve some kind of "Positive > Int" type, and some kind of "constructor" function like so: > > positiveNum :: Int -> Positive Int > > However, then this constructor function must deal with the problem of > receiving a negative integer, and thus I have only shifted the problem. > It is still an improvement, but yet it seems like I am missing some > important concept here... > The concept is called "dependent types", where a type can depend on a value. Haskell doesn't support them natively, although there are some hacks for limited cases. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110804/57e6e4cf/attachment-0001.htm> ------------------------------ Message: 3 Date: Wed, 03 Aug 2011 22:51:39 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: Re: [Haskell-beginners] Further constraining types To: Haskell Beginners <beginners@haskell.org> Message-ID: <4e3a417b.7030...@frigidcode.com> Content-Type: text/plain; charset=UTF-8; format=flowed On 08/03/2011 09:23 PM, Brandon Allbery wrote: > On Thu, Aug 4, 2011 at 01:03, Christopher Howard > <christopher.how...@frigidcode.com > <mailto:christopher.how...@frigidcode.com>> wrote: > > ...to deal with the case where a negative parameter is passed in. But it > seems like what I really want is something like this: > > f :: Positive Int -> Int > > I.e., the "positiveness" is hard-coded into the parameter type. But how > do I do this? I was thinking it would involve some kind of "Positive > Int" type, and some kind of "constructor" function like so: > > positiveNum :: Int -> Positive Int > > However, then this constructor function must deal with the problem of > receiving a negative integer, and thus I have only shifted the problem. > It is still an improvement, but yet it seems like I am missing some > important concept here... > > > The concept is called "dependent types", where a type can depend on a > value. Haskell doesn't support them natively, although there are some > hacks for limited cases. > > -- > brandon s allbery allber...@gmail.com <mailto:allber...@gmail.com> > wandering unix systems administrator (available) (412) 475-9364 vm/sms > This seems like a really significant issue for a functional programming language. Am I eventually going to have to switch to Agda? My friends are trying to convert me... -- frigidcode.com theologia.indicium.us ------------------------------ Message: 4 Date: Thu, 04 Aug 2011 17:36:49 +1000 From: Arlen Cuss <cel...@sairyx.org> Subject: Re: [Haskell-beginners] Further constraining types To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <4e3a4c11.40...@sairyx.org> Content-Type: text/plain; charset=ISO-8859-1 04.08.2011 15:03, Christopher Howard kirjutas: > Let's say I have "f", which is a function of the following type: > > f :: Int -> Int > > However, let's say f is only capable of handling positive integers. > Let's say that I'm committed to making f a complete function in the > sense that (1) the pattern matching of the function is always complete > and (2) there are no internal aborts, like an "error" call or an > "undefined" expression. Obviously I could change the type to > > f :: Int -> Maybe Int > > ...to deal with the case where a negative parameter is passed in. But it > seems like what I really want is something like this: > > f :: Positive Int -> Int > > I.e., the "positiveness" is hard-coded into the parameter type. But how > do I do this? I was thinking it would involve some kind of "Positive > Int" type, and some kind of "constructor" function like so: > > positiveNum :: Int -> Positive Int > > However, then this constructor function must deal with the problem of > receiving a negative integer, and thus I have only shifted the problem. > It is still an improvement, but yet it seems like I am missing some > important concept here... What about positiveNum :: Int -> Maybe (Positive Int)? The reality is you need to provide a way to get some Int to Positive Int, and since Haskell doesn't have the notion of a positive-only Int built in, you need to be prepared that a non-positive Int might get through to your constructor at runtime. After that, you're set! ------------------------------ Message: 5 Date: Thu, 4 Aug 2011 10:03:19 +0200 From: David Virebayre <dav.vire+hask...@gmail.com> Subject: Re: [Haskell-beginners] Further constraining types To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CAM_wFVsMRhdfZ18xxApAjgwSh+373WUqQv6e1B+NvXccM=a...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 2011/8/4 Christopher Howard <christopher.how...@frigidcode.com>: > On 08/03/2011 09:23 PM, Brandon Allbery wrote: > This seems like a really significant issue for a functional programming > language. Am I eventually going to have to switch to Agda? My friends are > trying to convert me... I don't know Agda and what dependent type guarantee, but I don't see how they would prevent a user typing '-123' where you expect a positive number, so one way or another you will have to deal with input at runtime. Once you've validated your user input though, nothing prevents you to have it return a Positive Int that you will guarantee can hold only positive integers, for example by using a smart constructor, and hiding the contructor in a separate module. You don't need dependant types for this. David. ------------------------------ Message: 6 Date: Thu, 4 Aug 2011 11:31:02 +0200 From: Luca Ciciriello <luca_cicirie...@hotmail.com> Subject: [Haskell-beginners] repetition To: beginners@haskell.org Message-ID: <blu0-smtp157364d1e522a84a5cbd9839a...@phx.gbl> Content-Type: text/plain; charset="us-ascii" Hi All. Is there any function in Prelude that removes the repeated elements in a list? In example I've a list like this one: xs = ["3","3","3","3","3","4","4","4","4","4","5","5","5","5","5","6","6","6","6","6","6","6"] I need a function f such that f xs = ["3","4","5","6"] thanks in advance for any answer. Luca ------------------------------ Message: 7 Date: Thu, 4 Aug 2011 10:33:32 +0100 From: Thomas Davie <tom.da...@gmail.com> Subject: Re: [Haskell-beginners] repetition To: Luca Ciciriello <luca_cicirie...@hotmail.com> Cc: beginners@haskell.org Message-ID: <f8055ba0-3d4a-4d65-b381-70c61b3d1...@gmail.com> Content-Type: text/plain; charset=us-ascii On 4 Aug 2011, at 10:31, Luca Ciciriello wrote: > Hi All. > Is there any function in Prelude that removes the repeated elements in a > list? > > In example I've a list like this one: xs = > ["3","3","3","3","3","4","4","4","4","4","5","5","5","5","5","6","6","6","6","6","6","6"] > > I need a function f such that f xs = ["3","4","5","6"] > > thanks in advance for any answer. map head . group Bob ------------------------------ Message: 8 Date: Thu, 4 Aug 2011 10:36:06 +0100 From: Ozgur Akgun <ozgurak...@gmail.com> Subject: Re: [Haskell-beginners] repetition To: Luca Ciciriello <luca_cicirie...@hotmail.com> Cc: beginners@haskell.org Message-ID: <calzazpb1pjh5onxh3gavkffrykf+zqsmq7cknus3ezkntah...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi. On 4 August 2011 10:31, Luca Ciciriello <luca_cicirie...@hotmail.com> wrote: > Is there any function in Prelude that removes the repeated elements in a > list? > http://haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html#v:nub HTH, Ozgur -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110804/20d14237/attachment-0001.htm> ------------------------------ Message: 9 Date: Thu, 4 Aug 2011 17:36:23 +0800 From: Lyndon Maydwell <maydw...@gmail.com> Subject: Re: [Haskell-beginners] repetition To: Thomas Davie <tom.da...@gmail.com> Cc: beginners@haskell.org Message-ID: <CAM5QZtxmdtGJbJ7B8cJnx0Hxv_KVUN-1KTORW1D7my=qsiv...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 nub > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 10 Date: Thu, 4 Aug 2011 17:37:34 +0800 From: Lyndon Maydwell <maydw...@gmail.com> Subject: Re: [Haskell-beginners] repetition To: Thomas Davie <tom.da...@gmail.com> Cc: beginners@haskell.org Message-ID: <cam5qztwxywf-i+c06h2w1sn2tsehiz7e8domu5djsp2jtmh...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Ah sorry, nub that requires importing Data.List. My mistake! On Thu, Aug 4, 2011 at 5:36 PM, Lyndon Maydwell <maydw...@gmail.com> wrote: > nub > >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 38, Issue 6 ****************************************