From atrudyjane at protonmail.com Tue Aug 1 02:42:17 2017 From: atrudyjane at protonmail.com (Atrudyjane) Date: Mon, 31 Jul 2017 22:42:17 -0400 Subject: [Haskell-beginners] Libraries for Playing Audio In-Reply-To: <1197554121.73338.1501480223697@communicator.strato.de> References: <1197554121.73338.1501480223697@communicator.strato.de> Message-ID: <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> Thanks Alexei, Think I've narrowed it down to either sox or conduit-audio. Looks like SDL-mixer hasn't been updated in a while and it has an 'All reported builds failed' status as of 2015. Regards, Andrea Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: [Haskell-beginners] Libraries for Playing Audio > Local Time: July 31, 2017 12:50 AM > UTC Time: July 31, 2017 5:50 AM > From: info at maximka.de > To: Atrudyjane , The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell > There is haskell wrapper for powerful sox availiable also. > http://hackage.haskell.org/package/sox > Alexei >> On 31 July 2017 at 07:09 Atrudyjane wrote: >> >> >> Hello Cafe, >> Is there a recommended Haskell library for playing/manipulating audio files? There"s a long list of sound libraries on Hackage, and was thinking looking into either conduit-audio or SDL-mixer. >> Thank You, >> Andrea >> >> Sent with [ProtonMail](https://protonmail.com) Secure Email._______________________________________________ >> 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 Tue Aug 1 08:31:40 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 1 Aug 2017 11:31:40 +0300 Subject: [Haskell-beginners] How to "cast" FromJSON instance value Message-ID: <20170801113140.250323e5@Pavel> Hello, List! I have, for example, function with signature like fn :: FromJSON a => Map Text a -> BlahBlah and I want to treat this `a` as String (or `Text`), to read it with `readMaybe`. Am I right that it's impossible? I get error about "...a is rigid type and could not be matched with Text...". But `Text` is `FromJSON` instance. Is it possible to do it (cast, convert, unwrap, etc)? The problem's source is that early I worked with `Text` values only (getting from HTML form) but now they become any type: int's, bool's, etc). === Best regards, Paul From ollie at ocharles.org.uk Tue Aug 1 09:01:22 2017 From: ollie at ocharles.org.uk (Oliver Charles) Date: Tue, 01 Aug 2017 09:01:22 +0000 Subject: [Haskell-beginners] Libraries for Playing Audio In-Reply-To: <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> References: <1197554121.73338.1501480223697@communicator.strato.de> <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> Message-ID: What are your requirements? SDL2's audio module is functional, but I don't know if it's sufficient for what you're looking for. On Tue, Aug 1, 2017 at 3:44 AM Atrudyjane wrote: > Thanks Alexei, > > Think I've narrowed it down to either sox or conduit-audio. Looks like > SDL-mixer hasn't been updated in a while and it has an 'All reported builds > failed' status as of 2015. > > Regards, > Andrea > > > Sent with ProtonMail Secure Email. > > -------- Original Message -------- > Subject: Re: [Haskell-beginners] Libraries for Playing Audio > Local Time: July 31, 2017 12:50 AM > UTC Time: July 31, 2017 5:50 AM > From: info at maximka.de > To: Atrudyjane , The Haskell-Beginners Mailing > List - Discussion of primarily beginner-level topics related to Haskell < > beginners at haskell.org> > > There is haskell wrapper for powerful sox availiable also. > http://hackage.haskell.org/package/sox > > Alexei > > > On 31 July 2017 at 07:09 Atrudyjane wrote: > > > > > > Hello Cafe, > > Is there a recommended Haskell library for playing/manipulating audio > files? There"s a long list of sound libraries on Hackage, and was thinking > looking into either conduit-audio or SDL-mixer. > > Thank You, > > Andrea > > > > Sent with [ProtonMail](https://protonmail.com) Secure > Email._______________________________________________ > > 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 jan.loewenstein at gmail.com Tue Aug 1 10:45:19 2017 From: jan.loewenstein at gmail.com (=?UTF-8?Q?Jan_von_L=C3=B6wenstein?=) Date: Tue, 01 Aug 2017 10:45:19 +0000 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: <20170801113140.250323e5@Pavel> References: <20170801113140.250323e5@Pavel> Message-ID: Hi, You don't know anything about your a's but that they have FromJSON instances. That in turn means you can get values from aeson parsing functions. Think parseJSON :: Value -> Parser a Could you be more specific about the problem you try to solve? Best Jan Baa schrieb am Di., 1. Aug. 2017, 10:32: > Hello, List! > > I have, for example, function with signature like > > fn :: FromJSON a => Map Text a -> BlahBlah > > and I want to treat this `a` as String (or `Text`), to read it with > `readMaybe`. Am I right that it's impossible? I get error about "...a > is rigid type and could not be matched with Text...". But `Text` is > `FromJSON` instance. Is it possible to do it (cast, convert, unwrap, etc)? > > The problem's source is that early I worked with `Text` values only > (getting from HTML form) but now they become any type: int's, bool's, > etc). > > === > 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 Tue Aug 1 11:01:17 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 1 Aug 2017 14:01:17 +0300 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: References: <20170801113140.250323e5@Pavel> Message-ID: <20170801140117.33db8801@Pavel> Hello, Jan! I "remove" the question :) Problem was: reading of HTML form values, which can be any type and saving them in a map. I done it w/ `Map Text Value` (instead of previous `Map Text Text`). To get values from the map, I implemented class and several instances which returns values of different types, something like: class GetValue a where getValue :: Text -> Map Text Value -> a (promoting of `a` anywhere in the existing code needs big refactoring, so map's value is `::Value` but not `::a`). Cons is a need to implement N instances of `GetValue`: one per getting type. Anywhere, Jan, thanks for quick answer, I'm sorry for this stupid question. > Hi, > > You don't know anything about your a's but that they have FromJSON > instances. That in turn means you can get values from aeson parsing > functions. Think parseJSON :: Value -> Parser a > Could you be more specific about the problem you try to solve? > > Best > Jan > > Baa schrieb am Di., 1. Aug. 2017, 10:32: > > > Hello, List! > > > > I have, for example, function with signature like > > > > fn :: FromJSON a => Map Text a -> BlahBlah > > > > and I want to treat this `a` as String (or `Text`), to read it with > > `readMaybe`. Am I right that it's impossible? I get error about > > "...a is rigid type and could not be matched with Text...". But > > `Text` is `FromJSON` instance. Is it possible to do it (cast, > > convert, unwrap, etc)? > > > > The problem's source is that early I worked with `Text` values only > > (getting from HTML form) but now they become any type: int's, > > bool's, etc). > > > > === > > Best regards, > > Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From jan.loewenstein at gmail.com Tue Aug 1 11:30:43 2017 From: jan.loewenstein at gmail.com (=?UTF-8?Q?Jan_von_L=C3=B6wenstein?=) Date: Tue, 01 Aug 2017 11:30:43 +0000 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: <20170801140117.33db8801@Pavel> References: <20170801113140.250323e5@Pavel> <20170801140117.33db8801@Pavel> Message-ID: You'd still have to handle the case that the Value is not what you expected. Otherwise you'll have a partial function (i.e. error in case of certain inputs). So maybe you'd best use aeson directly (which spares you the GetValue instances as well). getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a Best Jan P.S. There is no such thing as a stupid question. Baa schrieb am Di., 1. Aug. 2017, 13:02: > Hello, Jan! I "remove" the question :) > Problem was: reading of HTML form values, which can be any type and > saving them in a map. I done it w/ `Map Text Value` (instead of previous > `Map Text Text`). To get values from the map, I implemented class and > several instances which returns values of different types, something > like: > > class GetValue a where > getValue :: Text -> Map Text Value -> a > > (promoting of `a` anywhere in the existing code needs big refactoring, > so map's value is `::Value` but not `::a`). Cons is a need to implement > N instances of `GetValue`: one per getting type. > > Anywhere, Jan, thanks for quick answer, I'm sorry for this stupid > question. > > > > Hi, > > > > You don't know anything about your a's but that they have FromJSON > > instances. That in turn means you can get values from aeson parsing > > functions. Think parseJSON :: Value -> Parser a > > Could you be more specific about the problem you try to solve? > > > > Best > > Jan > > > > Baa schrieb am Di., 1. Aug. 2017, 10:32: > > > > > Hello, List! > > > > > > I have, for example, function with signature like > > > > > > fn :: FromJSON a => Map Text a -> BlahBlah > > > > > > and I want to treat this `a` as String (or `Text`), to read it with > > > `readMaybe`. Am I right that it's impossible? I get error about > > > "...a is rigid type and could not be matched with Text...". But > > > `Text` is `FromJSON` instance. Is it possible to do it (cast, > > > convert, unwrap, etc)? > > > > > > The problem's source is that early I worked with `Text` values only > > > (getting from HTML form) but now they become any type: int's, > > > bool's, etc). > > > > > > === > > > Best regards, > > > Paul > > > _______________________________________________ > > > 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 Tue Aug 1 11:47:00 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 1 Aug 2017 14:47:00 +0300 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: References: <20170801113140.250323e5@Pavel> <20170801140117.33db8801@Pavel> Message-ID: <20170801144700.17ddb015@Pavel> Ohh, pardon! Yes, signature was class GetValue a where getValue :: Text -> Map Text Value -> Maybe a with `Maybe` sure. But I didn't understand you: what do you mean "to use aeson directly"? Problem is to save `FromJSON a` instances in map but get from the map `Text`, `Bool` and etc values. Sure, it possible to parameterize all related functions/types with `FromJSON a => .. a` but in this case I hit 2 problems: 1. rigid type error when I have `FromJSON a =>` in some signature and try to use this `a` as `Text` value, for example 2. big refactoring (many signatures, types) So, I decided to save in the map `Value`s instead of `FromJSON a`s. De-facto, this map is heterogenous and keeps values of different types. And question for me was: to hide this fact under `FromJSON` or under `Value`. I'm not sure what is the best solution and I don't know how to solve 1. > You'd still have to handle the case that the Value is not what you > expected. Otherwise you'll have a partial function (i.e. error in > case of certain inputs). > > So maybe you'd best use aeson directly (which spares you the GetValue > instances as well). > > getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a > > Best > Jan > P.S. There is no such thing as a stupid question. > > Baa schrieb am Di., 1. Aug. 2017, 13:02: > > > Hello, Jan! I "remove" the question :) > > Problem was: reading of HTML form values, which can be any type and > > saving them in a map. I done it w/ `Map Text Value` (instead of > > previous `Map Text Text`). To get values from the map, I > > implemented class and several instances which returns values of > > different types, something like: > > > > class GetValue a where > > getValue :: Text -> Map Text Value -> a > > > > (promoting of `a` anywhere in the existing code needs big > > refactoring, so map's value is `::Value` but not `::a`). Cons is a > > need to implement N instances of `GetValue`: one per getting type. > > > > Anywhere, Jan, thanks for quick answer, I'm sorry for this stupid > > question. > > > > > > > Hi, > > > > > > You don't know anything about your a's but that they have FromJSON > > > instances. That in turn means you can get values from aeson > > > parsing functions. Think parseJSON :: Value -> Parser a > > > Could you be more specific about the problem you try to solve? > > > > > > Best > > > Jan > > > > > > Baa schrieb am Di., 1. Aug. 2017, 10:32: > > > > > > > Hello, List! > > > > > > > > I have, for example, function with signature like > > > > > > > > fn :: FromJSON a => Map Text a -> BlahBlah > > > > > > > > and I want to treat this `a` as String (or `Text`), to read it > > > > with `readMaybe`. Am I right that it's impossible? I get error > > > > about "...a is rigid type and could not be matched with > > > > Text...". But `Text` is `FromJSON` instance. Is it possible to > > > > do it (cast, convert, unwrap, etc)? > > > > > > > > The problem's source is that early I worked with `Text` values > > > > only (getting from HTML form) but now they become any type: > > > > int's, bool's, etc). > > > > > > > > === > > > > Best regards, > > > > Paul > > > > _______________________________________________ > > > > Beginners mailing list > > > > Beginners at haskell.org > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From jan.loewenstein at gmail.com Tue Aug 1 12:38:46 2017 From: jan.loewenstein at gmail.com (=?UTF-8?Q?Jan_von_L=C3=B6wenstein?=) Date: Tue, 01 Aug 2017 12:38:46 +0000 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: <20170801144700.17ddb015@Pavel> References: <20170801113140.250323e5@Pavel> <20170801140117.33db8801@Pavel> <20170801144700.17ddb015@Pavel> Message-ID: Hi, getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a getValue key map = (fromResult.fromJSON) $ lookup key map fromResult (Success a) = Just a fromResult (Error _) = Nothing I am not at a computer so I wouldn't be surprised if this doesn't compile. But you should see the picture. Best Jan Baa schrieb am Di., 1. Aug. 2017, 13:48: > Ohh, pardon! Yes, signature was > > class GetValue a where > getValue :: Text -> Map Text Value -> Maybe a > > with `Maybe` sure. But I didn't understand you: what do you mean "to > use aeson directly"? Problem is to save `FromJSON a` instances in map > but get from the map `Text`, `Bool` and etc values. Sure, it possible > to parameterize all related functions/types with `FromJSON a => .. a` > but in this case I hit 2 problems: > > 1. rigid type error when I have `FromJSON a =>` in some signature and > try to use this `a` as `Text` value, for example > 2. big refactoring (many signatures, types) > > So, I decided to save in the map `Value`s instead of `FromJSON a`s. > De-facto, this map is heterogenous and keeps values of different types. > And question for me was: to hide this fact under `FromJSON` or under > `Value`. I'm not sure what is the best solution and I don't know how to > solve 1. > > > > You'd still have to handle the case that the Value is not what you > > expected. Otherwise you'll have a partial function (i.e. error in > > case of certain inputs). > > > > So maybe you'd best use aeson directly (which spares you the GetValue > > instances as well). > > > > getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a > > > > Best > > Jan > > P.S. There is no such thing as a stupid question. > > > > Baa schrieb am Di., 1. Aug. 2017, 13:02: > > > > > Hello, Jan! I "remove" the question :) > > > Problem was: reading of HTML form values, which can be any type and > > > saving them in a map. I done it w/ `Map Text Value` (instead of > > > previous `Map Text Text`). To get values from the map, I > > > implemented class and several instances which returns values of > > > different types, something like: > > > > > > class GetValue a where > > > getValue :: Text -> Map Text Value -> a > > > > > > (promoting of `a` anywhere in the existing code needs big > > > refactoring, so map's value is `::Value` but not `::a`). Cons is a > > > need to implement N instances of `GetValue`: one per getting type. > > > > > > Anywhere, Jan, thanks for quick answer, I'm sorry for this stupid > > > question. > > > > > > > > > > Hi, > > > > > > > > You don't know anything about your a's but that they have FromJSON > > > > instances. That in turn means you can get values from aeson > > > > parsing functions. Think parseJSON :: Value -> Parser a > > > > Could you be more specific about the problem you try to solve? > > > > > > > > Best > > > > Jan > > > > > > > > Baa schrieb am Di., 1. Aug. 2017, 10:32: > > > > > > > > > Hello, List! > > > > > > > > > > I have, for example, function with signature like > > > > > > > > > > fn :: FromJSON a => Map Text a -> BlahBlah > > > > > > > > > > and I want to treat this `a` as String (or `Text`), to read it > > > > > with `readMaybe`. Am I right that it's impossible? I get error > > > > > about "...a is rigid type and could not be matched with > > > > > Text...". But `Text` is `FromJSON` instance. Is it possible to > > > > > do it (cast, convert, unwrap, etc)? > > > > > > > > > > The problem's source is that early I worked with `Text` values > > > > > only (getting from HTML form) but now they become any type: > > > > > int's, bool's, etc). > > > > > > > > > > === > > > > > Best regards, > > > > > Paul > > > > > _______________________________________________ > > > > > 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 Tue Aug 1 13:37:37 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 1 Aug 2017 16:37:37 +0300 Subject: [Haskell-beginners] How to "cast" FromJSON instance value In-Reply-To: References: <20170801113140.250323e5@Pavel> <20170801140117.33db8801@Pavel> <20170801144700.17ddb015@Pavel> Message-ID: <20170801163737.73d22d96@Pavel> Jan, this is the exactly what I'm looked for! Thank you again! :) getValue :: FromJSON a => T.Text -> M.Map T.Text a -> Maybe a getValue k m = do j <- fromJSON <$> M.lookup k m case j of Success a -> return a _ -> Nothing > Hi, > > getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a > getValue key map = (fromResult.fromJSON) $ lookup key map > > fromResult (Success a) = Just a > fromResult (Error _) = Nothing > > I am not at a computer so I wouldn't be surprised if this doesn't > compile. But you should see the picture. > > Best > Jan > > Baa schrieb am Di., 1. Aug. 2017, 13:48: > > > Ohh, pardon! Yes, signature was > > > > class GetValue a where > > getValue :: Text -> Map Text Value -> Maybe a > > > > with `Maybe` sure. But I didn't understand you: what do you mean "to > > use aeson directly"? Problem is to save `FromJSON a` instances in > > map but get from the map `Text`, `Bool` and etc values. Sure, it > > possible to parameterize all related functions/types with `FromJSON > > a => .. a` but in this case I hit 2 problems: > > > > 1. rigid type error when I have `FromJSON a =>` in some signature > > and try to use this `a` as `Text` value, for example > > 2. big refactoring (many signatures, types) > > > > So, I decided to save in the map `Value`s instead of `FromJSON a`s. > > De-facto, this map is heterogenous and keeps values of different > > types. And question for me was: to hide this fact under `FromJSON` > > or under `Value`. I'm not sure what is the best solution and I > > don't know how to solve 1. > > > > > > > You'd still have to handle the case that the Value is not what you > > > expected. Otherwise you'll have a partial function (i.e. error in > > > case of certain inputs). > > > > > > So maybe you'd best use aeson directly (which spares you the > > > GetValue instances as well). > > > > > > getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a > > > > > > Best > > > Jan > > > P.S. There is no such thing as a stupid question. > > > > > > Baa schrieb am Di., 1. Aug. 2017, 13:02: > > > > > > > Hello, Jan! I "remove" the question :) > > > > Problem was: reading of HTML form values, which can be any type > > > > and saving them in a map. I done it w/ `Map Text Value` > > > > (instead of previous `Map Text Text`). To get values from the > > > > map, I implemented class and several instances which returns > > > > values of different types, something like: > > > > > > > > class GetValue a where > > > > getValue :: Text -> Map Text Value -> a > > > > > > > > (promoting of `a` anywhere in the existing code needs big > > > > refactoring, so map's value is `::Value` but not `::a`). Cons > > > > is a need to implement N instances of `GetValue`: one per > > > > getting type. > > > > > > > > Anywhere, Jan, thanks for quick answer, I'm sorry for this > > > > stupid question. > > > > > > > > > > > > > Hi, > > > > > > > > > > You don't know anything about your a's but that they have > > > > > FromJSON instances. That in turn means you can get values > > > > > from aeson parsing functions. Think parseJSON :: Value -> > > > > > Parser a Could you be more specific about the problem you try > > > > > to solve? > > > > > > > > > > Best > > > > > Jan > > > > > > > > > > Baa schrieb am Di., 1. Aug. 2017, 10:32: > > > > > > > > > > > Hello, List! > > > > > > > > > > > > I have, for example, function with signature like > > > > > > > > > > > > fn :: FromJSON a => Map Text a -> BlahBlah > > > > > > > > > > > > and I want to treat this `a` as String (or `Text`), to read > > > > > > it with `readMaybe`. Am I right that it's impossible? I get > > > > > > error about "...a is rigid type and could not be matched > > > > > > with Text...". But `Text` is `FromJSON` instance. Is it > > > > > > possible to do it (cast, convert, unwrap, etc)? > > > > > > > > > > > > The problem's source is that early I worked with `Text` > > > > > > values only (getting from HTML form) but now they become > > > > > > any type: int's, bool's, etc). > > > > > > > > > > > > === > > > > > > Best regards, > > > > > > Paul > > > > > > _______________________________________________ > > > > > > 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 > > From 50295 at web.de Tue Aug 1 23:16:04 2017 From: 50295 at web.de (Olumide) Date: Wed, 2 Aug 2017 00:16:04 +0100 Subject: [Haskell-beginners] Grappling with State Monad get Message-ID: Ahoy Haskellers, In the section "Getting and Setting State" (http://learnyouahaskell.com/for-a-few-monads-more#state) in LYH get is defined as get = state $ \s -> (s, s) How does does get determine the type s, is considering that it has no argument as per the definition given above? Or is the definition written in some sort of point-free notation where an argument has been dropped? I find the line stackNow <- get in the the function(?) stackyStack confusing for the same reason. I guess my difficulty is that state $ \s ->(s , s) has a generic type (s) whereas the stackyStack has a concrete type. Is the type of s determined from the type of the stateful computation/do notation? Regards, - Olumide From tanuki at gmail.com Tue Aug 1 23:35:14 2017 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Tue, 1 Aug 2017 16:35:14 -0700 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: References: Message-ID: 's' here is not a type variable, it's an actual variable. \s -> (s, s) defines a lambda function which takes any value, and returns a tuple with that value in both positions. So yes, get is point-free, but the missing argument is right there in-line. And yes, its type is simply implied from context. On Aug 1, 2017 4:17 PM, "Olumide" <50295 at web.de> wrote: Ahoy Haskellers, In the section "Getting and Setting State" (http://learnyouahaskell.com/f or-a-few-monads-more#state) in LYH get is defined as get = state $ \s -> (s, s) How does does get determine the type s, is considering that it has no argument as per the definition given above? Or is the definition written in some sort of point-free notation where an argument has been dropped? I find the line stackNow <- get in the the function(?) stackyStack confusing for the same reason. I guess my difficulty is that state $ \s ->(s , s) has a generic type (s) whereas the stackyStack has a concrete type. Is the type of s determined from the type of the stateful computation/do notation? Regards, - Olumide _______________________________________________ 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 Wed Aug 2 00:13:12 2017 From: 50295 at web.de (Olumide) Date: Wed, 2 Aug 2017 01:13:12 +0100 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: References: Message-ID: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> Of course 's' is not a type variable as its lowercase. Therefore, get is a monad 'constructed' by the state function, correct? So, in the do notation the lambda is extracted and used as per the definition of bind. The context of which we speak therefore must derive from the next expression(?) in the do notation, which is somewhat confusing to determine in the example stackyStack :: State Stack () stackyStack = do stackNow <- get if stackNow == [1,2,3] then put [8,3,1] else put [9,2,1] Regards, - Olumide On 02/08/17 00:35, Theodore Lief Gannon wrote: > 's' here is not a type variable, it's an actual variable. \s -> (s, s) > defines a lambda function which takes any value, and returns a tuple > with that value in both positions. > > So yes, get is point-free, but the missing argument is right there > in-line. And yes, its type is simply implied from context. > > > On Aug 1, 2017 4:17 PM, "Olumide" <50295 at web.de > > wrote: > > Ahoy Haskellers, > > In the section "Getting and Setting State" > (http://learnyouahaskell.com/for-a-few-monads-more#state > ) in LYH > get is defined as > > get = state $ \s -> (s, s) > > How does does get determine the type s, is considering that it has > no argument as per the definition given above? Or is the definition > written in some sort of point-free notation where an argument has > been dropped? > > I find the line stackNow <- get in the the function(?) stackyStack > confusing for the same reason. I guess my difficulty is that state $ > \s ->(s , s) has a generic type (s) whereas the stackyStack has a > concrete type. Is the type of s determined from the type of the > stateful computation/do notation? > > Regards, > > - Olumide > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From atrudyjane at protonmail.com Wed Aug 2 01:23:59 2017 From: atrudyjane at protonmail.com (Atrudyjane) Date: Tue, 01 Aug 2017 21:23:59 -0400 Subject: [Haskell-beginners] Libraries for Playing Audio In-Reply-To: References: <1197554121.73338.1501480223697@communicator.strato.de> <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> Message-ID: Hi Oliver, The requirements are to play, pause play, and stop playing an mp3 file. Also would like to use time elapsed and duration data. Andrea Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: [Haskell-beginners] Libraries for Playing Audio > Local Time: August 1, 2017 4:01 AM > UTC Time: August 1, 2017 9:01 AM > From: ollie at ocharles.org.uk > To: Atrudyjane , The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell , info at maximka.de > What are your requirements? SDL2's audio module is functional, but I don't know if it's sufficient for what you're looking for. > > On Tue, Aug 1, 2017 at 3:44 AM Atrudyjane wrote: > >> Thanks Alexei, >> Think I've narrowed it down to either sox or conduit-audio. Looks like SDL-mixer hasn't been updated in a while and it has an 'All reported builds failed' status as of 2015. >> Regards, >> Andrea >> >> Sent with [ProtonMail](https://protonmail.com) Secure Email. >> >>> -------- Original Message -------- >>> Subject: Re: [Haskell-beginners] Libraries for Playing Audio >>> Local Time: July 31, 2017 12:50 AM >>> UTC Time: July 31, 2017 5:50 AM >>> From: info at maximka.de >>> To: Atrudyjane , The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell >>> There is haskell wrapper for powerful sox availiable also. >>> http://hackage.haskell.org/package/sox >>> Alexei >>>> On 31 July 2017 at 07:09 Atrudyjane wrote: >>>> >>>> >>>> Hello Cafe, >>>> Is there a recommended Haskell library for playing/manipulating audio files? There"s a long list of sound libraries on Hackage, and was thinking looking into either conduit-audio or SDL-mixer. >>>> Thank You, >>>> Andrea >>>> >>>> Sent with [ProtonMail](https://protonmail.com) Secure Email._______________________________________________ >>>> 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 tanuki at gmail.com Wed Aug 2 02:26:57 2017 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Tue, 1 Aug 2017 19:26:57 -0700 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> References: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> Message-ID: Actually, get is constrained immediately to be State Stack Stack. If later statements tried to use it as something else, it would be a type error. The types in a do block can only vary in their final parameter. The type of stackyStack is State Stack (), so in that do block all the statements must be forall a. State Stack a. Now, check the type of get in GHCi: get :: State a a We know that the first type parameter here is Stack, and the second position is the same type, thus State Stack Stack. On Tue, Aug 1, 2017 at 5:13 PM, Olumide <50295 at web.de> wrote: > Of course 's' is not a type variable as its lowercase. > > Therefore, get is a monad 'constructed' by the state function, correct? > > So, in the do notation the lambda is extracted and used as per the > definition of bind. The context of which we speak therefore must derive > from the next expression(?) in the do notation, which is somewhat confusing > to determine in the example > > stackyStack :: State Stack () > stackyStack = do > stackNow <- get > if stackNow == [1,2,3] > then put [8,3,1] > else put [9,2,1] > > Regards, > > - Olumide > > On 02/08/17 00:35, Theodore Lief Gannon wrote: > >> 's' here is not a type variable, it's an actual variable. \s -> (s, s) >> defines a lambda function which takes any value, and returns a tuple with >> that value in both positions. >> >> So yes, get is point-free, but the missing argument is right there >> in-line. And yes, its type is simply implied from context. >> >> >> On Aug 1, 2017 4:17 PM, "Olumide" <50295 at web.de > >> wrote: >> >> Ahoy Haskellers, >> >> In the section "Getting and Setting State" >> (http://learnyouahaskell.com/for-a-few-monads-more#state >> ) in LYH >> get is defined as >> >> get = state $ \s -> (s, s) >> >> How does does get determine the type s, is considering that it has >> no argument as per the definition given above? Or is the definition >> written in some sort of point-free notation where an argument has >> been dropped? >> >> I find the line stackNow <- get in the the function(?) stackyStack >> confusing for the same reason. I guess my difficulty is that state $ >> \s ->(s , s) has a generic type (s) whereas the stackyStack has a >> concrete type. Is the type of s determined from the type of the >> stateful computation/do notation? >> >> Regards, >> >> - Olumide >> _______________________________________________ >> 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 ollie at ocharles.org.uk Wed Aug 2 09:03:32 2017 From: ollie at ocharles.org.uk (Oliver Charles) Date: Wed, 02 Aug 2017 09:03:32 +0000 Subject: [Haskell-beginners] Libraries for Playing Audio In-Reply-To: References: <1197554121.73338.1501480223697@communicator.strato.de> <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> Message-ID: That would be doable with SDL2, but you'll need to handle mp3 decoding yourself - perhaps using lame or something. On Wed, Aug 2, 2017 at 2:24 AM Atrudyjane wrote: > Hi Oliver, > > The requirements are to play, pause play, and stop playing an mp3 file. > Also would like to use time elapsed and duration data. > > Andrea > > > Sent with ProtonMail Secure Email. > > -------- Original Message -------- > Subject: Re: [Haskell-beginners] Libraries for Playing Audio > > Local Time: August 1, 2017 4:01 AM > UTC Time: August 1, 2017 9:01 AM > From: ollie at ocharles.org.uk > To: Atrudyjane , The Haskell-Beginners Mailing > List - Discussion of primarily beginner-level topics related to Haskell < > beginners at haskell.org>, info at maximka.de > > What are your requirements? SDL2's audio module is functional, but I don't > know if it's sufficient for what you're looking for. > > On Tue, Aug 1, 2017 at 3:44 AM Atrudyjane > wrote: > >> Thanks Alexei, >> >> Think I've narrowed it down to either sox or conduit-audio. Looks like >> SDL-mixer hasn't been updated in a while and it has an 'All reported builds >> failed' status as of 2015. >> >> Regards, >> Andrea >> >> >> Sent with ProtonMail Secure Email. >> >> -------- Original Message -------- >> Subject: Re: [Haskell-beginners] Libraries for Playing Audio >> Local Time: July 31, 2017 12:50 AM >> UTC Time: July 31, 2017 5:50 AM >> From: info at maximka.de >> To: Atrudyjane , The Haskell-Beginners >> Mailing List - Discussion of primarily beginner-level topics related to >> Haskell >> >> There is haskell wrapper for powerful sox availiable also. >> http://hackage.haskell.org/package/sox >> >> Alexei >> >> > On 31 July 2017 at 07:09 Atrudyjane wrote: >> > >> > >> > Hello Cafe, >> > Is there a recommended Haskell library for playing/manipulating audio >> files? There"s a long list of sound libraries on Hackage, and was thinking >> looking into either conduit-audio or SDL-mixer. >> > Thank You, >> > Andrea >> > >> > Sent with [ProtonMail](https://protonmail.com) Secure >> Email._______________________________________________ >> > 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 atrudyjane at protonmail.com Thu Aug 3 02:31:17 2017 From: atrudyjane at protonmail.com (Atrudyjane) Date: Wed, 02 Aug 2017 22:31:17 -0400 Subject: [Haskell-beginners] Libraries for Playing Audio In-Reply-To: References: <1197554121.73338.1501480223697@communicator.strato.de> <9-OGhbO026pu9EbidNe8YkghqLbGz8CgLpKBj4PhoQS-MmwbETPtK1xtCBwjNsvD7tpFWIVTgMBQfyEjd2M8NcHHoIhVFwx8QcTgfx_reTo=@protonmail.com> Message-ID: For mp3 decoding in Haskell, a quick search brought up the mp3decoder library (which is not recommended by the author, experimental only), the LAME library (encoding only). conduit-audio-lame (encoding only). Looks like mp3 decoding with lame will be a project by itself! Andrea Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: [Haskell-beginners] Libraries for Playing Audio > Local Time: August 2, 2017 4:03 AM > UTC Time: August 2, 2017 9:03 AM > From: ollie at ocharles.org.uk > To: Atrudyjane > The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell , info at maximka.de > That would be doable with SDL2, but you'll need to handle mp3 decoding yourself - perhaps using lame or something. > > On Wed, Aug 2, 2017 at 2:24 AM Atrudyjane wrote: > >> Hi Oliver, >> The requirements are to play, pause play, and stop playing an mp3 file. Also would like to use time elapsed and duration data. >> Andrea >> >> Sent with [ProtonMail](https://protonmail.com) Secure Email. >> >>> -------- Original Message -------- >>> Subject: Re: [Haskell-beginners] Libraries for Playing Audio >> >>> Local Time: August 1, 2017 4:01 AM >>> UTC Time: August 1, 2017 9:01 AM >>> From: ollie at ocharles.org.uk >>> To: Atrudyjane , The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell , info at maximka.de >>> What are your requirements? SDL2's audio module is functional, but I don't know if it's sufficient for what you're looking for. >>> >>> On Tue, Aug 1, 2017 at 3:44 AM Atrudyjane wrote: >>> >>>> Thanks Alexei, >>>> Think I've narrowed it down to either sox or conduit-audio. Looks like SDL-mixer hasn't been updated in a while and it has an 'All reported builds failed' status as of 2015. >>>> Regards, >>>> Andrea >>>> >>>> Sent with [ProtonMail](https://protonmail.com) Secure Email. >>>> >>>>> -------- Original Message -------- >>>>> Subject: Re: [Haskell-beginners] Libraries for Playing Audio >>>>> Local Time: July 31, 2017 12:50 AM >>>>> UTC Time: July 31, 2017 5:50 AM >>>>> From: info at maximka.de >>>>> To: Atrudyjane , The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell >>>>> There is haskell wrapper for powerful sox availiable also. >>>>> http://hackage.haskell.org/package/sox >>>>> Alexei >>>>>> On 31 July 2017 at 07:09 Atrudyjane wrote: >>>>>> >>>>>> >>>>>> Hello Cafe, >>>>>> Is there a recommended Haskell library for playing/manipulating audio files? There"s a long list of sound libraries on Hackage, and was thinking looking into either conduit-audio or SDL-mixer. >>>>>> Thank You, >>>>>> Andrea >>>>>> >>>>>> Sent with [ProtonMail](https://protonmail.com) Secure Email._______________________________________________ >>>>>> 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 yassine912 at gmail.com Thu Aug 3 19:19:49 2017 From: yassine912 at gmail.com (Yassine) Date: Thu, 3 Aug 2017 21:19:49 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works Message-ID: Hi, I have a question about functor applicate. I know that: pure (+1) <*> Just 2 produce: Just 3 because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 produce Just (2+1) but in more complex case like: newtype Parser a = P (String -> [(a,String)]) parse :: Parser a -> String -> [(a,String)] parse (P p) inp = p inp item :: Parser Char item = P (\inp -> case inp of [] -> [] (x:xs) -> [(x,xs)]) instance Functor Parser where fmap g p = P (\inp -> case p inp of [] -> [] [(v, out)] -> [(g v, out)]) instance Applicative Parser where pure v = P (\inp -> [(v, inp)]) pg <*> px = P (\inp -> case parse pg inp of [] -> [] [(g, out)] -> parse (fmap g px) out) When I do: parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" The answer is: [(('a','b'),"c")] But I don't understand what exactly happens. First: pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) Then: P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? Can someone explain what's happens step by step please. Thank you. From casey_newsome98 at ymail.com Thu Aug 3 22:59:27 2017 From: casey_newsome98 at ymail.com (Casey Newsome) Date: Thu, 3 Aug 2017 22:59:27 +0000 (UTC) Subject: [Haskell-beginners] Password Program Questions References: <1187571632.5422106.1501801167672.ref@mail.yahoo.com> Message-ID: <1187571632.5422106.1501801167672@mail.yahoo.com> I am very new to Haskell and I am attempting to make a simple password program as my first program. I have ran into a problem and I am not very sure on how to fix it. I do not know how to make a second section for the passwords. My guessing attempts have failed so I am asking for help. Here is my code main = do       putStrLn "Hello, Who are you?"      name <- getLine --User Input      putStrLn ("Hey " ++ name ++ ", What's the password?")      pass <- getLine      if pass == "12345"          then putStrLn ("Welcome")          pw          else do              putStrLn "That is wrong!"              mainpw = do    putStrLn "What Password do you need?" Thanks in advance, Casey :D -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Aug 3 23:39:04 2017 From: toad3k at gmail.com (David McBride) Date: Thu, 3 Aug 2017 19:39:04 -0400 Subject: [Haskell-beginners] Password Program Questions In-Reply-To: <1187571632.5422106.1501801167672@mail.yahoo.com> References: <1187571632.5422106.1501801167672.ref@mail.yahoo.com> <1187571632.5422106.1501801167672@mail.yahoo.com> Message-ID: Remember that haskell is whitespace delimited. You probably intended putStrLn "Welcome" to line up with pw, in its own do. if pass == "12345" then do putStrLn "welcome" pw else do putStrLn "wrong" main On Thu, Aug 3, 2017 at 6:59 PM, Casey Newsome wrote: > I am very new to Haskell and I am attempting to make a simple password > program as my first program. I have ran into a problem and I am not very > sure on how to fix it. I do not know how to make a second section for the > passwords. My guessing attempts have failed so I am asking for help. > > > > > > > Here is my code > > main = do > putStrLn "Hello, Who are you?" > name <- getLine --User Input > putStrLn ("Hey " ++ name ++ ", What's the password?") > pass <- getLine > if pass == "12345" > then putStrLn ("Welcome") > pw > else do > putStrLn "That is wrong!" > main > pw = do > putStrLn "What Password do you need?" > > > > > > > Thanks in advance, Casey :D > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From toad3k at gmail.com Fri Aug 4 18:04:55 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 4 Aug 2017 14:04:55 -0400 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: This is a bit complicated for this list. You might have a bit more luck posting this to stackoverflow.com. On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: > Hi, > > I have a question about functor applicate. > > I know that: > pure (+1) <*> Just 2 > > > produce: Just 3 > because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > produce Just (2+1) > > > but in more complex case like: > newtype Parser a = P (String -> [(a,String)]) > > parse :: Parser a -> String -> [(a,String)] > parse (P p) inp = p inp > > > item :: Parser Char > item = P (\inp -> case inp of > [] -> [] > (x:xs) -> [(x,xs)]) > > instance Functor Parser where > fmap g p = P (\inp -> case p inp of > [] -> [] > [(v, out)] -> [(g v, out)]) > > instance Applicative Parser where > pure v = P (\inp -> [(v, inp)]) > pg <*> px = P (\inp -> case parse pg inp of > [] -> [] > [(g, out)] -> parse (fmap g px) out) > > > When I do: > parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > > The answer is: > [(('a','b'),"c")] > > But I don't understand what exactly happens. > First: > pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > > Then: > P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > > Can someone explain what's happens step by step please. > > Thank you. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From yassine912 at gmail.com Fri Aug 4 19:04:10 2017 From: yassine912 at gmail.com (Yassine) Date: Fri, 4 Aug 2017 21:04:10 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: Ok, thanks for your answer 2017-08-04 20:04 GMT+02:00 David McBride : > This is a bit complicated for this list. You might have a bit more > luck posting this to stackoverflow.com. > > On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: >> Hi, >> >> I have a question about functor applicate. >> >> I know that: >> pure (+1) <*> Just 2 >> >> >> produce: Just 3 >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 >> produce Just (2+1) >> >> >> but in more complex case like: >> newtype Parser a = P (String -> [(a,String)]) >> >> parse :: Parser a -> String -> [(a,String)] >> parse (P p) inp = p inp >> >> >> item :: Parser Char >> item = P (\inp -> case inp of >> [] -> [] >> (x:xs) -> [(x,xs)]) >> >> instance Functor Parser where >> fmap g p = P (\inp -> case p inp of >> [] -> [] >> [(v, out)] -> [(g v, out)]) >> >> instance Applicative Parser where >> pure v = P (\inp -> [(v, inp)]) >> pg <*> px = P (\inp -> case parse pg inp of >> [] -> [] >> [(g, out)] -> parse (fmap g px) out) >> >> >> When I do: >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" >> >> The answer is: >> [(('a','b'),"c")] >> >> But I don't understand what exactly happens. >> First: >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) >> >> Then: >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? >> >> Can someone explain what's happens step by step please. >> >> Thank you. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From jeffbrown.the at gmail.com Fri Aug 4 20:02:31 2017 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Fri, 4 Aug 2017 16:02:31 -0400 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: If you post there, you could put the link on this thread; I'd be interested. On Fri, Aug 4, 2017 at 3:04 PM, Yassine wrote: > Ok, thanks for your answer > > 2017-08-04 20:04 GMT+02:00 David McBride : > > This is a bit complicated for this list. You might have a bit more > > luck posting this to stackoverflow.com. > > > > On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: > >> Hi, > >> > >> I have a question about functor applicate. > >> > >> I know that: > >> pure (+1) <*> Just 2 > >> > >> > >> produce: Just 3 > >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > >> produce Just (2+1) > >> > >> > >> but in more complex case like: > >> newtype Parser a = P (String -> [(a,String)]) > >> > >> parse :: Parser a -> String -> [(a,String)] > >> parse (P p) inp = p inp > >> > >> > >> item :: Parser Char > >> item = P (\inp -> case inp of > >> [] -> [] > >> (x:xs) -> [(x,xs)]) > >> > >> instance Functor Parser where > >> fmap g p = P (\inp -> case p inp of > >> [] -> [] > >> [(v, out)] -> [(g v, out)]) > >> > >> instance Applicative Parser where > >> pure v = P (\inp -> [(v, inp)]) > >> pg <*> px = P (\inp -> case parse pg inp of > >> [] -> [] > >> [(g, out)] -> parse (fmap g px) out) > >> > >> > >> When I do: > >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > >> > >> The answer is: > >> [(('a','b'),"c")] > >> > >> But I don't understand what exactly happens. > >> First: > >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > >> > >> Then: > >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > >> > >> Can someone explain what's happens step by step please. > >> > >> Thank you. > >> _______________________________________________ > >> 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 > -- Jeff Brown | Jeffrey Benjamin Brown Website | Facebook | LinkedIn (spammy, so I often miss messages here) | Github -------------- next part -------------- An HTML attachment was scrubbed... URL: From brutallesale at gmail.com Fri Aug 4 20:06:45 2017 From: brutallesale at gmail.com (sasa bogicevic) Date: Fri, 4 Aug 2017 22:06:45 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: Hey does this even compile for you ? I get this in the Functor instance for Parser • Couldn't match expected type ‘String -> [(a, String)]’ with actual type ‘Parser a’ • The function ‘p’ is applied to one argument, but its type ‘Parser a’ has none In the expression: p inp In the expression: case p inp of { [] -> [] [(v, out)] -> [(g v, out)] } • Relevant bindings include p :: Parser a (bound at src/Mailinglistproblem.hs:19:10) g :: a -> b (bound at src/Mailinglistproblem.hs:19:8) fmap :: (a -> b) -> Parser a -> Parser b { name: Bogicevic Sasa phone: +381606006200 } > On Aug 4, 2017, at 22:02, Jeffrey Brown wrote: > > If you post there, you could put the link on this thread; I'd be interested. > > On Fri, Aug 4, 2017 at 3:04 PM, Yassine wrote: > Ok, thanks for your answer > > 2017-08-04 20:04 GMT+02:00 David McBride : > > This is a bit complicated for this list. You might have a bit more > > luck posting this to stackoverflow.com. > > > > On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: > >> Hi, > >> > >> I have a question about functor applicate. > >> > >> I know that: > >> pure (+1) <*> Just 2 > >> > >> > >> produce: Just 3 > >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > >> produce Just (2+1) > >> > >> > >> but in more complex case like: > >> newtype Parser a = P (String -> [(a,String)]) > >> > >> parse :: Parser a -> String -> [(a,String)] > >> parse (P p) inp = p inp > >> > >> > >> item :: Parser Char > >> item = P (\inp -> case inp of > >> [] -> [] > >> (x:xs) -> [(x,xs)]) > >> > >> instance Functor Parser where > >> fmap g p = P (\inp -> case p inp of > >> [] -> [] > >> [(v, out)] -> [(g v, out)]) > >> > >> instance Applicative Parser where > >> pure v = P (\inp -> [(v, inp)]) > >> pg <*> px = P (\inp -> case parse pg inp of > >> [] -> [] > >> [(g, out)] -> parse (fmap g px) out) > >> > >> > >> When I do: > >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > >> > >> The answer is: > >> [(('a','b'),"c")] > >> > >> But I don't understand what exactly happens. > >> First: > >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > >> > >> Then: > >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > >> > >> Can someone explain what's happens step by step please. > >> > >> Thank you. > >> _______________________________________________ > >> 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 > > > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook | LinkedIn(spammy, so I often miss messages here) | Github > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From brutallesale at gmail.com Fri Aug 4 20:10:39 2017 From: brutallesale at gmail.com (sasa bogicevic) Date: Fri, 4 Aug 2017 22:10:39 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: <22D2AE2D-F97A-4121-A683-A295E2E4C88C@gmail.com> Ok there was a constructor missing, maybe you should create a gist so we can help out instance Functor Parser where fmap g (P p) = P (\inp -> case p inp of [] -> [] [(v, out)] -> [(g v, out)]) { name: Bogicevic Sasa phone: +381606006200 } > On Aug 4, 2017, at 22:02, Jeffrey Brown wrote: > > If you post there, you could put the link on this thread; I'd be interested. > > On Fri, Aug 4, 2017 at 3:04 PM, Yassine wrote: > Ok, thanks for your answer > > 2017-08-04 20:04 GMT+02:00 David McBride : > > This is a bit complicated for this list. You might have a bit more > > luck posting this to stackoverflow.com. > > > > On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: > >> Hi, > >> > >> I have a question about functor applicate. > >> > >> I know that: > >> pure (+1) <*> Just 2 > >> > >> > >> produce: Just 3 > >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > >> produce Just (2+1) > >> > >> > >> but in more complex case like: > >> newtype Parser a = P (String -> [(a,String)]) > >> > >> parse :: Parser a -> String -> [(a,String)] > >> parse (P p) inp = p inp > >> > >> > >> item :: Parser Char > >> item = P (\inp -> case inp of > >> [] -> [] > >> (x:xs) -> [(x,xs)]) > >> > >> instance Functor Parser where > >> fmap g p = P (\inp -> case p inp of > >> [] -> [] > >> [(v, out)] -> [(g v, out)]) > >> > >> instance Applicative Parser where > >> pure v = P (\inp -> [(v, inp)]) > >> pg <*> px = P (\inp -> case parse pg inp of > >> [] -> [] > >> [(g, out)] -> parse (fmap g px) out) > >> > >> > >> When I do: > >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > >> > >> The answer is: > >> [(('a','b'),"c")] > >> > >> But I don't understand what exactly happens. > >> First: > >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > >> > >> Then: > >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > >> > >> Can someone explain what's happens step by step please. > >> > >> Thank you. > >> _______________________________________________ > >> 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 > > > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook | LinkedIn(spammy, so I often miss messages here) | Github > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From yassine912 at gmail.com Fri Aug 4 20:29:16 2017 From: yassine912 at gmail.com (Yassine) Date: Fri, 4 Aug 2017 22:29:16 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: <22D2AE2D-F97A-4121-A683-A295E2E4C88C@gmail.com> References: <22D2AE2D-F97A-4121-A683-A295E2E4C88C@gmail.com> Message-ID: Here is the link to stackoverflow: https://stackoverflow.com/questions/45514315/applicative-functor-and-partial-application-how-it-works Sorry there is a mistake in the definition of fmap. It is: case parse p inp and not: case p inp 2017-08-04 22:10 GMT+02:00 sasa bogicevic : > Ok there was a constructor missing, maybe you should create a gist so we can help out > > instance Functor Parser where > fmap g (P p) = P (\inp -> case p inp of > [] -> [] > [(v, out)] -> [(g v, out)]) > > { > name: Bogicevic Sasa > phone: +381606006200 > } > > > >> On Aug 4, 2017, at 22:02, Jeffrey Brown wrote: >> >> If you post there, you could put the link on this thread; I'd be interested. >> >> On Fri, Aug 4, 2017 at 3:04 PM, Yassine wrote: >> Ok, thanks for your answer >> >> 2017-08-04 20:04 GMT+02:00 David McBride : >> > This is a bit complicated for this list. You might have a bit more >> > luck posting this to stackoverflow.com. >> > >> > On Thu, Aug 3, 2017 at 3:19 PM, Yassine wrote: >> >> Hi, >> >> >> >> I have a question about functor applicate. >> >> >> >> I know that: >> >> pure (+1) <*> Just 2 >> >> >> >> >> >> produce: Just 3 >> >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 >> >> produce Just (2+1) >> >> >> >> >> >> but in more complex case like: >> >> newtype Parser a = P (String -> [(a,String)]) >> >> >> >> parse :: Parser a -> String -> [(a,String)] >> >> parse (P p) inp = p inp >> >> >> >> >> >> item :: Parser Char >> >> item = P (\inp -> case inp of >> >> [] -> [] >> >> (x:xs) -> [(x,xs)]) >> >> >> >> instance Functor Parser where >> >> fmap g p = P (\inp -> case p inp of >> >> [] -> [] >> >> [(v, out)] -> [(g v, out)]) >> >> >> >> instance Applicative Parser where >> >> pure v = P (\inp -> [(v, inp)]) >> >> pg <*> px = P (\inp -> case parse pg inp of >> >> [] -> [] >> >> [(g, out)] -> parse (fmap g px) out) >> >> >> >> >> >> When I do: >> >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" >> >> >> >> The answer is: >> >> [(('a','b'),"c")] >> >> >> >> But I don't understand what exactly happens. >> >> First: >> >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) >> >> >> >> Then: >> >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? >> >> >> >> Can someone explain what's happens step by step please. >> >> >> >> Thank you. >> >> _______________________________________________ >> >> 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 >> >> >> >> -- >> Jeff Brown | Jeffrey Benjamin Brown >> Website | Facebook | LinkedIn(spammy, so I often miss messages here) | Github >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From ivanllopard at gmail.com Fri Aug 4 21:30:44 2017 From: ivanllopard at gmail.com (Ivan Llopard) Date: Fri, 4 Aug 2017 23:30:44 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: Hi Yassine, I prefer to explain you with an abstract view of these definitions. Unrolling this stuff in your mind (or paper) can be complex and, IMO, it might be useless as it does not give you any specific hints to build even more complex ones. You can view Parser a as an object with a certain structure (or form, or definition if you prefer). However, you do not want to know how complex its structure or definition is. You are certain about one thing, it holds some value of type a. Let's say that such value is "hidden" by Parser. The same idea applies to Maybe a. Then, you want to work with that value no matter the structure of Parser. As you already know, fmap allows you to do that. You can go from Parser a to Parser b with a function from a to b. The applicative allows you to go further. If you have a hidden function (e.g. Parser (a->b)) and a hidden parameter (Parser a). Then you want to apply that hidden function to the hidden parameter in order to obtain a Parser b. That is what the expression parserF <*> ParserA would do if parserF hides a function and parserA its parameter. Now, you need to know more about the meaning of Parser a. It is an object that reads the input and produce a result (or token) accordingly. The returned value of the parser is a list of (result, remaining_input). The interesting part is the result value, which is of type a. You want to play around with it. Again, fmap is an easy way. Going from Parser a to Parser b via fmap does not change the parsing action of Parser a, you will have a Parser b but the behavior remains the same. You just played with the result of the first parser. The functor instance tells that more precisely (fixed): instance Functor Parser where fmap g (P p) = P (\inp -> case p inp of [] -> [] [(v, out)] -> [(g v, out)]) Now look at the definition of the applicative instance Applicative Parser where pure v = P (\inp -> [(v, inp)]) pg <*> px = P (\inp -> case parse pg inp of [] -> [] [(g, out)] -> parse (fmap g px) out) First of all, the function "parser" applies the parser, i.e., it parses the input and returns the list [(g, out)]. Here, we have two applications of "parser". The first one applies parser pg, "case parse pg inp". Obviously, pg hides a function "g". Now you preserve the same behavior of px but you fmap on it function "g". That is, the parser "fmap g px" will do the same as px but its result is changed by g. And finally, you apply such parser. Let us take the first two terms of your example first_item = pure (\x y -> (x,y)) <*> item then g = \x y -> (x,y) which is a higher order function. In the expression, g is applied partially over the result of item. You know that item returns the first char of the input, 'a'. first_item is then a parser that hides a function of the form h = \y -> ('a', y). Because it hides a function, you can use the applicative again first_term <*> item and h will be applied to the result of item again. Because we already applied item once, the remaining input is "bc". Then, item will give you 'b' as a result. Now h 'b' = ('a, 'b'), which is the result of your final parser plus the remaining input "c". Applying the final parser, you obtain [('a', 'b'), "c")] I hope this will help you ! Best, Ivan 2017-08-03 21:19 GMT+02:00 Yassine : > Hi, > > I have a question about functor applicate. > > I know that: > pure (+1) <*> Just 2 > > > produce: Just 3 > because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > produce Just (2+1) > > > but in more complex case like: > newtype Parser a = P (String -> [(a,String)]) > > parse :: Parser a -> String -> [(a,String)] > parse (P p) inp = p inp > > > item :: Parser Char > item = P (\inp -> case inp of > [] -> [] > (x:xs) -> [(x,xs)]) > > instance Functor Parser where > fmap g p = P (\inp -> case p inp of > [] -> [] > [(v, out)] -> [(g v, out)]) > > instance Applicative Parser where > pure v = P (\inp -> [(v, inp)]) > pg <*> px = P (\inp -> case parse pg inp of > [] -> [] > [(g, out)] -> parse (fmap g px) out) > > > When I do: > parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > > The answer is: > [(('a','b'),"c")] > > But I don't understand what exactly happens. > First: > pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > > Then: > P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > > Can someone explain what's happens step by step please. > > Thank you. > _______________________________________________ > 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 yassine912 at gmail.com Fri Aug 4 22:29:14 2017 From: yassine912 at gmail.com (Yassine) Date: Sat, 5 Aug 2017 00:29:14 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: Thanks for you nice answer but I still have some difficulties. When you do: g = (\x y -> (x,y)) first_item = pure g <*> item Because <*> is left associative, we do first the application of g on item before apply item, is it correct ? Furthermore, item return a list containing a tuple with the first character and the remaining of the string. So how can I get a list with a tuple containing another tuple with the parsed characters (inner tuple) and the remaining of the string (in the outer tuple). 2017-08-04 23:30 GMT+02:00 Ivan Llopard : > Hi Yassine, > > I prefer to explain you with an abstract view of these definitions. > Unrolling this stuff in your mind (or paper) can be complex and, IMO, it > might be useless as it does not give you any specific hints to build even > more complex ones. > > You can view Parser a as an object with a certain structure (or form, or > definition if you prefer). However, you do not want to know how complex its > structure or definition is. You are certain about one thing, it holds some > value of type a. > Let's say that such value is "hidden" by Parser. The same idea applies to > Maybe a. > > Then, you want to work with that value no matter the structure of Parser. As > you already know, fmap allows you to do that. You can go from Parser a to > Parser b with a function from a to b. > The applicative allows you to go further. If you have a hidden function > (e.g. Parser (a->b)) and a hidden parameter (Parser a). Then you want to > apply that hidden function to the hidden parameter in order to obtain a > Parser b. > That is what the expression parserF <*> ParserA would do if parserF hides a > function and parserA its parameter. > > Now, you need to know more about the meaning of Parser a. It is an object > that reads the input and produce a result (or token) accordingly. > The returned value of the parser is a list of (result, remaining_input). > The interesting part is the result value, which is of type a. You want to > play around with it. Again, fmap is an easy way. Going from Parser a to > Parser b via fmap does not change the parsing action of Parser a, you will > have a Parser b but the behavior remains the same. You just played with the > result of the first parser. > > The functor instance tells that more precisely (fixed): > > instance Functor Parser where > fmap g (P p) = P (\inp -> case p inp of > [] -> [] > [(v, out)] -> [(g v, out)]) > > Now look at the definition of the applicative > > instance Applicative Parser where > pure v = P (\inp -> [(v, inp)]) > pg <*> px = P (\inp -> case parse pg inp of > [] -> [] > [(g, out)] -> parse (fmap g px) out) > > First of all, the function "parser" applies the parser, i.e., it parses the > input and returns the list [(g, out)]. Here, we have two applications of > "parser". > The first one applies parser pg, "case parse pg inp". Obviously, pg hides a > function "g". > Now you preserve the same behavior of px but you fmap on it function "g". > That is, the parser "fmap g px" will do the same as px but its result is > changed by g. > And finally, you apply such parser. > > Let us take the first two terms of your example > > first_item = pure (\x y -> (x,y)) <*> item > > then g = \x y -> (x,y) > which is a higher order function. In the expression, g is applied partially > over the result of item. You know that item returns the first char of the > input, 'a'. > first_item is then a parser that hides a function of the form h = \y -> > ('a', y). > > Because it hides a function, you can use the applicative again > > first_term <*> item > > and h will be applied to the result of item again. Because we already > applied item once, the remaining input is "bc". Then, item will give you 'b' > as a result. > Now h 'b' = ('a, 'b'), which is the result of your final parser plus the > remaining input "c". Applying the final parser, you obtain > > [('a', 'b'), "c")] > > I hope this will help you ! > > Best, > Ivan > > 2017-08-03 21:19 GMT+02:00 Yassine : >> >> Hi, >> >> I have a question about functor applicate. >> >> I know that: >> pure (+1) <*> Just 2 >> >> >> produce: Just 3 >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 >> produce Just (2+1) >> >> >> but in more complex case like: >> newtype Parser a = P (String -> [(a,String)]) >> >> parse :: Parser a -> String -> [(a,String)] >> parse (P p) inp = p inp >> >> >> item :: Parser Char >> item = P (\inp -> case inp of >> [] -> [] >> (x:xs) -> [(x,xs)]) >> >> instance Functor Parser where >> fmap g p = P (\inp -> case p inp of >> [] -> [] >> [(v, out)] -> [(g v, out)]) >> >> instance Applicative Parser where >> pure v = P (\inp -> [(v, inp)]) >> pg <*> px = P (\inp -> case parse pg inp of >> [] -> [] >> [(g, out)] -> parse (fmap g px) out) >> >> >> When I do: >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" >> >> The answer is: >> [(('a','b'),"c")] >> >> But I don't understand what exactly happens. >> First: >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) >> >> Then: >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? >> >> Can someone explain what's happens step by step please. >> >> Thank you. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From 50295 at web.de Fri Aug 4 23:12:17 2017 From: 50295 at web.de (Olumide) Date: Sat, 5 Aug 2017 00:12:17 +0100 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: References: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> Message-ID: Thanks Theodore. I'm still pondering your answer and I've tried to write desugar the do-notation like so: stackyStack :: State Stack () stackyStack = get >>= (\stackNow -> ... ) I can _sort of_ see how the type of stackyStack 'imposes' a type on the polymorphic function get, even though I'm not sure that I can precisely explain *exactly* how it happens. Here is my attempt: Comparing the definition of bind (>>=) :: m a -> (a -> m b) -> m b with the desugared form of stackyStack, it seems to me that a is stackNow is an [Int], and m is State [Int]. Is this correct? On a not-too-unrelated note, why is the State (with upper case S) used in the following instance of the state monad instance Monad (State s) where return x = State $ \s -> (x,s) (State h) >>= f = State $ \s ... bearing in mind that Control.Monad.State does not expose its value constructor. Thanks, - Olumide On 02/08/17 03:26, Theodore Lief Gannon wrote: > Actually, get is constrained immediately to be State Stack Stack. If > later statements tried to use it as something else, it would be a type > error. > > The types in a do block can only vary in their final parameter. The type > of stackyStack is State Stack (), so in that do block all the statements > must be forall a. State Stack a. > > Now, check the type of get in GHCi: > get :: State a a > > We know that the first type parameter here is Stack, and the second > position is the same type, thus State Stack Stack. > > > > On Tue, Aug 1, 2017 at 5:13 PM, Olumide <50295 at web.de > > wrote: > > Of course 's' is not a type variable as its lowercase. > > Therefore, get is a monad 'constructed' by the state function, correct? > > So, in the do notation the lambda is extracted and used as per the > definition of bind. The context of which we speak therefore must > derive from the next expression(?) in the do notation, which is > somewhat confusing to determine in the example > > stackyStack :: State Stack () > stackyStack = do > stackNow <- get > if stackNow == [1,2,3] > then put [8,3,1] > else put [9,2,1] > > Regards, > > - Olumide > > On 02/08/17 00:35, Theodore Lief Gannon wrote: > > 's' here is not a type variable, it's an actual variable. \s -> > (s, s) defines a lambda function which takes any value, and > returns a tuple with that value in both positions. > > So yes, get is point-free, but the missing argument is right > there in-line. And yes, its type is simply implied from context. > > > On Aug 1, 2017 4:17 PM, "Olumide" <50295 at web.de > >> wrote: > > Ahoy Haskellers, > > In the section "Getting and Setting State" > (http://learnyouahaskell.com/for-a-few-monads-more#state > > >) in LYH > get is defined as > > get = state $ \s -> (s, s) > > How does does get determine the type s, is considering that > it has > no argument as per the definition given above? Or is the > definition > written in some sort of point-free notation where an > argument has > been dropped? > > I find the line stackNow <- get in the the function(?) > stackyStack > confusing for the same reason. I guess my difficulty is > that state $ > \s ->(s , s) has a generic type (s) whereas the stackyStack > has a > concrete type. Is the type of s determined from the type of the > stateful computation/do notation? > > Regards, > > - Olumide > _______________________________________________ > 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 > From rein.henrichs at gmail.com Tue Aug 8 06:12:24 2017 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Tue, 08 Aug 2017 06:12:24 +0000 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> References: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> Message-ID: On Tue, Aug 1, 2017 at 5:14 PM Olumide <50295 at web.de> wrote: > Of course 's' is not a type variable as its lowercase. > But type variables *are* lowercase. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Tue Aug 8 20:21:04 2017 From: 50295 at web.de (Olumide) Date: Tue, 8 Aug 2017 21:21:04 +0100 Subject: [Haskell-beginners] Grappling with State Monad get In-Reply-To: References: <857c118a-34a4-20c0-5414-719eb88b05c3@web.de> Message-ID: <830da6a4-2b65-2803-3031-6606be671af3@web.de> Type I meant to say. Thank for the correction. On 08/08/17 07:12, Rein Henrichs wrote: > On Tue, Aug 1, 2017 at 5:14 PM Olumide <50295 at web.de > > wrote: > > Of course 's' is not a type variable as its lowercase. > > > But type variables *are* lowercase. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From aquagnu at gmail.com Thu Aug 10 08:35:52 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 10 Aug 2017 11:35:52 +0300 Subject: [Haskell-beginners] How to make instance of MonoFunctor Message-ID: <20170810113552.08831716@Pavel> Hello, Dear List! I want to make functor of my type like newtype UserName = UserName { unName :: Text } sure, it's impossible, so I will make MonoFunctor instead of (from library mono-traversable). So, I try: instance MonoFunctor UserName where omap fn (UserName n) = UserName $ fn $ n but I get error • Couldn't match expected type ‘Element UserName’ with actual type ‘Text’ • In the second argument of ‘($)’, namely ‘unName an’ In the second argument of ‘($)’, namely ‘fn $ unName an’ In the expression: UserName $ fn $ unName an interesting is that Text "type Element Text" of "type family Element mono" (instance?). So, how to make mono-functor for such `UserName` structure? -- Best regards, Paul From michael at snoyman.com Thu Aug 10 08:58:04 2017 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 10 Aug 2017 11:58:04 +0300 Subject: [Haskell-beginners] How to make instance of MonoFunctor In-Reply-To: <20170810113552.08831716@Pavel> References: <20170810113552.08831716@Pavel> Message-ID: What do you want the type of `omap` to be for `UserName`? There are two reasonable definitions: omap :: (Text -> Text) -> (UserName -> UserName) omap :: (Char -> Char) -> (UserName -> UserName) The first one is saying that a UserName is a container of a single Text value. The second is that a UserName is a container of a sequence of Char values. Once you figure out what the answer to this question is, you'll need to use an associated type called Element to specify what you intend, e.g.: type Element UserName = Char On Thu, Aug 10, 2017 at 11:35 AM, Baa wrote: > Hello, Dear List! > > I want to make functor of my type like > > newtype UserName = UserName { unName :: Text } > > sure, it's impossible, so I will make MonoFunctor instead of (from > library mono-traversable). So, I try: > > instance MonoFunctor UserName where > omap fn (UserName n) = UserName $ fn $ n > > but I get error > > • Couldn't match expected type ‘Element UserName’ > with actual type ‘Text’ > • In the second argument of ‘($)’, namely ‘unName an’ > In the second argument of ‘($)’, namely ‘fn $ unName an’ > In the expression: UserName $ fn $ unName an > > interesting is that Text "type Element Text" of "type family Element > mono" (instance?). So, how to make mono-functor for such `UserName` > structure? > > > -- > 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 Thu Aug 10 09:34:30 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 10 Aug 2017 12:34:30 +0300 Subject: [Haskell-beginners] How to make instance of MonoFunctor In-Reply-To: References: <20170810113552.08831716@Pavel> Message-ID: <20170810123430.77e47a39@Pavel> Aha, so I missed: type instance Element UserName = Text and now this is right: instance MonoFunctor UserName where omap fn n = UserName $ fn $ unName n Yes, this will be omap :: (Text -> Text) -> (UserName -> UserName). Many thanks!! > What do you want the type of `omap` to be for `UserName`? There are > two reasonable definitions: > > omap :: (Text -> Text) -> (UserName -> UserName) > omap :: (Char -> Char) -> (UserName -> UserName) > > The first one is saying that a UserName is a container of a single > Text value. The second is that a UserName is a container of a > sequence of Char values. Once you figure out what the answer to this > question is, you'll need to use an associated type called Element to > specify what you intend, e.g.: > > type Element UserName = Char > > On Thu, Aug 10, 2017 at 11:35 AM, Baa wrote: > > > Hello, Dear List! > > > > I want to make functor of my type like > > > > newtype UserName = UserName { unName :: Text } > > > > sure, it's impossible, so I will make MonoFunctor instead of (from > > library mono-traversable). So, I try: > > > > instance MonoFunctor UserName where > > omap fn (UserName n) = UserName $ fn $ n > > > > but I get error > > > > • Couldn't match expected type ‘Element UserName’ > > with actual type ‘Text’ > > • In the second argument of ‘($)’, namely ‘unName an’ > > In the second argument of ‘($)’, namely ‘fn $ unName an’ > > In the expression: UserName $ fn $ unName an > > > > interesting is that Text "type Element Text" of "type family Element > > mono" (instance?). So, how to make mono-functor for such `UserName` > > structure? > > > > > > -- > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From lists0 at freea2a.de Fri Aug 11 20:11:54 2017 From: lists0 at freea2a.de (lists0 at freea2a.de) Date: Fri, 11 Aug 2017 22:11:54 +0200 Subject: [Haskell-beginners] How to "cabal install" on current Arch/Manjaro ? Message-ID: <20170811221154.3a947565@duin> Helle dear readers, at the moment I'm not able to compile the most things with cabal/ghc. For example: cabal install cpphs gives Linking dist/build/cpphs/cpphs ... /usr/bin/ld: cannot find -lHStext-1.2.2.2-3ENqlljngKa6xj1Go2fVWq I have read that Arch linux has changed haskell to use dynamic linking, and I have installed the new packet "ghc-static" with static libraries. How can I switch between static and dynamic linking in cabal and what are the preconditions? Where can I give the directories for searching for haskell-libraries? Thank you in advance for help. Jürgen From lists0 at freea2a.de Sun Aug 13 19:32:56 2017 From: lists0 at freea2a.de (lists0 at freea2a.de) Date: Sun, 13 Aug 2017 21:32:56 +0200 Subject: [Haskell-beginners] How to "cabal install" on current Arch/Manjaro ? In-Reply-To: <20170811221154.3a947565@duin> References: <20170811221154.3a947565@duin> Message-ID: <20170813213256.4f9457b2@duin> Hi all, update: compilition was possible with the undocumented flag: --ghc-options -dynamic so: cabal install cpphs --ghc-options -dynamic I found it in a reddit-post (https://www.reddit.com/r/archlinux/comments/6nlglg/arch_haskell/) But I'm still not sure, what I have done with ghc and cabal :-( Greetings Jürgen Op Fri, 11 Aug 2017 22:11:54 +0200 lists0 at freea2a.de schreef: > Helle dear readers, > > at the moment I'm not able to compile the most things with cabal/ghc. > > For example: > cabal install cpphs > > gives > > Linking dist/build/cpphs/cpphs ... > /usr/bin/ld: cannot find -lHStext-1.2.2.2-3ENqlljngKa6xj1Go2fVWq > > I have read that Arch linux has changed haskell to use dynamic > linking, and I have installed the new packet "ghc-static" with static > libraries. > > How can I switch between static and dynamic linking in cabal and what > are the preconditions? > Where can I give the directories for searching for haskell-libraries? > > Thank you in advance for help. > > Jürgen > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From voldermort at hotmail.com Thu Aug 17 07:55:28 2017 From: voldermort at hotmail.com (Jonathon Delgado) Date: Thu, 17 Aug 2017 07:55:28 +0000 Subject: [Haskell-beginners] Ambiguous type variable Message-ID: I'm trying to use catch (...) (\e -> putStrLn $ show e) However, I get an error Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved. This goes away if I change the code to catch (...) (\e -> putStrLn $ show (e::IOException)) A couple of things I don't understand here: - The signature for catch begins "Exception e", and exception it "class (Typeable e, Show e) => Exception e". So why isn't show automatically available? - Why does the new code work at all? e is Exception, not IOException. What would happen if it caught a different Exception? From fa-ml at ariis.it Thu Aug 17 08:15:18 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 17 Aug 2017 10:15:18 +0200 Subject: [Haskell-beginners] Ambiguous type variable In-Reply-To: References: Message-ID: <20170817081518.ar27uotrgpqsbxxs@x60s.casa> On Thu, Aug 17, 2017 at 07:55:28AM +0000, Jonathon Delgado wrote: > I'm trying to use > catch (...) (\e -> putStrLn $ show e) > However, I get an error > Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved. > This goes away if I change the code to > catch (...) (\e -> putStrLn $ show (e::IOException)) > > A couple of things I don't understand here: > - The signature for catch begins "Exception e", and exception it "class (Typeable e, Show e) => Exception e". So why isn't show automatically available? > - Why does the new code work at all? e is Exception, not IOException. What would happen if it caught a different Exception? IOException is a concrete type while Exception is a typeclass. In the end, the compiler needs the former, the latter not being enough. The code works as any other class-based function would someFunction :: Monoid a -> [a] -> a -- ^-- in the end `Monoid a` will become something concrete, like -- a String, a Sum, etc. Does that make sense? From michael at snoyman.com Thu Aug 17 08:58:31 2017 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 17 Aug 2017 11:58:31 +0300 Subject: [Haskell-beginners] Ambiguous type variable In-Reply-To: References: Message-ID: On Thu, Aug 17, 2017 at 10:55 AM, Jonathon Delgado wrote: > I'm trying to use > catch (...) (\e -> putStrLn $ show e) > However, I get an error > Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the > constraint ‘(Show a0)’ from being solved. > This goes away if I change the code to > catch (...) (\e -> putStrLn $ show (e::IOException)) > > A couple of things I don't understand here: > - The signature for catch begins "Exception e", and exception it "class > (Typeable e, Show e) => Exception e". So why isn't show automatically > available? > - Why does the new code work at all? e is Exception, not IOException. What > would happen if it caught a different Exception? > In my experience, the most common thing people need is "catch all synchronous exceptions." The word "synchronous" there is the source of a lot of confusion, and relates to a complicated topic of asynchronous exceptions. My recommendation is: don't worry about that right now, use the safe-exceptions package, and switch from catch to catchAny. More details on the package are available at: https://haskell-lang.org/library/safe-exceptions -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Thu Aug 17 12:24:07 2017 From: voldermort at hotmail.com (Jonathon Delgado) Date: Thu, 17 Aug 2017 12:24:07 +0000 Subject: [Haskell-beginners] Ambiguous type variable Message-ID: I'm sure it makes sense! I'm not really following though. I understood typeclasses to be analogous to OO interfaces. So if a variable implements the Exception interface, and Exception implements the Show interface, then it should automatically support show. I take it this was wrong? How does the compiler use typeclasses if they're not interfaces? Francesco Ariis wrote: > I'm trying to use >   catch (...) (\e -> putStrLn $ show e) > However, I get an error >   Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved. > This goes away if I change the code to >   catch (...) (\e -> putStrLn $ show (e::IOException)) > > A couple of things I don't understand here: > - The signature for catch begins "Exception e", and exception it "class (Typeable e, Show e) => Exception e". So why isn't show automatically available? > - Why does the new code work at all? e is Exception, not IOException. What would happen if it caught a different Exception? IOException is a concrete type while Exception is a typeclass. In the end, the compiler needs the former, the latter not being enough. The code works as any other class-based function would     someFunction :: Monoid a -> [a] -> a     -- ^-- in the end `Monoid a` will become something concrete, like     -- a String, a Sum, etc. Does that make sense? From markus.l2ll at gmail.com Thu Aug 17 13:25:43 2017 From: markus.l2ll at gmail.com (=?UTF-8?B?TWFya3VzIEzDpGxs?=) Date: Thu, 17 Aug 2017 15:25:43 +0200 Subject: [Haskell-beginners] Ambiguous type variable In-Reply-To: References: Message-ID: Hi Jonathon! You only catch some specific type of exception, everything else is simply past onwards. See end of p. 2/beginning of p. 3 here: http://community.haskell.org/~simonmar/papers/ext-exceptions.pdf On Thu, Aug 17, 2017 at 2:24 PM, Jonathon Delgado wrote: > I'm sure it makes sense! I'm not really following though. > > I understood typeclasses to be analogous to OO interfaces. So if a > variable implements the Exception interface, and Exception implements the > Show interface, then it should automatically support show. > > I take it this was wrong? How does the compiler use typeclasses if they're > not interfaces? > > > Francesco Ariis wrote: > > > I'm trying to use > > catch (...) (\e -> putStrLn $ show e) > > However, I get an error > > Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the > constraint ‘(Show a0)’ from being solved. > > This goes away if I change the code to > > catch (...) (\e -> putStrLn $ show (e::IOException)) > > > > A couple of things I don't understand here: > > - The signature for catch begins "Exception e", and exception it "class > (Typeable e, Show e) => Exception e". So why isn't show automatically > available? > > - Why does the new code work at all? e is Exception, not IOException. > What would happen if it caught a different Exception? > > IOException is a concrete type while Exception is a typeclass. In the end, > the compiler needs the former, the latter not being enough. > > The code works as any other class-based function would > > someFunction :: Monoid a -> [a] -> a > -- ^-- in the end `Monoid a` will become something concrete, like > -- a String, a Sum, etc. > > Does that make sense? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Markus Läll -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Aug 17 13:29:27 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 17 Aug 2017 15:29:27 +0200 Subject: [Haskell-beginners] Ambiguous type variable In-Reply-To: References: Message-ID: <20170817132927.pvwg64etmjuxznu2@x60s.casa> On Thu, Aug 17, 2017 at 12:24:07PM +0000, Jonathon Delgado wrote: > I'm sure it makes sense! I'm not really following though. > > I understood typeclasses to be analogous to OO interfaces. So if a variable > implements the Exception interface, and Exception implements the Show > interface, then it should automatically support show. > > I take it this was wrong? How does the compiler use typeclasses if they're > not interfaces? That's correct! Indeed ghc is not complaining about a lack of instances, as it would with, say λ> putStrLn 5 -- • No instance for (Num String) arising from etc etc. but about the *ambiguity* of type variable `e`. How does `catch` know _which_ exception to deal with if you don't specify the concrete type? Consider: prova = catch (print $ div (error "hey bby") 0) (\e -> print "ouch" >> print (e :: ErrorCall)) -- I want to deal with arithmetic errors here and not in `prova` palla = catch prova (\e -> print "baaah" >> print (e :: ArithException)) If I switch ArithException and ErrorCall the behaviour of invoking `palla` changes. Having a catch-all `catch` is possible by using (e :: SomeException); if you don't care about `e` and just want to do an action regardless, you are probably better off with `onException`. Ask more if needed! From michael at snoyman.com Thu Aug 17 13:36:49 2017 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 17 Aug 2017 16:36:49 +0300 Subject: [Haskell-beginners] Ambiguous type variable In-Reply-To: <20170817132927.pvwg64etmjuxznu2@x60s.casa> References: <20170817132927.pvwg64etmjuxznu2@x60s.casa> Message-ID: On Thu, Aug 17, 2017 at 4:29 PM, Francesco Ariis wrote: > On Thu, Aug 17, 2017 at 12:24:07PM +0000, Jonathon Delgado wrote: > > I'm sure it makes sense! I'm not really following though. > > > > I understood typeclasses to be analogous to OO interfaces. So if a > variable > > implements the Exception interface, and Exception implements the Show > > interface, then it should automatically support show. > > > > I take it this was wrong? How does the compiler use typeclasses if > they're > > not interfaces? > > That's correct! Indeed ghc is not complaining about a lack of > instances, as it would with, say > > λ> putStrLn 5 > -- • No instance for (Num String) arising from etc etc. > > but about the *ambiguity* of type variable `e`. How does `catch` know > _which_ exception to deal with if you don't specify the concrete type? > Consider: > > prova = catch (print $ div (error "hey bby") 0) > (\e -> print "ouch" >> > print (e :: ErrorCall)) > > -- I want to deal with arithmetic errors here and not in `prova` > palla = catch prova > (\e -> print "baaah" >> > print (e :: ArithException)) > > If I switch ArithException and ErrorCall the behaviour of invoking `palla` > changes. > > Having a catch-all `catch` is possible by using (e :: SomeException); > if you don't care about `e` and just want to do an action regardless, you > are probably better off with `onException`. > > This is dangerous: `catch` with `e :: SomeException` will catch all asynchronous exceptions, breaking things like timeout, race, and the async library in general. That's why my message about mentioned the safe-exceptions package. Michael > Ask more if needed! > _______________________________________________ > 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 voldermort at hotmail.com Thu Aug 17 14:18:41 2017 From: voldermort at hotmail.com (Jonathon Delgado) Date: Thu, 17 Aug 2017 14:18:41 +0000 Subject: [Haskell-beginners] Ambiguous type variable Message-ID: Thank you very much, that does clarify things! Francesco Ariis wrote: That's correct! Indeed ghc is not complaining about a lack of instances, as it would with, say     λ> putStrLn 5     -- • No instance for (Num String) arising from etc etc. but about the *ambiguity* of type variable `e`.  How does `catch` know _which_ exception to deal with if you don't specify the concrete type? Consider:     prova = catch (print $ div (error "hey bby") 0)                   (\e -> print "ouch" >>                          print (e :: ErrorCall))     -- I want to deal with arithmetic errors here and not in `prova`     palla = catch prova                   (\e -> print "baaah" >>                          print (e :: ArithException)) If I switch ArithException and ErrorCall the behaviour of invoking `palla` changes. Having a catch-all `catch` is possible by using (e :: SomeException); if you don't care about `e` and just want to do an action regardless, you are probably better off with `onException`. Ask more if needed! From ivanllopard at gmail.com Thu Aug 17 19:20:10 2017 From: ivanllopard at gmail.com (Ivan Llopard) Date: Thu, 17 Aug 2017 21:20:10 +0200 Subject: [Haskell-beginners] Applicative: how <*> really works In-Reply-To: References: Message-ID: Exactly, It is left-associative and it will apply "pure g", which does nothing in terms of parsing but put g into the parsing result, and then apply item. Another way to think about it, is to forget about the list and think only in terms of types. With a value of type Parser (a -> (b, c)) and Parser a you can use <*> to get a value of type Parser (b, c). Then, if you execute such a parser you will have a list of nested tuples as you requested, i.e. [(b, c), String]. Try your first example with g = (\x -> (x,0)) and pure g <*> item. Play with different expressions and the applicative operator. Best, Ivan 2017-08-05 0:29 GMT+02:00 Yassine : > Thanks for you nice answer but I still have some difficulties. > > When you do: > g = (\x y -> (x,y)) > first_item = pure g <*> item > > Because <*> is left associative, we do first the application of g on > item before apply item, is it correct ? > > Furthermore, item return a list containing a tuple with the first > character and the remaining of the string. So how can I get a list > with a tuple containing another tuple with the parsed characters > (inner tuple) and the remaining of the string (in the outer tuple). > > 2017-08-04 23:30 GMT+02:00 Ivan Llopard : > > Hi Yassine, > > > > I prefer to explain you with an abstract view of these definitions. > > Unrolling this stuff in your mind (or paper) can be complex and, IMO, it > > might be useless as it does not give you any specific hints to build even > > more complex ones. > > > > You can view Parser a as an object with a certain structure (or form, or > > definition if you prefer). However, you do not want to know how complex > its > > structure or definition is. You are certain about one thing, it holds > some > > value of type a. > > Let's say that such value is "hidden" by Parser. The same idea applies to > > Maybe a. > > > > Then, you want to work with that value no matter the structure of > Parser. As > > you already know, fmap allows you to do that. You can go from Parser a to > > Parser b with a function from a to b. > > The applicative allows you to go further. If you have a hidden function > > (e.g. Parser (a->b)) and a hidden parameter (Parser a). Then you want to > > apply that hidden function to the hidden parameter in order to obtain a > > Parser b. > > That is what the expression parserF <*> ParserA would do if parserF > hides a > > function and parserA its parameter. > > > > Now, you need to know more about the meaning of Parser a. It is an object > > that reads the input and produce a result (or token) accordingly. > > The returned value of the parser is a list of (result, remaining_input). > > The interesting part is the result value, which is of type a. You want to > > play around with it. Again, fmap is an easy way. Going from Parser a to > > Parser b via fmap does not change the parsing action of Parser a, you > will > > have a Parser b but the behavior remains the same. You just played with > the > > result of the first parser. > > > > The functor instance tells that more precisely (fixed): > > > > instance Functor Parser where > > fmap g (P p) = P (\inp -> case p inp of > > [] -> [] > > [(v, out)] -> [(g v, out)]) > > > > Now look at the definition of the applicative > > > > instance Applicative Parser where > > pure v = P (\inp -> [(v, inp)]) > > pg <*> px = P (\inp -> case parse pg inp of > > [] -> [] > > [(g, out)] -> parse (fmap g px) out) > > > > First of all, the function "parser" applies the parser, i.e., it parses > the > > input and returns the list [(g, out)]. Here, we have two applications of > > "parser". > > The first one applies parser pg, "case parse pg inp". Obviously, pg > hides a > > function "g". > > Now you preserve the same behavior of px but you fmap on it function "g". > > That is, the parser "fmap g px" will do the same as px but its result is > > changed by g. > > And finally, you apply such parser. > > > > Let us take the first two terms of your example > > > > first_item = pure (\x y -> (x,y)) <*> item > > > > then g = \x y -> (x,y) > > which is a higher order function. In the expression, g is applied > partially > > over the result of item. You know that item returns the first char of the > > input, 'a'. > > first_item is then a parser that hides a function of the form h = \y -> > > ('a', y). > > > > Because it hides a function, you can use the applicative again > > > > first_term <*> item > > > > and h will be applied to the result of item again. Because we already > > applied item once, the remaining input is "bc". Then, item will give you > 'b' > > as a result. > > Now h 'b' = ('a, 'b'), which is the result of your final parser plus the > > remaining input "c". Applying the final parser, you obtain > > > > [('a', 'b'), "c")] > > > > I hope this will help you ! > > > > Best, > > Ivan > > > > 2017-08-03 21:19 GMT+02:00 Yassine : > >> > >> Hi, > >> > >> I have a question about functor applicate. > >> > >> I know that: > >> pure (+1) <*> Just 2 > >> > >> > >> produce: Just 3 > >> because pure (+1) produce Just (+1) and then Just (+1) <*> Just 2 > >> produce Just (2+1) > >> > >> > >> but in more complex case like: > >> newtype Parser a = P (String -> [(a,String)]) > >> > >> parse :: Parser a -> String -> [(a,String)] > >> parse (P p) inp = p inp > >> > >> > >> item :: Parser Char > >> item = P (\inp -> case inp of > >> [] -> [] > >> (x:xs) -> [(x,xs)]) > >> > >> instance Functor Parser where > >> fmap g p = P (\inp -> case p inp of > >> [] -> [] > >> [(v, out)] -> [(g v, out)]) > >> > >> instance Applicative Parser where > >> pure v = P (\inp -> [(v, inp)]) > >> pg <*> px = P (\inp -> case parse pg inp of > >> [] -> [] > >> [(g, out)] -> parse (fmap g px) out) > >> > >> > >> When I do: > >> parse (pure (\x y -> (x,y)) <*> item <*> item) "abc" > >> > >> The answer is: > >> [(('a','b'),"c")] > >> > >> But I don't understand what exactly happens. > >> First: > >> pure (\x y -> (x,y)) => P (\inp -> [(\x y -> (x,y), inp)]) > >> > >> Then: > >> P (\inp -> [(\x y -> (x,y), inp)]) <*> item => ??? > >> > >> Can someone explain what's happens step by step please. > >> > >> Thank you. > >> _______________________________________________ > >> 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 Fri Aug 18 09:35:19 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 18 Aug 2017 12:35:19 +0300 Subject: [Haskell-beginners] Fractional of DiffTime Message-ID: <20170818123519.06c26706@Pavel> Hello, List! DiffTime type has "closed" on itself operation "/". So, (/) :: DiffTime -> DiffTime -> DiffTime But from a physics point of view, it doesn't make sense. When you divide hours by hours you get "dimensionless" value, not units (hours) but simple number (I'm not sure how it's named in English). And it's true for any physical values: [m/s] : [m/s] = [Int] (not [m/s] sure) Is it right to define CLOSED "/" for such set like DiffTime? === Best regards, Paul From toad3k at gmail.com Fri Aug 18 12:34:29 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 18 Aug 2017 08:34:29 -0400 Subject: [Haskell-beginners] Fractional of DiffTime In-Reply-To: <20170818123519.06c26706@Pavel> References: <20170818123519.06c26706@Pavel> Message-ID: DiffTimes need to be added and subtracted. Unfortunately to add or subtract anything you must implement the Num class. By doing that you now you either also support division and multiplication, or you throw a runtime error. This also comes up with vectors and matrices which don't follow the usual Num rules, and so must have their own operators in libraries to support their operations. It has been suggested in the past to separate all of the operations in the Num class into their constituent parts, say Addable, Subtractable, Multiplicative, Negatable, etc, but you can imagine the boilerplate of implementing all those classes for your own types, and also the hairy types that would be inferred by the compiler for very simple arithmetic functions. But if you are going to go that far, you might as well try to go all the way down into number theory. So there are alternative numeric preludes that attempt to deal with most of this stuff on hackage. For example numeric-prelude, although that library does not include DiffTime specifically, it likely has the classes necessary to make a reasonable go at it. On Fri, Aug 18, 2017 at 5:35 AM, Baa wrote: > Hello, List! > > DiffTime type has "closed" on itself operation "/". So, > > (/) :: DiffTime -> DiffTime -> DiffTime > > But from a physics point of view, it doesn't make sense. When you > divide hours by hours you get "dimensionless" value, not units > (hours) but simple number (I'm not sure how it's named in English). > > And it's true for any physical values: > > [m/s] : [m/s] = [Int] (not [m/s] sure) > > Is it right to define CLOSED "/" for such set like DiffTime? > > === > Best regards, Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Fri Aug 18 13:04:16 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 18 Aug 2017 16:04:16 +0300 Subject: [Haskell-beginners] Fractional of DiffTime In-Reply-To: References: <20170818123519.06c26706@Pavel> Message-ID: <20170818160416.7859455a@Pavel> Hello, David. Interesting... There is also library num-hask, but no DiffTime there. > It has been suggested in the past to separate all of the operations in > the Num class into their constituent parts, say Addable, Subtractable, > Multiplicative, Negatable, etc, but you can imagine the boilerplate of > implementing all those classes for your own types, and also the hairy > types that would be inferred by the compiler for very simple > arithmetic functions. But if you are going to go that far, you might > as well try to go all the way down into number theory. It makes sense. OK. Thank you! > > So there are alternative numeric preludes that attempt to deal with > most of this stuff on hackage. For example numeric-prelude, although > that library does not include DiffTime specifically, it likely has the > classes necessary to make a reasonable go at it. > > On Fri, Aug 18, 2017 at 5:35 AM, Baa wrote: > > Hello, List! > > > > DiffTime type has "closed" on itself operation "/". So, > > > > (/) :: DiffTime -> DiffTime -> DiffTime > > > > But from a physics point of view, it doesn't make sense. When you > > divide hours by hours you get "dimensionless" value, not units > > (hours) but simple number (I'm not sure how it's named in English). > > > > And it's true for any physical values: > > > > [m/s] : [m/s] = [Int] (not [m/s] sure) > > > > Is it right to define CLOSED "/" for such set like DiffTime? > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Aug 25 08:05:34 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 25 Aug 2017 08:05:34 +0000 Subject: [Haskell-beginners] Maybe a -> Maybe b Message-ID: Hello, I have this data Proxy = Proxy String And I want to write a function f :: Maybe Proxy -> Maybe String f ma = case ma of (Just (Proxy a)) -> Just a Nothing -> Nothing I was wondering if there is no simpler way to do this ? thanks Frederic From olivier at iffrig.eu Fri Aug 25 12:27:57 2017 From: olivier at iffrig.eu (Olivier Iffrig) Date: Fri, 25 Aug 2017 14:27:57 +0200 Subject: [Haskell-beginners] Maybe a -> Maybe b In-Reply-To: References: Message-ID: <20170825122757.tj2u5u2gn53fkvue@neon.iffrig.eu> PICCA Frederic-Emmanuel wrote (2017-08-25 08:05:34): > Hello, I have this > > data Proxy = Proxy String > > And I want to write a function > > f :: Maybe Proxy -> Maybe String > f ma = case ma of > (Just (Proxy a)) -> Just a > Nothing -> Nothing > > I was wondering if there is no simpler way to do this ? Maybe implements the Functor type class (as an exercise, you can try to figure out the implementation), therefore you can simply use fmap, which in the case of Maybe, has type (a -> b) -> Maybe a -> Maybe b You just need a function to "unwrap" the String inside of the Proxy, and you're done. -- Olivier From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Aug 25 12:45:37 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 25 Aug 2017 12:45:37 +0000 Subject: [Haskell-beginners] Maybe a -> Maybe b In-Reply-To: <20170825122757.tj2u5u2gn53fkvue@neon.iffrig.eu> References: , <20170825122757.tj2u5u2gn53fkvue@neon.iffrig.eu> Message-ID: > Maybe implements the Functor type class (as an exercise, you can try to > figure out the implementation), therefore you can simply use fmap, which > in the case of Maybe, has type (a -> b) -> Maybe a -> Maybe b Thanks I reallized this after sending the email thanks Frederic From imantc at gmail.com Fri Aug 25 12:56:41 2017 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 25 Aug 2017 15:56:41 +0300 Subject: [Haskell-beginners] Maybe a -> Maybe b In-Reply-To: References: <20170825122757.tj2u5u2gn53fkvue@neon.iffrig.eu> Message-ID: > as an exercise, you can try to figure out the implementation .. time is up :-P Here is an answer for slightly more generic Proxy and f: data Proxy a = Proxy a exProxy::Functor f => f (Proxy a) -> f a exProxy = (un1 <$>) where un1 (Proxy a1) = a1 ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From deepmindster at gmail.com Fri Aug 25 12:58:05 2017 From: deepmindster at gmail.com (Andrey Klaus) Date: Fri, 25 Aug 2017 15:58:05 +0300 Subject: [Haskell-beginners] Beginners Digest, Vol 110, Issue 20 In-Reply-To: References: Message-ID: Hello f ma = fmap ((Proxy a) -> Just a) ma or even shorter f = fmap ((Proxy a) -> Just a) 2017-08-25 15:00 GMT+03:00 : > 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. Maybe a -> Maybe b (PICCA Frederic-Emmanuel) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 25 Aug 2017 08:05:34 +0000 > From: PICCA Frederic-Emmanuel > > To: "beginners at haskell.org" > Subject: [Haskell-beginners] Maybe a -> Maybe b > Message-ID: > synchrotron-soleil.fr> > > Content-Type: text/plain; charset="us-ascii" > > Hello, I have this > > data Proxy = Proxy String > > And I want to write a function > > f :: Maybe Proxy -> Maybe String > f ma = case ma of > (Just (Proxy a)) -> Just a > Nothing -> Nothing > > I was wondering if there is no simpler way to do this ? > > thanks > > Frederic > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 110, Issue 20 > ****************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deepmindster at gmail.com Fri Aug 25 13:03:49 2017 From: deepmindster at gmail.com (Andrey Klaus) Date: Fri, 25 Aug 2017 16:03:49 +0300 Subject: [Haskell-beginners] Beginners Digest, Vol 110, Issue 20 In-Reply-To: References: Message-ID: sorry, these 2 should be correct f ma = fmap (\(Proxy a) -> a) ma f = fmap (\(Proxy a) -> a) 2017-08-25 15:58 GMT+03:00 Andrey Klaus : > Hello > > f ma = fmap ((Proxy a) -> Just a) ma > > or even shorter > > f = fmap ((Proxy a) -> Just a) > > > 2017-08-25 15:00 GMT+03:00 : > >> 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. Maybe a -> Maybe b (PICCA Frederic-Emmanuel) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Fri, 25 Aug 2017 08:05:34 +0000 >> From: PICCA Frederic-Emmanuel >> >> To: "beginners at haskell.org" >> Subject: [Haskell-beginners] Maybe a -> Maybe b >> Message-ID: >> > on-soleil.fr> >> >> Content-Type: text/plain; charset="us-ascii" >> >> Hello, I have this >> >> data Proxy = Proxy String >> >> And I want to write a function >> >> f :: Maybe Proxy -> Maybe String >> f ma = case ma of >> (Just (Proxy a)) -> Just a >> Nothing -> Nothing >> >> I was wondering if there is no simpler way to do this ? >> >> thanks >> >> Frederic >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> ------------------------------ >> >> End of Beginners Digest, Vol 110, Issue 20 >> ****************************************** >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Aug 25 13:06:01 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 25 Aug 2017 13:06:01 +0000 Subject: [Haskell-beginners] Maybe a -> Maybe b In-Reply-To: References: <20170825122757.tj2u5u2gn53fkvue@neon.iffrig.eu> , Message-ID: data Proxy a = Proxy a exProxy::Functor f => f (Proxy a) -> f a exProxy = (un1 <$>) where un1 (Proxy a1) = a1 nice :) ​ From mamontov.dp at gmail.com Fri Aug 25 13:06:16 2017 From: mamontov.dp at gmail.com (Dmitry Mamontov) Date: Fri, 25 Aug 2017 16:06:16 +0300 Subject: [Haskell-beginners] Beginners Digest, Vol 110, Issue 20 In-Reply-To: References: Message-ID: Hello, Maybe, using fmap would be enough? data Proxy = Proxy String f :: Maybe Proxy -> Maybe String f = fmap (\(Proxy a) -> a) 2017-08-25 15:00 GMT+03:00 : > 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. Maybe a -> Maybe b (PICCA Frederic-Emmanuel) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 25 Aug 2017 08:05:34 +0000 > From: PICCA Frederic-Emmanuel > > To: "beginners at haskell.org" > Subject: [Haskell-beginners] Maybe a -> Maybe b > Message-ID: > synchrotron-soleil.fr> > > Content-Type: text/plain; charset="us-ascii" > > Hello, I have this > > data Proxy = Proxy String > > And I want to write a function > > f :: Maybe Proxy -> Maybe String > f ma = case ma of > (Just (Proxy a)) -> Just a > Nothing -> Nothing > > I was wondering if there is no simpler way to do this ? > > thanks > > Frederic > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 110, Issue 20 > ****************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Tue Aug 29 12:36:05 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 29 Aug 2017 15:36:05 +0300 Subject: [Haskell-beginners] How to parse JSON into existential type Message-ID: <20170829153605.4a8cbd01@Pavel> Hello List! In some of my JSONs I have part "list of any values", for example: [1, "hi", "false", 2.71] To parse it I create type like: data RespItem = forall a. FromJSON a => RespItem { riItem :: [a] } ,------------------------------------------------------------------- | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't | see any difference, so I'm not sure what is right constraints list. `------------------------------------------------------------------- And GHC does not allow to derive automatically with "deriving" Show and Generic instances for existential types, as I see. So I write: instance Generic RespItem instance Show RespItem Also this type `RespItem` in part of another one: data Resp = Resp { rHeadings :: [T.Text] , rRow :: [RespItem] } deriving (Generic, Show) Interesting is that now auto-`deriving` works! OK, but I need to to instantiate `FromJSON` for RespItem because next step must be `FromJSON` for Resp. So I'm trying: instance FromJSON RespItem where parseJSON ??? = ??? and here I get different errors, and absolutely don't understand how to parse it, I get "ambiguous type error..." and so on (which is right, sure). === Best regards, Paul From toad3k at gmail.com Tue Aug 29 12:56:06 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 08:56:06 -0400 Subject: [Haskell-beginners] How to parse JSON into existential type In-Reply-To: <20170829153605.4a8cbd01@Pavel> References: <20170829153605.4a8cbd01@Pavel> Message-ID: Rather than having an existential, which is difficult to work with at the best of times, how about making RespItem into something concrete? You could make your own data type to represent strings and arrays and objects, etc, but you could also just use Value from aeson, since it already exists and already has a FromJSON instance. data Resp = Resp { rHeadings :: [T.Text], rRow :: [Data.Aeson.Value] } I couldn't get deriving Generic to work, but I've personally not had too much trouble writing aeson instances manually. instance FromJSON Resp where parseJSON = withObject "Resp" $ \v -> Resp <$> v .: "headings" <*> v .: "rows" There is also an aeson-lens package that can make parsing json easy, if you are into lenses. On Tue, Aug 29, 2017 at 8:36 AM, Baa wrote: > Hello List! > > In some of my JSONs I have part "list of any values", for example: > > [1, "hi", "false", 2.71] > > To parse it I create type like: > > data RespItem = forall a. FromJSON a => RespItem { > riItem :: [a] } > > ,------------------------------------------------------------------- > | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't > | see any difference, so I'm not sure what is right constraints list. > `------------------------------------------------------------------- > > And GHC does not allow to derive automatically with "deriving" Show > and Generic instances for existential types, as I see. So I write: > > instance Generic RespItem > instance Show RespItem > > Also this type `RespItem` in part of another one: > > data Resp = Resp { > rHeadings :: [T.Text] > , rRow :: [RespItem] > } deriving (Generic, Show) > > Interesting is that now auto-`deriving` works! OK, but I need to > to instantiate `FromJSON` for RespItem because next step must be > `FromJSON` for Resp. So I'm trying: > > instance FromJSON RespItem where > parseJSON ??? = ??? > > and here I get different errors, and absolutely don't understand how to > parse it, I get "ambiguous type error..." and so on (which is right, > sure). > > > === > Best regards, Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From mannyromero at mail.com Tue Aug 29 13:02:31 2017 From: mannyromero at mail.com (Manny Romero) Date: Tue, 29 Aug 2017 15:02:31 +0200 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." Message-ID: An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Aug 29 13:08:35 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 09:08:35 -0400 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." In-Reply-To: References: Message-ID: The problem most users face with using straight up cabal is that often the needs of one package conflict with the needs of some of the others you've installed. I highly recommend you use stack to install idris. The process should look something like this: download stack, install it. (directions here: https://docs.haskellstack.org/en/stable/README/) git clone https://github.com/idris-lang/Idris-dev.git cd idris-dev stack install And then either run ~/.local/bin/idris or make sure .local/bin is in your PATH so that you can run idris on the command line. On Tue, Aug 29, 2017 at 9:02 AM, Manny Romero wrote: > I am a Linux user (Mint 18) trying to install Idris. I don't know the > slightest thing about computers. I barely managed to install Linux, and > later the full GHC, based on ample instructions available on the Web. (Still > don't actually recall how I did it!) > > Idris, however, seems a little trickier. I followed the website > (https://www.idris-lang.org/download/)'s instructions: > > cabal update > cabal install idris > > ...because apparently I installed "cabal" at some point. But I get this > message, which apparently is quite common: > > cabal: The following packages are likely to be broken by the reinstalls: > semigroupoids-5.1 > lens-4.15.1 > kan-extensions-5.0.1 > profunctors-5.2 > comonad-5 > bifunctors-5.4.1 > Use --force-reinstalls if you want to install anyway. > > ...those are some of my favorite things! I can't live without them! I am > reading things about creating a "sandbox" and so forth. But I cannot use or > make sense of this information. I don't know the first thing about cabal; I > never use it; I just load everything into GHCI all the time. > > Does anyone have some *specific* instructions that I can follow (as "rotely" > and dumbly as possible) to get Idris downloaded so I can use it for some > beginning studies, without breaking Haskell? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From aquagnu at gmail.com Tue Aug 29 13:08:51 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 29 Aug 2017 16:08:51 +0300 Subject: [Haskell-beginners] How to parse JSON into existential type In-Reply-To: References: <20170829153605.4a8cbd01@Pavel> Message-ID: <20170829160851.2e15c95b@Pavel> Ohh, right, there is `Value`!! Thank you David for good idea! > Rather than having an existential, which is difficult to work with at > the best of times, how about making RespItem into something concrete? > You could make your own data type to represent strings and arrays and > objects, etc, but you could also just use Value from aeson, since it > already exists and already has a FromJSON instance. > > data Resp = Resp { > rHeadings :: [T.Text], > rRow :: [Data.Aeson.Value] > } > > I couldn't get deriving Generic to work, but I've personally not had > too much trouble writing aeson instances manually. > > instance FromJSON Resp where > parseJSON = withObject "Resp" $ \v -> Resp <$> v .: "headings" <*> > v .: "rows" > > There is also an aeson-lens package that can make parsing json easy, > if you are into lenses. > > > On Tue, Aug 29, 2017 at 8:36 AM, Baa wrote: > > Hello List! > > > > In some of my JSONs I have part "list of any values", for example: > > > > [1, "hi", "false", 2.71] > > > > To parse it I create type like: > > > > data RespItem = forall a. FromJSON a => RespItem { > > riItem :: [a] } > > > > ,------------------------------------------------------------------- > > | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't > > | see any difference, so I'm not sure what is right constraints > > list. > > `------------------------------------------------------------------- > > > > And GHC does not allow to derive automatically with "deriving" Show > > and Generic instances for existential types, as I see. So I write: > > > > instance Generic RespItem > > instance Show RespItem > > > > Also this type `RespItem` in part of another one: > > > > data Resp = Resp { > > rHeadings :: [T.Text] > > , rRow :: [RespItem] > > } deriving (Generic, Show) > > > > Interesting is that now auto-`deriving` works! OK, but I need to > > to instantiate `FromJSON` for RespItem because next step must be > > `FromJSON` for Resp. So I'm trying: > > > > instance FromJSON RespItem where > > parseJSON ??? = ??? > > > > and here I get different errors, and absolutely don't understand > > how to parse it, I get "ambiguous type error..." and so on (which > > is right, sure). > > > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From shishir.srivastava at gmail.com Tue Aug 29 15:04:53 2017 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Tue, 29 Aug 2017 16:04:53 +0100 Subject: [Haskell-beginners] Multiline code in GHCi In-Reply-To: References: Message-ID: Just revisiting haskell after a hiatus and to begin that with a rather uncalled for query - In the system type declaration for the data type Bool as below what are the types of the two values 'True' and 'False' *data Bool = False | True* Are the values 'String' ? In which case how's the Bool data type different from String enumerator data type ? Thanks, S -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Aug 29 15:20:01 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 11:20:01 -0400 Subject: [Haskell-beginners] Multiline code in GHCi In-Reply-To: References: Message-ID: The type of both True and False is Bool. Just like the type of 1 and 2 and 3 is Integer. Bool and Integer are types. True, False, and 42 are all values. On Tue, Aug 29, 2017 at 11:04 AM, Shishir Srivastava wrote: > Just revisiting haskell after a hiatus and to begin that with a rather > uncalled for query - > > In the system type declaration for the data type Bool as below what are the > types of the two values 'True' and 'False' > > data Bool = False | True > > Are the values 'String' ? In which case how's the Bool data type different > from String enumerator data type ? > > Thanks, > S > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From mannyromero at mail.com Tue Aug 29 15:49:53 2017 From: mannyromero at mail.com (Manny Romero) Date: Tue, 29 Aug 2017 17:49:53 +0200 Subject: [Haskell-beginners] Multiline code in GHCi In-Reply-To: References: Message-ID: An HTML attachment was scrubbed... URL: From mannyromero at mail.com Tue Aug 29 15:51:11 2017 From: mannyromero at mail.com (Manny Romero) Date: Tue, 29 Aug 2017 17:51:11 +0200 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." Message-ID: An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Tue Aug 29 15:58:22 2017 From: aquagnu at gmail.com (Baa) Date: Tue, 29 Aug 2017 18:58:22 +0300 Subject: [Haskell-beginners] Is it possible to "run" JSON Parser? Message-ID: <20170829185822.54ee960d@Pavel> Hello List again! :) If I have a `FromJSON` instance, with `parseJSON` which translates `Value` to MyType, how can I run this parser like I "run" state/writer/reader monads? I mean not decoding of a bytestring representation: decode::ByteString -> Maybe MyType but run::Value -> Maybe MyType The reason is that I have already collected Value's , and I have parsers, so what is the problem, it would seem, to run parser on the Value - to convert `Value` into `Maybe MyType`... Is it possible? === Best regards, Paul From toad3k at gmail.com Tue Aug 29 16:01:00 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 12:01:00 -0400 Subject: [Haskell-beginners] Multiline code in GHCi In-Reply-To: References: Message-ID: Sorry, I should have kept reading. stack setup will most likely install ghc without a problem. Since stack doesn't appear to support your distro, if it doesn't it may be because you are missing some of those libraries it mentions. It looks like it is based on debian, so you would go apt-get install the various packages gcc, make, libffi, zlib, libgmp and libtinfo. If stack setup succeeds, then you stack install and after that, you should have files in /home/third/.local/bin, one of which is likely idris. Hopefully everything works okay for you! On Tue, Aug 29, 2017 at 11:49 AM, Manny Romero wrote: > Thanks! I don't have the slightest idea what any of this did, with the > exception of "cd Idris-dev", but it seems to have worked...up until I got > this message: > > Populated index cache. > No compiler found, expected minor version match with ghc-8.0.2 (x86_64) > (based on resolver setting in /home/third/Idris-dev/stack.yaml). > To install the correct GHC into /home/third/.stack/programs/x86_64-linux/, > try running "stack setup" or use the "--install-ghc" flag. > > ...additionally, I don't seem to have acquired a ~/.local/bin/idris ("no > such file or directory"), nor for that matter do I know how to adjust my > PATH. > > Also, for what it may be worth, I had been warned after the "curl -sSL > https://get.haskellstack.org/ | sh" that: > > Detected Linux distribution: linuxmint > This installer doesn't support your Linux distribution, trying generic > bindist... > Stack has been installed to: /usr/local/bin/stack > Since this installer doesn't support your Linux distribution, > there is no guarantee that 'stack' will work at all! You may > need to manually install some system info dependencies for GHC: > gcc, make, libffi, zlib, libgmp and libtinfo > Please see http://docs.haskellstack.org/en/stable/install_and_upgrade/ > Pull requests to add support for this distro would be welcome! > WARNING: '/home/third/.local/bin' is not on your PATH. > For best results, please add it to the beginning of PATH in your > profile. > > ...Sorry to be so completely clueless about the most basic aspects of what's > going on, but it really is the state of my knowledge for now! > > > ------------------------- > > Date: Tue, 29 Aug 2017 09:08:35 -0400 > From: David McBride > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Installing Idris for Linux Dummies: > "The following packages are likely to be broken..." > Message-ID: > > Content-Type: text/plain; charset="UTF-8" > > The problem most users face with using straight up cabal is that often > the needs of one package conflict with the needs of some of the others > you've installed. I highly recommend you use stack to install idris. > The process should look something like this: > > download stack, install it. (directions here: > https://docs.haskellstack.org/en/stable/README/) > git clone https://github.com/idris-lang/Idris-dev.git > cd idris-dev > stack install > > And then either run ~/.local/bin/idris or make sure .local/bin is in > your PATH so that you can run idris on the command line. > > On Tue, Aug 29, 2017 at 9:02 AM, Manny Romero wrote: >> I am a Linux user (Mint 18) trying to install Idris. I don't know the >> slightest thing about computers. I barely managed to install Linux, and >> later the full GHC, based on ample instructions available on the Web. >> (Still >> don't actually recall how I did it!) >> >> Idris, however, seems a little trickier. I followed the website >> (https://www.idris-lang.org/download/)'s instructions: >> >> cabal update >> cabal install idris >> >> ...because apparently I installed "cabal" at some point. But I get this >> message, which apparently is quite common: >> >> cabal: The following packages are likely to be broken by the reinstalls: >> semigroupoids-5.1 >> lens-4.15.1 >> kan-extensions-5.0.1 >> profunctors-5.2 >> comonad-5 >> bifunctors-5.4.1 >> Use --force-reinstalls if you want to install anyway. >> >> ...those are some of my favorite things! I can't live without them! I am >> reading things about creating a "sandbox" and so forth. But I cannot use >> or >> make sense of this information. I don't know the first thing about cabal; >> I >> never use it; I just load everything into GHCI all the time. >> >> Does anyone have some *specific* instructions that I can follow (as >> "rotely" >> and dumbly as possible) to get Idris downloaded so I can use it for some >> beginning studies, without breaking Haskell? >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > From timmelzer at gmail.com Tue Aug 29 16:17:31 2017 From: timmelzer at gmail.com (Norbert Melzer) Date: Tue, 29 Aug 2017 16:17:31 +0000 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." In-Reply-To: References: Message-ID: Manny Romero schrieb am Di., 29. Aug. 2017 um 15:03 Uhr: > I am a Linux user (Mint 18) trying to install Idris. I don't know the > slightest thing about computers. > Sorry I have to ask… But if you do not know anything about computers as you said, why do you want to install Idris? > I barely managed to install Linux, and later the full GHC, based on ample > instructions available on the Web. (Still don't actually recall how I did > it!) > Installing Linux (the mainstream distributions at least) is not different from installing windows… Insert CD, select language, select username, wait, be happy… I really do not want to hurt your feelings, but why are you wading through these things you do not understand? Can't you try something else which is just slightly out of your comfort zone? Or find someone in your area guiding you through everything? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mannyromero at mail.com Tue Aug 29 16:24:15 2017 From: mannyromero at mail.com (Manny Romero) Date: Tue, 29 Aug 2017 18:24:15 +0200 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." In-Reply-To: References: Message-ID: An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Aug 29 16:27:34 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 12:27:34 -0400 Subject: [Haskell-beginners] Is it possible to "run" JSON Parser? In-Reply-To: <20170829185822.54ee960d@Pavel> References: <20170829185822.54ee960d@Pavel> Message-ID: There are three ways to go about this. Method one, we could turn all the Values into Maybe MyTypes. Method two, we could filter out any Value which cannot be turned into an MyType. Method three, we could fail to parse entirely if any Value cannot be turned into a MyType succesfully. Here is some code that demonstrates all three approaches. import Data.Aeson import Data.Aeson.Types (Parser) import Control.Monad import qualified Data.Text as T import Data.Maybe (catMaybes) data Resp = Resp { rHeadings :: [T.Text], rows1 :: [Maybe MyType], rows2 :: [MyType], rows3 :: [MyType] } data MyType = MyType instance FromJSON Resp where parseJSON = withObject "Resp" $ \v -> do hds <- v .: "headings" -- we could catch all of mytypes as maybes r1 <- fmap f <$> v .: "rows" :: Parser [Maybe MyType] -- we could throw away values which can't be turned into MyType r2 <- catMaybes . fmap f <$> v .: "rows" :: Parser [MyType] -- we could fail the parse entirely if any value fails. r3 <- v .: "rows" >>= traverse f' pure $ Resp hds r1 r2 r3 f :: Value -> Maybe MyType f v = undefined f' :: Value -> Parser MyType f' (String t) = pure MyType f' (Bool t) = pure MyType f' (Number t) = pure MyType f' (Null) = pure MyType -- Anything that is not one of the above will cause a failure of the entire parse. f' _ = mzero On Tue, Aug 29, 2017 at 11:58 AM, Baa wrote: > Hello List again! :) > > If I have a `FromJSON` instance, with `parseJSON` which translates > `Value` to MyType, how can I run this parser like I "run" > state/writer/reader monads? I mean not decoding of a bytestring > representation: > > decode::ByteString -> Maybe MyType > > but > > run::Value -> Maybe MyType > > The reason is that I have already collected Value's , and I have > parsers, so what is the problem, it would seem, to run parser on the > Value - to convert `Value` into `Maybe MyType`... Is it possible? > > === > Best regards, Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From toad3k at gmail.com Tue Aug 29 16:31:28 2017 From: toad3k at gmail.com (David McBride) Date: Tue, 29 Aug 2017 12:31:28 -0400 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." In-Reply-To: References: Message-ID: You are very close. Try apt-get install zlib or possibly apt-get install zlib-dev. I'm also seeing a possible zlib-bin. This is all mint specific info, so I can't get any closer than that. You will not get a .local directory until you succesfully install a package via stack for the first time. On Tue, Aug 29, 2017 at 12:24 PM, Manny Romero wrote: > stack setup succeeded! But stack install got to 10/90 before: > > Process exited with code: ExitFailure 1 > Configuring digest-0.0.1.2... > Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2: Missing dependency on a > foreign > library: > * Missing (or bad) header file: zlib.h > * Missing C library: z > This problem can usually be solved by installing the system package that > provides this library (you may need the "-dev" version). If the library > is > already installed but in a non-standard location then you can use the > flags > --extra-include-dirs= and --extra-lib-dirs= to specify where it is. > If the header file does exist, it may contain errors that are caught by > the C > compiler at the preprocessing stage. In this case you can re-run > configure > with the verbosity flag -v3 to see the error messages. > > > ...Also, I don't seem to have a .local/bin. The only thing I see in .local > is a folder "share", which seems to have a bunch of things inside that came > with the Linux distribution (the file manager and so forth). I don't know > how or if this is related to the problem. > > Thanks again. This is really the only place I can think of that could give > me any hope of getting this installed. > Sent: Tuesday, August 29, 2017 at 12:01 PM > From: "David McBride" > To: "Manny Romero" > Cc: "Haskell Beginners" > Subject: Re: [Haskell-beginners] Multiline code in GHCi > Sorry, I should have kept reading. stack setup will most likely > install ghc without a problem. > > Since stack doesn't appear to support your distro, if it doesn't it > may be because you are missing some of those libraries it mentions. > It looks like it is based on debian, so you would go apt-get install > the various packages gcc, make, libffi, zlib, libgmp and > libtinfo. > > If stack setup succeeds, then you stack install and after that, you > should have files in /home/third/.local/bin, one of which is likely > idris. > > Hopefully everything works okay for you! > > > On Tue, Aug 29, 2017 at 11:49 AM, Manny Romero wrote: >> Thanks! I don't have the slightest idea what any of this did, with the >> exception of "cd Idris-dev", but it seems to have worked...up until I got >> this message: >> >> Populated index cache. >> No compiler found, expected minor version match with ghc-8.0.2 (x86_64) >> (based on resolver setting in /home/third/Idris-dev/stack.yaml). >> To install the correct GHC into /home/third/.stack/programs/x86_64-linux/, >> try running "stack setup" or use the "--install-ghc" flag. >> >> ...additionally, I don't seem to have acquired a ~/.local/bin/idris ("no >> such file or directory"), nor for that matter do I know how to adjust my >> PATH. >> >> Also, for what it may be worth, I had been warned after the "curl -sSL >> https://get.haskellstack.org/ | sh" that: >> >> Detected Linux distribution: linuxmint >> This installer doesn't support your Linux distribution, trying generic >> bindist... >> Stack has been installed to: /usr/local/bin/stack >> Since this installer doesn't support your Linux distribution, >> there is no guarantee that 'stack' will work at all! You may >> need to manually install some system info dependencies for GHC: >> gcc, make, libffi, zlib, libgmp and libtinfo >> Please see http://docs.haskellstack.org/en/stable/install_and_upgrade/ >> Pull requests to add support for this distro would be welcome! >> WARNING: '/home/third/.local/bin' is not on your PATH. >> For best results, please add it to the beginning of PATH in your >> profile. >> >> ...Sorry to be so completely clueless about the most basic aspects of >> what's >> going on, but it really is the state of my knowledge for now! >> >> >> ------------------------- >> >> Date: Tue, 29 Aug 2017 09:08:35 -0400 >> From: David McBride >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> Subject: Re: [Haskell-beginners] Installing Idris for Linux Dummies: >> "The following packages are likely to be broken..." >> Message-ID: >> >> Content-Type: text/plain; charset="UTF-8" >> >> The problem most users face with using straight up cabal is that often >> the needs of one package conflict with the needs of some of the others >> you've installed. I highly recommend you use stack to install idris. >> The process should look something like this: >> >> download stack, install it. (directions here: >> https://docs.haskellstack.org/en/stable/README/) >> git clone https://github.com/idris-lang/Idris-dev.git >> cd idris-dev >> stack install >> >> And then either run ~/.local/bin/idris or make sure .local/bin is in >> your PATH so that you can run idris on the command line. >> >> On Tue, Aug 29, 2017 at 9:02 AM, Manny Romero >> wrote: >>> I am a Linux user (Mint 18) trying to install Idris. I don't know the >>> slightest thing about computers. I barely managed to install Linux, and >>> later the full GHC, based on ample instructions available on the Web. >>> (Still >>> don't actually recall how I did it!) >>> >>> Idris, however, seems a little trickier. I followed the website >>> (https://www.idris-lang.org/download/)'s instructions: >>> >>> cabal update >>> cabal install idris >>> >>> ...because apparently I installed "cabal" at some point. But I get this >>> message, which apparently is quite common: >>> >>> cabal: The following packages are likely to be broken by the reinstalls: >>> semigroupoids-5.1 >>> lens-4.15.1 >>> kan-extensions-5.0.1 >>> profunctors-5.2 >>> comonad-5 >>> bifunctors-5.4.1 >>> Use --force-reinstalls if you want to install anyway. >>> >>> ...those are some of my favorite things! I can't live without them! I am >>> reading things about creating a "sandbox" and so forth. But I cannot use >>> or >>> make sense of this information. I don't know the first thing about cabal; >>> I >>> never use it; I just load everything into GHCI all the time. >>> >>> Does anyone have some *specific* instructions that I can follow (as >>> "rotely" >>> and dumbly as possible) to get Idris downloaded so I can use it for some >>> beginning studies, without breaking Haskell? >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> From mannyromero at mail.com Tue Aug 29 21:52:14 2017 From: mannyromero at mail.com (Manny Romero) Date: Tue, 29 Aug 2017 23:52:14 +0200 Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." In-Reply-To: References: Message-ID: An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Wed Aug 30 06:53:55 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 30 Aug 2017 09:53:55 +0300 Subject: [Haskell-beginners] Is it possible to "run" JSON Parser? In-Reply-To: References: <20170829185822.54ee960d@Pavel> Message-ID: <20170830095355.1e9a0076@Pavel> Thank you, David. 1st way seems to be most close to my task. But from your answers I see that actually no way to "run" Aeson Parser monad except with ByteString argument (even not a direct "run"), right? I check Aeson sources and IMHO no exporting functions to do it... Anyway, thank you again! > There are three ways to go about this. > > Method one, we could turn all the Values into Maybe MyTypes. > Method two, we could filter out any Value which cannot be turned into > an MyType. Method three, we could fail to parse entirely if any Value > cannot be turned into a MyType succesfully. > > Here is some code that demonstrates all three approaches. > > import Data.Aeson > import Data.Aeson.Types (Parser) > import Control.Monad > import qualified Data.Text as T > import Data.Maybe (catMaybes) > > data Resp = Resp { > rHeadings :: [T.Text], > rows1 :: [Maybe MyType], > rows2 :: [MyType], > rows3 :: [MyType] > } > > data MyType = MyType > > instance FromJSON Resp where > parseJSON = withObject "Resp" $ \v -> do > hds <- v .: "headings" > > > -- we could catch all of mytypes as maybes > r1 <- fmap f <$> v .: "rows" :: Parser [Maybe MyType] > > -- we could throw away values which can't be turned into MyType > r2 <- catMaybes . fmap f <$> v .: "rows" :: Parser [MyType] > > -- we could fail the parse entirely if any value fails. > r3 <- v .: "rows" >>= traverse f' > pure $ Resp hds r1 r2 r3 > > f :: Value -> Maybe MyType > f v = undefined > > f' :: Value -> Parser MyType > f' (String t) = pure MyType > f' (Bool t) = pure MyType > f' (Number t) = pure MyType > f' (Null) = pure MyType > -- Anything that is not one of the above will cause a failure of the > entire parse. > f' _ = mzero > > On Tue, Aug 29, 2017 at 11:58 AM, Baa wrote: > > Hello List again! :) > > > > If I have a `FromJSON` instance, with `parseJSON` which translates > > `Value` to MyType, how can I run this parser like I "run" > > state/writer/reader monads? I mean not decoding of a bytestring > > representation: > > > > decode::ByteString -> Maybe MyType > > > > but > > > > run::Value -> Maybe MyType > > > > The reason is that I have already collected Value's , and I have > > parsers, so what is the problem, it would seem, to run parser on the > > Value - to convert `Value` into `Maybe MyType`... Is it possible? > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Wed Aug 30 07:30:45 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 30 Aug 2017 10:30:45 +0300 Subject: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question Message-ID: <20170830103045.528468d0@Pavel> Hello, List! There is a library https://hackage.haskell.org/package/path-0.6.1 of Chris Done from FPCOMPLETE. `Path` - to be safe - can be constructed only with parsing (with TH or directly). OK. But the `Path` has different representation on Windows and POSIX which seems that no way to use both on the same platform (source of path can be network peer which has another platform). Does anyone use this library and if does - how do you workaround this? === Best regards, Paul From gale at sefer.org Wed Aug 30 10:27:55 2017 From: gale at sefer.org (Yitzchak Gale) Date: Wed, 30 Aug 2017 13:27:55 +0300 Subject: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question In-Reply-To: <20170830103045.528468d0@Pavel> References: <20170830103045.528468d0@Pavel> Message-ID: Hi Paul, You wrote: > [In the path library] the `Path` has different representation > on Windows and POSIX which seems that no way > to use both on the same platform You are right, the path library does not yet support that. This issue will fix it: https://github.com/commercialhaskell/path/issues/82 In the meantime, use the standard filepath library, which supports paths from other platforms. Regards, Yitz From aquagnu at gmail.com Wed Aug 30 10:46:54 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 30 Aug 2017 13:46:54 +0300 Subject: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question In-Reply-To: References: <20170830103045.528468d0@Pavel> Message-ID: <20170830134654.5f773747@Pavel> Hmm, OK. Thank you, Yitzchak! IMHO it will be good to have like in Python: all kind of paths (NT, POSIX, etc) available as well as local path (local platform dependent)... > Hi Paul, > > You wrote: > > [In the path library] the `Path` has different representation > > on Windows and POSIX which seems that no way > > to use both on the same platform > > You are right, the path library does not yet support that. > This issue will fix it: > > https://github.com/commercialhaskell/path/issues/82 > > In the meantime, use the standard filepath library, which > supports paths from other platforms. > > Regards, > Yitz > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From gale at sefer.org Wed Aug 30 15:48:03 2017 From: gale at sefer.org (Yitzchak Gale) Date: Wed, 30 Aug 2017 18:48:03 +0300 Subject: [Haskell-beginners] Fwd: Path {Abs|Rel} {Dir|File} type question In-Reply-To: References: <20170830103045.528468d0@Pavel> <20170830134654.5f773747@Pavel> Message-ID: You wrote: >>> [In the path library] the `Path` has different representation >>> on Windows and POSIX which seems that no way >>> to use both on the same platform > IMHO it will be good to have like in Python: all kind of paths (NT, > POSIX, etc) available as well as local path (local platform > dependent)... Why like in Python? You mean like in Haskell. The standard and popular "filepath" library in Haskell does all that very nicely. The "path" library you are looking at is a newer library that wraps "filepath" and provides more type safety. It looks very nice. I hope the issue with multiplatform paths will soon be fixed, and then perhaps the path library will become more widely used. In the meantime, I suggest you use the "filepath" library. Regards, Yitz