From aquagnu at gmail.com Thu Nov 2 13:41:21 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 15:41:21 +0200 Subject: [Haskell-beginners] How to write Read instance Message-ID: <20171102154121.6535e6ac@Pavel> Hello all! I found some errors in the reading of previously shown big and complex record. Reason is: some of fields are reading wrongly. So, is there any useful documents how to write `Read` instance correctly (because I can't find good tutorial in the Web and often hit errors with `Read` instance)? May be tutorial/examples/any good info... === Best regards, Paul From toad3k at gmail.com Thu Nov 2 14:27:12 2017 From: toad3k at gmail.com (David McBride) Date: Thu, 2 Nov 2017 10:27:12 -0400 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: <20171102154121.6535e6ac@Pavel> References: <20171102154121.6535e6ac@Pavel> Message-ID: The most common way is to just auto derive Read. I'm not sure that that ever really fails. Are you sure the problem isn't with the Show instance of the type? People commonly write invalid Show instances to make them look pretty and they shouldn't. read and show are supposed to be inverses of each other because when they aren't, problems like this occur. The simple way to do a Read instance is to implement the reads function for it. The confusion comes from its type. readsPrec :: Int -> ReadS a. ReadS is defined as String -> [(a, String)], where a is the parsed result and String is the rest of the string that is being parsed, , which may look confusing, and the Int is precedence, which can usually be ignored. It could have been Int -> String -> Maybe (a, String), but Read predates Maybe. So instead it returns a list and if it fails to parse, it returns [] instead of Nothing. So. data MyFoo = MyFoo instance Read MyFoo where -- readsPrec :: Int -> String -> [(MyFoo, String)] readsPrec _ = readFoo readFoo :: String -> [(MyFoo, String)] readFoo str = case splitAt 5 str of ("MyFoo", rest) -> [(MyFoo, rest)] otherwise -> [] If you need something more complex, there are functions to do it in base that perform lexing and parsing. I have never used them but you can go ahead and read some of the instances such as Ordering at https://hackage.haskell.org/package/base-4.10.0.0/docs/src/GHC.Read.html#line-398 to try and learn how it might work for you. But honestly I think you should look at fixing your Show instance first, if possible. On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > Hello all! > > I found some errors in the reading of previously shown big and > complex record. Reason is: some of fields are reading wrongly. So, is > there any useful documents how to write `Read` instance correctly > (because I can't find good tutorial in the Web and often hit errors > with `Read` instance)? May be tutorial/examples/any good info... > > > === > 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 Nov 2 14:51:06 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 16:51:06 +0200 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: References: <20171102154121.6535e6ac@Pavel> Message-ID: <20171102165106.4f61f6f0@Pavel> Hello, David! `Show` instance is simple: instance Show Hex where show = T.unpack . ghValue so > show (Hex "1234ab") 1234ab > read "1234ab"::Hex 1234ab > read "Just 1234ab"::Maybe Hex -- fails like wrapped in the record!! Yes, I'm ignoring precedence usually too. And I return rest of the string. Playing with `UTCTime`'s readsPrec shows me that behaviour looks the same: UTCTime's reader returns the same rest. So, may be trick is in the: 1. Precedence ?! 2. readListPrec = readListPrecDefault readList = readListDefault ? But I get error: readListPrec is not visible method of class Read... 3. readPrec ? I implemented readsPrec which is old-style, but am I right that old-style and new-style are absolutely the same from reading point of view and old-style can replace new-style and vice versa? PS. I don't import any special modules. > The most common way is to just auto derive Read. I'm not sure that > that ever really fails. Are you sure the problem isn't with the Show > instance of the type? People commonly write invalid Show instances > to make them look pretty and they shouldn't. read and show are > supposed to be inverses of each other because when they aren't, > problems like this occur. > > The simple way to do a Read instance is to implement the reads > function for it. The confusion comes from its type. readsPrec :: > Int -> ReadS a. ReadS is defined as String -> [(a, String)], where a > is the parsed result and String is the rest of the string that is > being parsed, , which may look confusing, and the Int is precedence, > which can usually be ignored. It could have been Int -> String -> > Maybe (a, String), but Read predates Maybe. So instead it returns a > list and if it fails to parse, it returns [] instead of Nothing. So. > > data MyFoo = MyFoo > > instance Read MyFoo where > -- readsPrec :: Int -> String -> [(MyFoo, String)] > readsPrec _ = readFoo > > readFoo :: String -> [(MyFoo, String)] > readFoo str = case splitAt 5 str of > ("MyFoo", rest) -> [(MyFoo, rest)] > otherwise -> [] > > If you need something more complex, there are functions to do it in > base that perform lexing and parsing. I have never used them but you > can go ahead and read some of the instances such as Ordering at > https://hackage.haskell.org/package/base-4.10.0.0/docs/src/GHC.Read.html#line-398 > to try and learn how it might work for you. > > But honestly I think you should look at fixing your Show instance > first, if possible. > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > Hello all! > > > > I found some errors in the reading of previously shown big and > > complex record. Reason is: some of fields are reading wrongly. So, > > is there any useful documents how to write `Read` instance correctly > > (because I can't find good tutorial in the Web and often hit errors > > with `Read` instance)? May be tutorial/examples/any good info... > > > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From toad3k at gmail.com Thu Nov 2 15:05:37 2017 From: toad3k at gmail.com (David McBride) Date: Thu, 2 Nov 2017 11:05:37 -0400 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: <20171102165106.4f61f6f0@Pavel> References: <20171102154121.6535e6ac@Pavel> <20171102165106.4f61f6f0@Pavel> Message-ID: My own toy example works. I don't know how yours differs. On Thu, Nov 2, 2017 at 10:51 AM, Baa wrote: > Hello, David! > > `Show` instance is simple: > > instance Show Hex where > show = T.unpack . ghValue > > so > > > show (Hex "1234ab") > 1234ab > > read "1234ab"::Hex > 1234ab > > read "Just 1234ab"::Maybe Hex -- fails like wrapped in the record!! > > Yes, I'm ignoring precedence usually too. And I return rest of the > string. Playing with `UTCTime`'s readsPrec shows me that behaviour > looks the same: UTCTime's reader returns the same rest. So, may be > trick is in the: > > 1. Precedence ?! > 2. readListPrec = readListPrecDefault > readList = readListDefault ? > > But I get error: readListPrec is not visible method of class Read... > 3. readPrec ? I implemented readsPrec which is old-style, but am I > right that old-style and new-style are absolutely the same from > reading point of view and old-style can replace new-style and vice > versa? > > PS. I don't import any special modules. > > > > The most common way is to just auto derive Read. I'm not sure that > > that ever really fails. Are you sure the problem isn't with the Show > > instance of the type? People commonly write invalid Show instances > > to make them look pretty and they shouldn't. read and show are > > supposed to be inverses of each other because when they aren't, > > problems like this occur. > > > > The simple way to do a Read instance is to implement the reads > > function for it. The confusion comes from its type. readsPrec :: > > Int -> ReadS a. ReadS is defined as String -> [(a, String)], where a > > is the parsed result and String is the rest of the string that is > > being parsed, , which may look confusing, and the Int is precedence, > > which can usually be ignored. It could have been Int -> String -> > > Maybe (a, String), but Read predates Maybe. So instead it returns a > > list and if it fails to parse, it returns [] instead of Nothing. So. > > > > data MyFoo = MyFoo > > > > instance Read MyFoo where > > -- readsPrec :: Int -> String -> [(MyFoo, String)] > > readsPrec _ = readFoo > > > > readFoo :: String -> [(MyFoo, String)] > > readFoo str = case splitAt 5 str of > > ("MyFoo", rest) -> [(MyFoo, rest)] > > otherwise -> [] > > > > If you need something more complex, there are functions to do it in > > base that perform lexing and parsing. I have never used them but you > > can go ahead and read some of the instances such as Ordering at > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > src/GHC.Read.html#line-398 > > to try and learn how it might work for you. > > > > But honestly I think you should look at fixing your Show instance > > first, if possible. > > > > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > > > Hello all! > > > > > > I found some errors in the reading of previously shown big and > > > complex record. Reason is: some of fields are reading wrongly. So, > > > is there any useful documents how to write `Read` instance correctly > > > (because I can't find good tutorial in the Web and often hit errors > > > with `Read` instance)? May be tutorial/examples/any good info... > > > > > > > > > === > > > 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 Thu Nov 2 15:13:43 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 17:13:43 +0200 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: References: <20171102154121.6535e6ac@Pavel> <20171102165106.4f61f6f0@Pavel> Message-ID: <20171102171343.76a1c322@Pavel> Does it work with wrapping in records, in "Just" ? Would you show this example, please? I try this: import qualified Data.Text as T import GHC.Read import qualified Data.Char as C newtype GitHash = GitHash { ghValue :: T.Text } deriving (Eq, Ord, Generic) instance Show GitHash where show = T.unpack . ghValue instance Read GitHash where readsPrec p = readParen (p > 10) reader where reader :: ReadS GitHash reader s = case span C.isHexDigit s of ([], _) -> [] (hex, nohex) -> [(GitHash $ T.pack hex, nohex)] readListPrec = readListPrecDefault readList = readListDefault and this parses: > read "1234ab"::GitHash but not this: > read "Just 1234"::Maybe GitHash *** Exception: Prelude.read: no parse > My own toy example works. I don't know how yours differs. > > On Thu, Nov 2, 2017 at 10:51 AM, Baa wrote: > > > Hello, David! > > > > `Show` instance is simple: > > > > instance Show Hex where > > show = T.unpack . ghValue > > > > so > > > > > show (Hex "1234ab") > > 1234ab > > > read "1234ab"::Hex > > 1234ab > > > read "Just 1234ab"::Maybe Hex -- fails like wrapped in the > > > record!! > > > > Yes, I'm ignoring precedence usually too. And I return rest of the > > string. Playing with `UTCTime`'s readsPrec shows me that behaviour > > looks the same: UTCTime's reader returns the same rest. So, may be > > trick is in the: > > > > 1. Precedence ?! > > 2. readListPrec = readListPrecDefault > > readList = readListDefault ? > > > > But I get error: readListPrec is not visible method of class > > Read... 3. readPrec ? I implemented readsPrec which is old-style, > > but am I right that old-style and new-style are absolutely the same > > from reading point of view and old-style can replace new-style and > > vice versa? > > > > PS. I don't import any special modules. > > > > > > > The most common way is to just auto derive Read. I'm not sure > > > that that ever really fails. Are you sure the problem isn't with > > > the Show instance of the type? People commonly write invalid > > > Show instances to make them look pretty and they shouldn't. read > > > and show are supposed to be inverses of each other because when > > > they aren't, problems like this occur. > > > > > > The simple way to do a Read instance is to implement the reads > > > function for it. The confusion comes from its type. readsPrec :: > > > Int -> ReadS a. ReadS is defined as String -> [(a, String)], > > > where a is the parsed result and String is the rest of the string > > > that is being parsed, , which may look confusing, and the Int is > > > precedence, which can usually be ignored. It could have been Int > > > -> String -> Maybe (a, String), but Read predates Maybe. So > > > instead it returns a list and if it fails to parse, it returns [] > > > instead of Nothing. So. > > > > > > data MyFoo = MyFoo > > > > > > instance Read MyFoo where > > > -- readsPrec :: Int -> String -> [(MyFoo, String)] > > > readsPrec _ = readFoo > > > > > > readFoo :: String -> [(MyFoo, String)] > > > readFoo str = case splitAt 5 str of > > > ("MyFoo", rest) -> [(MyFoo, rest)] > > > otherwise -> [] > > > > > > If you need something more complex, there are functions to do it > > > in base that perform lexing and parsing. I have never used them > > > but you can go ahead and read some of the instances such as > > > Ordering at > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > src/GHC.Read.html#line-398 > > > to try and learn how it might work for you. > > > > > > But honestly I think you should look at fixing your Show instance > > > first, if possible. > > > > > > > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > > > > > Hello all! > > > > > > > > I found some errors in the reading of previously shown big and > > > > complex record. Reason is: some of fields are reading wrongly. > > > > So, is there any useful documents how to write `Read` instance > > > > correctly (because I can't find good tutorial in the Web and > > > > often hit errors with `Read` instance)? May be > > > > tutorial/examples/any good info... > > > > > > > > > > > > === > > > > 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 Thu Nov 2 15:17:09 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 17:17:09 +0200 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: References: <20171102154121.6535e6ac@Pavel> Message-ID: <20171102171709.597c46b5@Pavel> Hmm, difference is that your example with "Foo" uses fixed (ident) lexem. But when you need to return rest of the string which is not part of your type - this leads to problem for me... > The most common way is to just auto derive Read. I'm not sure that > that ever really fails. Are you sure the problem isn't with the Show > instance of the type? People commonly write invalid Show instances > to make them look pretty and they shouldn't. read and show are > supposed to be inverses of each other because when they aren't, > problems like this occur. > > The simple way to do a Read instance is to implement the reads > function for it. The confusion comes from its type. readsPrec :: > Int -> ReadS a. ReadS is defined as String -> [(a, String)], where a > is the parsed result and String is the rest of the string that is > being parsed, , which may look confusing, and the Int is precedence, > which can usually be ignored. It could have been Int -> String -> > Maybe (a, String), but Read predates Maybe. So instead it returns a > list and if it fails to parse, it returns [] instead of Nothing. So. > > data MyFoo = MyFoo > > instance Read MyFoo where > -- readsPrec :: Int -> String -> [(MyFoo, String)] > readsPrec _ = readFoo > > readFoo :: String -> [(MyFoo, String)] > readFoo str = case splitAt 5 str of > ("MyFoo", rest) -> [(MyFoo, rest)] > otherwise -> [] > > If you need something more complex, there are functions to do it in > base that perform lexing and parsing. I have never used them but you > can go ahead and read some of the instances such as Ordering at > https://hackage.haskell.org/package/base-4.10.0.0/docs/src/GHC.Read.html#line-398 > to try and learn how it might work for you. > > But honestly I think you should look at fixing your Show instance > first, if possible. > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > Hello all! > > > > I found some errors in the reading of previously shown big and > > complex record. Reason is: some of fields are reading wrongly. So, > > is there any useful documents how to write `Read` instance correctly > > (because I can't find good tutorial in the Web and often hit errors > > with `Read` instance)? May be tutorial/examples/any good info... > > > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From aquagnu at gmail.com Thu Nov 2 15:27:53 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 17:27:53 +0200 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: References: <20171102154121.6535e6ac@Pavel> <20171102165106.4f61f6f0@Pavel> Message-ID: <20171102172753.56a426f4@Pavel> David, it's very strange! My snippet works with "Just" and wrapping in a record too, but only if I surround hex-number with ( and ): "D {d = (123abc)}" or "Just (123abc)" If I remove call of `readParen` then it can parse strings like: "D {d = 123abc}" but can not like "Just 123abc" > My own toy example works. I don't know how yours differs. > > On Thu, Nov 2, 2017 at 10:51 AM, Baa wrote: > > > Hello, David! > > > > `Show` instance is simple: > > > > instance Show Hex where > > show = T.unpack . ghValue > > > > so > > > > > show (Hex "1234ab") > > 1234ab > > > read "1234ab"::Hex > > 1234ab > > > read "Just 1234ab"::Maybe Hex -- fails like wrapped in the > > > record!! > > > > Yes, I'm ignoring precedence usually too. And I return rest of the > > string. Playing with `UTCTime`'s readsPrec shows me that behaviour > > looks the same: UTCTime's reader returns the same rest. So, may be > > trick is in the: > > > > 1. Precedence ?! > > 2. readListPrec = readListPrecDefault > > readList = readListDefault ? > > > > But I get error: readListPrec is not visible method of class > > Read... 3. readPrec ? I implemented readsPrec which is old-style, > > but am I right that old-style and new-style are absolutely the same > > from reading point of view and old-style can replace new-style and > > vice versa? > > > > PS. I don't import any special modules. > > > > > > > The most common way is to just auto derive Read. I'm not sure > > > that that ever really fails. Are you sure the problem isn't with > > > the Show instance of the type? People commonly write invalid > > > Show instances to make them look pretty and they shouldn't. read > > > and show are supposed to be inverses of each other because when > > > they aren't, problems like this occur. > > > > > > The simple way to do a Read instance is to implement the reads > > > function for it. The confusion comes from its type. readsPrec :: > > > Int -> ReadS a. ReadS is defined as String -> [(a, String)], > > > where a is the parsed result and String is the rest of the string > > > that is being parsed, , which may look confusing, and the Int is > > > precedence, which can usually be ignored. It could have been Int > > > -> String -> Maybe (a, String), but Read predates Maybe. So > > > instead it returns a list and if it fails to parse, it returns [] > > > instead of Nothing. So. > > > > > > data MyFoo = MyFoo > > > > > > instance Read MyFoo where > > > -- readsPrec :: Int -> String -> [(MyFoo, String)] > > > readsPrec _ = readFoo > > > > > > readFoo :: String -> [(MyFoo, String)] > > > readFoo str = case splitAt 5 str of > > > ("MyFoo", rest) -> [(MyFoo, rest)] > > > otherwise -> [] > > > > > > If you need something more complex, there are functions to do it > > > in base that perform lexing and parsing. I have never used them > > > but you can go ahead and read some of the instances such as > > > Ordering at > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > src/GHC.Read.html#line-398 > > > to try and learn how it might work for you. > > > > > > But honestly I think you should look at fixing your Show instance > > > first, if possible. > > > > > > > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > > > > > Hello all! > > > > > > > > I found some errors in the reading of previously shown big and > > > > complex record. Reason is: some of fields are reading wrongly. > > > > So, is there any useful documents how to write `Read` instance > > > > correctly (because I can't find good tutorial in the Web and > > > > often hit errors with `Read` instance)? May be > > > > tutorial/examples/any good info... > > > > > > > > > > > > === > > > > 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 Thu Nov 2 16:45:37 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 2 Nov 2017 18:45:37 +0200 Subject: [Haskell-beginners] How to write Read instance In-Reply-To: References: <20171102154121.6535e6ac@Pavel> <20171102165106.4f61f6f0@Pavel> Message-ID: <20171102184537.7d5c1006@Pavel> David, your experience and intuition were absolutely right: solution is in the right Show and Read pair. So, this seems to work in all cases: import qualified Text.ParserCombinators.ReadP as P import Text.ParserCombinators.ReadPrec (lift) import qualified Data.Char as C -- |Type of Git hashes newtype GitHash = GitHash { ghValue :: T.Text } deriving (Eq, Ord, Generic) instance Show GitHash where showsPrec p a = showParen (p > 10) (showString $ T.unpack $ ghValue a) hexDigits :: P.ReadP String hexDigits = P.munch1 C.isHexDigit instance Read GitHash where readPrec = parens $ do lift P.skipSpaces s::String <- lift hexDigits return $ GitHash $ T.pack s Thanks a lot again!! > My own toy example works. I don't know how yours differs. > > On Thu, Nov 2, 2017 at 10:51 AM, Baa wrote: > > > Hello, David! > > > > `Show` instance is simple: > > > > instance Show Hex where > > show = T.unpack . ghValue > > > > so > > > > > show (Hex "1234ab") > > 1234ab > > > read "1234ab"::Hex > > 1234ab > > > read "Just 1234ab"::Maybe Hex -- fails like wrapped in the > > > record!! > > > > Yes, I'm ignoring precedence usually too. And I return rest of the > > string. Playing with `UTCTime`'s readsPrec shows me that behaviour > > looks the same: UTCTime's reader returns the same rest. So, may be > > trick is in the: > > > > 1. Precedence ?! > > 2. readListPrec = readListPrecDefault > > readList = readListDefault ? > > > > But I get error: readListPrec is not visible method of class > > Read... 3. readPrec ? I implemented readsPrec which is old-style, > > but am I right that old-style and new-style are absolutely the same > > from reading point of view and old-style can replace new-style and > > vice versa? > > > > PS. I don't import any special modules. > > > > > > > The most common way is to just auto derive Read. I'm not sure > > > that that ever really fails. Are you sure the problem isn't with > > > the Show instance of the type? People commonly write invalid > > > Show instances to make them look pretty and they shouldn't. read > > > and show are supposed to be inverses of each other because when > > > they aren't, problems like this occur. > > > > > > The simple way to do a Read instance is to implement the reads > > > function for it. The confusion comes from its type. readsPrec :: > > > Int -> ReadS a. ReadS is defined as String -> [(a, String)], > > > where a is the parsed result and String is the rest of the string > > > that is being parsed, , which may look confusing, and the Int is > > > precedence, which can usually be ignored. It could have been Int > > > -> String -> Maybe (a, String), but Read predates Maybe. So > > > instead it returns a list and if it fails to parse, it returns [] > > > instead of Nothing. So. > > > > > > data MyFoo = MyFoo > > > > > > instance Read MyFoo where > > > -- readsPrec :: Int -> String -> [(MyFoo, String)] > > > readsPrec _ = readFoo > > > > > > readFoo :: String -> [(MyFoo, String)] > > > readFoo str = case splitAt 5 str of > > > ("MyFoo", rest) -> [(MyFoo, rest)] > > > otherwise -> [] > > > > > > If you need something more complex, there are functions to do it > > > in base that perform lexing and parsing. I have never used them > > > but you can go ahead and read some of the instances such as > > > Ordering at > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > src/GHC.Read.html#line-398 > > > to try and learn how it might work for you. > > > > > > But honestly I think you should look at fixing your Show instance > > > first, if possible. > > > > > > > > > On Thu, Nov 2, 2017 at 9:41 AM, Baa wrote: > > > > > > > Hello all! > > > > > > > > I found some errors in the reading of previously shown big and > > > > complex record. Reason is: some of fields are reading wrongly. > > > > So, is there any useful documents how to write `Read` instance > > > > correctly (because I can't find good tutorial in the Web and > > > > often hit errors with `Read` instance)? May be > > > > tutorial/examples/any good info... > > > > > > > > > > > > === > > > > 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 Fri Nov 3 11:43:40 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 3 Nov 2017 13:43:40 +0200 Subject: [Haskell-beginners] Problem with Parser combinators Message-ID: <20171103134340.58a7b386@Pavel> Hello, all! I try this parser for `Read` instance: import qualified Text.ParserCombinators.ReadP as P import qualified Text.ParserCombinators.ReadPrec as RP import Data.Text as T instance Read RV where readPrec = parens $ do RP.lift P.skipSpaces s <- RP.look guard (not $ null s) (RP.+++) (RV1 <$> readPrec::RP.ReadPrec RV) (pure $ RV2 $ T.pack s) And see that `+++` (or <|>) works in strange way (I don't understand what happens). IMHO if first parser fails (i.e. `RV1 <$> readPrec::RP.ReadPrec RV`) then second should return `RV2 $ T.pack s`). But seems that if 1st fails then all fail too! I tried `+++`, `<++`, `<|>` - the same result. How is it possible?! I need to return something if parsing fails. Best is to return another parser but initial problem was that alternative parser must return the same type as first one. So, I decided to return "constant" - here it is `RV2 $ T.pack s`. Guarding from empty string is needed for this alternative value which I'll return when 1st parser fails. But... seems something is wrong. === Best regards, Paul From iconsize at gmail.com Sun Nov 5 17:51:57 2017 From: iconsize at gmail.com (Marcus Manning) Date: Sun, 5 Nov 2017 18:51:57 +0100 Subject: [Haskell-beginners] Could not get parser ready Message-ID: Hello, I follow the instructions of script [1] in order to set up a parser functionality. But I' get into problems at page 202 with the code: p :: Parser (Char,Char) p = do              x ← item              item              y ← item              return (x,y) ghci and ghc throw errors: Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; return (x,y)} :10:65: error:     • Couldn't match type ‘[(Char, String)]’ with ‘Char’       Expected type: String -> [((Char, Char), String)]         Actual type: Parser ([(Char, String)], [(Char, String)])     • In a stmt of a 'do' block: return (x, y)       In the expression:         do x <- item            item            y <- item            return (x, y)       In an equation for ‘p’:           p = do x <- item                  item                  y <- item                  .... Did the semantics of do expr changed? [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf Cheers, iconfly. From fa-ml at ariis.it Sun Nov 5 20:45:45 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 5 Nov 2017 21:45:45 +0100 Subject: [Haskell-beginners] Could not get parser ready In-Reply-To: References: Message-ID: <20171105204545.awdviuimn4ppa6mc@x60s.casa> On Sun, Nov 05, 2017 at 06:51:57PM +0100, Marcus Manning wrote: > Hello, > > I follow the instructions of script [1] in order to set up a parser > functionality. But I' get into problems at page 202 with the code: > > p :: Parser (Char,Char) > p = do >              x ← item >              item >              y ← item >              return (x,y) > > > ghci and ghc throw errors: > Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; > return (x,y)} Hello Marcus, what is the :type of `item`? From to_br at uni-bremen.de Sun Nov 5 20:56:02 2017 From: to_br at uni-bremen.de (Tobias Brandt) Date: Sun, 05 Nov 2017 21:56:02 +0100 Subject: [Haskell-beginners] Could not get parser ready In-Reply-To: Message-ID: <20171105215602.Horde.ImSW87F6UDtqhG4r3-E7k8R@webmail.uni-bremen.de> Hey, can you show us your Parser definition?  Cheers, Tobias  ----- Nachricht von Marcus Manning ---------      Datum: Sun, 5 Nov 2017 18:51:57 +0100        Von: Marcus Manning Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell    Betreff: [Haskell-beginners] Could not get parser ready         An: beginners at haskell.org > Hello, > > I follow the instructions of script [1] in order to set up a parser > functionality. But I' get into problems at page 202 with the code: > > p :: Parser (Char,Char) > p = do >              x ← item >              item >              y ← item >              return (x,y) > > ghci and ghc throw errors: > Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- > item; return (x,y)} > > :10:65: error: >     • Couldn't match type ‘[(Char, String)]’ with ‘Char’ >       Expected type: String -> [((Char, Char), String)] >         Actual type: Parser ([(Char, String)], [(Char, String)]) >     • In a stmt of a 'do' block: return (x, y) >       In the expression: >         do x <- item >            item >            y <- item >            return (x, y) >       In an equation for ‘p’: >           p = do x <- item >                  item >                  y <- item >                  .... > Did the semantics of do expr changed? > > [1] > https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf > > Cheers, > > iconfly. > _______________________________________________ > Beginners mailing list > Beginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ----- Ende der Nachricht von Marcus Manning ----- -------------- next part -------------- An HTML attachment was scrubbed... URL: From iconsize at gmail.com Mon Nov 6 08:15:58 2017 From: iconsize at gmail.com (Marcus Manning) Date: Mon, 6 Nov 2017 09:15:58 +0100 Subject: [Haskell-beginners] Could not get parser ready In-Reply-To: <20171105215602.Horde.ImSW87F6UDtqhG4r3-E7k8R@webmail.uni-bremen.de> References: <20171105215602.Horde.ImSW87F6UDtqhG4r3-E7k8R@webmail.uni-bremen.de> Message-ID: type Parser a = String → [(a,String)] item :: Parser Char item = λinp → case inp of [] → [] (x:xs) → [(x,xs)] failure :: Parser a failure = λinp → [] return :: a → Parser a return v = λinp → [(v,inp)] (+++) :: Parser a → Parser a → Parser a p +++ q = λinp → case p inp of [] → q inp [(v,out)] → [(v,out)] parse :: Parser a → String → [(a,String)] parse p inp = p inp p :: Parser (Char,Char) p = do x ← item item y ← item return (x,y) It is described in pages 189-216 in [1]. [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf I assume the bind operator (==>) was overwritten by (>>=) :: Parser a → (a → Parser b) → Parser b p >>= f = λinp → case parse p inp of [ ] → [ ] [ (v, out) ] → parse (f v) out in order to manipulate the do expr to make the p function work, right? 2017-11-05 21:56 GMT+01:00 Tobias Brandt : > Hey, > > can you show us your Parser definition? > > Cheers, > Tobias > > ----- Nachricht von Marcus Manning --------- > Datum: Sun, 5 Nov 2017 18:51:57 +0100 > Von: Marcus Manning > Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Betreff: [Haskell-beginners] Could not get parser ready > An: beginners at haskell.org > > Hello, > > I follow the instructions of script [1] in order to set up a parser > functionality. But I' get into problems at page 202 with the code: > > p :: Parser (Char,Char) > p = do > x ← item > item > y ← item > return (x,y) > > > ghci and ghc throw errors: > Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; > return (x,y)} > > :10:65: error: > • Couldn't match type ‘[(Char, String)]’ with ‘Char’ > Expected type: String -> [((Char, Char), String)] > Actual type: Parser ([(Char, String)], [(Char, String)]) > • In a stmt of a 'do' block: return (x, y) > In the expression: > do x <- item > item > y <- item > return (x, y) > In an equation for ‘p’: > p = do x <- item > item > y <- item > .... > Did the semantics of do expr changed? > > [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/ > resources/pdf/haskell.pdf > > Cheers, > > iconfly. > _______________________________________________ > Beginners mailing list > Beginners at haskell.orghttp://mail.haskell.org/cgi-bin/ > mailman/listinfo/beginners > > > > > ----- Ende der Nachricht von Marcus Manning ----- > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Nov 6 13:29:38 2017 From: toad3k at gmail.com (David McBride) Date: Mon, 6 Nov 2017 08:29:38 -0500 Subject: [Haskell-beginners] Could not get parser ready In-Reply-To: References: <20171105215602.Horde.ImSW87F6UDtqhG4r3-E7k8R@webmail.uni-bremen.de> Message-ID: The problem is that in p you are using do notation for bind, which uses the Monad instance for bind (>>=) for ((->) String), because Parser is a type alias for (String -> [(a, String)]. But then you are using your own return which is not of the same type as Monad's return would be. The way you have it now your return considers the loose `a` as the Monad parameter, but do notation considers it [(a, String)] instead. You can either a) write your own bind that conforms to your type. bind :: Parser a -> (a -> Parser b) -> Parser b bind = undefined p' :: Parser (Char, Char) p' = item `bind` \x -> item `bind` \_ -> item `bind` \y -> Foo.return (x, y) Or you can use the Monad return instead. But the type is not what you expect. p :: String -> ([(Char, String)], [(Char, String)]) p = do x <- item item y <- item Prelude.return (x,y) On Mon, Nov 6, 2017 at 3:15 AM, Marcus Manning wrote: > type Parser a = String → [(a,String)] > > item :: Parser Char > item = λinp → case inp of > [] → [] > (x:xs) → [(x,xs)] > failure :: Parser a > failure = λinp → [] > > return :: a → Parser a > return v = λinp → [(v,inp)] > > (+++) :: Parser a → Parser a → Parser a > p +++ q = λinp → case p inp of > [] → q inp > [(v,out)] → [(v,out)] > > parse :: Parser a → String → [(a,String)] > parse p inp = p inp > > p :: Parser (Char,Char) > p = do x ← item > item > y ← item > return (x,y) > > It is described in pages 189-216 in [1]. > > [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/ > haskell.pdf > > I assume the bind operator (==>) was overwritten by > > (>>=) :: Parser a → (a → Parser b) → Parser b p > >>= f = λinp → case parse p inp of > [ ] → [ ] > [ (v, out) ] → parse (f v) out > > in order to manipulate the do expr to make the p function work, right? > > 2017-11-05 21:56 GMT+01:00 Tobias Brandt : > >> Hey, >> >> can you show us your Parser definition? >> >> Cheers, >> Tobias >> >> ----- Nachricht von Marcus Manning --------- >> Datum: Sun, 5 Nov 2017 18:51:57 +0100 >> Von: Marcus Manning >> Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> Betreff: [Haskell-beginners] Could not get parser ready >> An: beginners at haskell.org >> >> Hello, >> >> I follow the instructions of script [1] in order to set up a parser >> functionality. But I' get into problems at page 202 with the code: >> >> p :: Parser (Char,Char) >> p = do >> x ← item >> item >> y ← item >> return (x,y) >> >> >> ghci and ghc throw errors: >> Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; >> return (x,y)} >> >> :10:65: error: >> • Couldn't match type ‘[(Char, String)]’ with ‘Char’ >> Expected type: String -> [((Char, Char), String)] >> Actual type: Parser ([(Char, String)], [(Char, String)]) >> • In a stmt of a 'do' block: return (x, y) >> In the expression: >> do x <- item >> item >> y <- item >> return (x, y) >> In an equation for ‘p’: >> p = do x <- item >> item >> y <- item >> .... >> Did the semantics of do expr changed? >> >> [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/reso >> urces/pdf/haskell.pdf >> >> Cheers, >> >> iconfly. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman >> /listinfo/beginners >> >> >> >> >> ----- Ende der Nachricht von Marcus Manning ----- >> >> >> _______________________________________________ >> 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 iconsize at gmail.com Mon Nov 6 15:48:04 2017 From: iconsize at gmail.com (Marcus Manning) Date: Mon, 6 Nov 2017 16:48:04 +0100 Subject: [Haskell-beginners] Could not get parser ready In-Reply-To: References: <20171105215602.Horde.ImSW87F6UDtqhG4r3-E7k8R@webmail.uni-bremen.de> Message-ID: p' :: Parser (Char, Char) p' = item `bind` \x -> item `bind` \_ -> item `bind` \y -> return (x, y) with bind:: Parser a -> (a -> Parser b) -> Parser b bind p f = \ inp -> case parse p inp of [] -> [] [(v,out)] -> parse (f v) out works like a charm. Another alternatiev would to change the Parser definition to the one given in [1]. Thanks. Cheers, iconfly [1] http://dev.stephendiehl.com/fun/002_parsers.html 2017-11-06 14:29 GMT+01:00 David McBride : > The problem is that in p you are using do notation for bind, which uses > the Monad instance for bind (>>=) for ((->) String), because Parser is a > type alias for (String -> [(a, String)]. But then you are using your own > return which is not of the same type as Monad's return would be. The way > you have it now your return considers the loose `a` as the Monad parameter, > but do notation considers it [(a, String)] instead. > > You can either a) write your own bind that conforms to your type. > > bind :: Parser a -> (a -> Parser b) -> Parser b > bind = undefined > > p' :: Parser (Char, Char) > p' = item `bind` \x -> item `bind` \_ -> item `bind` \y -> Foo.return (x, > y) > > Or you can use the Monad return instead. But the type is not what you > expect. > > p :: String -> ([(Char, String)], [(Char, String)]) > p = do x <- item > item > y <- item > Prelude.return (x,y) > > > > > > On Mon, Nov 6, 2017 at 3:15 AM, Marcus Manning wrote: > >> type Parser a = String → [(a,String)] >> >> item :: Parser Char >> item = λinp → case inp of >> [] → [] >> (x:xs) → [(x,xs)] >> failure :: Parser a >> failure = λinp → [] >> >> return :: a → Parser a >> return v = λinp → [(v,inp)] >> >> (+++) :: Parser a → Parser a → Parser a >> p +++ q = λinp → case p inp of >> [] → q inp >> [(v,out)] → [(v,out)] >> >> parse :: Parser a → String → [(a,String)] >> parse p inp = p inp >> >> p :: Parser (Char,Char) >> p = do x ← item >> item >> y ← item >> return (x,y) >> >> It is described in pages 189-216 in [1]. >> >> [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/ >> resources/pdf/haskell.pdf >> >> I assume the bind operator (==>) was overwritten by >> >> (>>=) :: Parser a → (a → Parser b) → Parser b p >> >>= f = λinp → case parse p inp of >> [ ] → [ ] >> [ (v, out) ] → parse (f v) out >> >> in order to manipulate the do expr to make the p function work, right? >> >> 2017-11-05 21:56 GMT+01:00 Tobias Brandt : >> >>> Hey, >>> >>> can you show us your Parser definition? >>> >>> Cheers, >>> Tobias >>> >>> ----- Nachricht von Marcus Manning --------- >>> Datum: Sun, 5 Nov 2017 18:51:57 +0100 >>> Von: Marcus Manning >>> Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily >>> beginner-level topics related to Haskell >>> Betreff: [Haskell-beginners] Could not get parser ready >>> An: beginners at haskell.org >>> >>> Hello, >>> >>> I follow the instructions of script [1] in order to set up a parser >>> functionality. But I' get into problems at page 202 with the code: >>> >>> p :: Parser (Char,Char) >>> p = do >>> x ← item >>> item >>> y ← item >>> return (x,y) >>> >>> >>> ghci and ghc throw errors: >>> Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; >>> return (x,y)} >>> >>> :10:65: error: >>> • Couldn't match type ‘[(Char, String)]’ with ‘Char’ >>> Expected type: String -> [((Char, Char), String)] >>> Actual type: Parser ([(Char, String)], [(Char, String)]) >>> • In a stmt of a 'do' block: return (x, y) >>> In the expression: >>> do x <- item >>> item >>> y <- item >>> return (x, y) >>> In an equation for ‘p’: >>> p = do x <- item >>> item >>> y <- item >>> .... >>> Did the semantics of do expr changed? >>> >>> [1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/reso >>> urces/pdf/haskell.pdf >>> >>> Cheers, >>> >>> iconfly. >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman >>> /listinfo/beginners >>> >>> >>> >>> >>> ----- Ende der Nachricht von Marcus Manning ----- >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Wed Nov 8 19:21:14 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Wed, 8 Nov 2017 19:21:14 +0000 Subject: [Haskell-beginners] Type constructor Message-ID: Hi, I’m modelling fractions with a view to looking at continued fractions and I have this recursive structure. type Numerator = Integer data Fraction = Numbr Integer | F Numerator Fraction in ghci I do λ-> :t F 1 (Numbr 2) F 1 (Numbr 2) :: Fraction which is fine. But what surprised me is that it also works without using Numbr e.g. λ-> :t F 1 2 F 1 2 :: Fraction why is this? Thanks Mike From toad3k at gmail.com Wed Nov 8 19:31:50 2017 From: toad3k at gmail.com (David McBride) Date: Wed, 8 Nov 2017 14:31:50 -0500 Subject: [Haskell-beginners] Type constructor In-Reply-To: References: Message-ID: The only thing I can think of is that you wrote a Num instance for Fraction. That allows it to represent a fraction as a literal 2 because you can create a fraction from an integer via fromInteger. On Wed, Nov 8, 2017 at 2:21 PM, mike h wrote: > Hi, > > I’m modelling fractions with a view to looking at continued fractions and > I have this recursive structure. > > type Numerator = Integer > data Fraction = Numbr Integer | F Numerator Fraction > > > in ghci I do > > λ-> :t F 1 (Numbr 2) > F 1 (Numbr 2) :: Fraction > > which is fine. But what surprised me is that it also works without using > Numbr e.g. > > λ-> :t F 1 2 > F 1 2 :: Fraction > > why is this? > > Thanks > > Mike > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Wed Nov 8 20:26:41 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Wed, 8 Nov 2017 20:26:41 +0000 Subject: [Haskell-beginners] Type constructor In-Reply-To: References: Message-ID: <96E5750B-F32C-46A1-8D5F-2C9EF0EB4C0C@yahoo.co.uk> Duh! Give that man a ceeeegar! Thanks :) > On 8 Nov 2017, at 19:31, David McBride wrote: > > The only thing I can think of is that you wrote a Num instance for Fraction. That allows it to represent a fraction as a literal 2 because you can create a fraction from an integer via fromInteger. > > On Wed, Nov 8, 2017 at 2:21 PM, mike h > wrote: > Hi, > > I’m modelling fractions with a view to looking at continued fractions and I have this recursive structure. > > type Numerator = Integer > data Fraction = Numbr Integer | F Numerator Fraction > > > in ghci I do > > λ-> :t F 1 (Numbr 2) > F 1 (Numbr 2) :: Fraction > > which is fine. But what surprised me is that it also works without using Numbr e.g. > > λ-> :t F 1 2 > F 1 2 :: Fraction > > why is this? > > Thanks > > Mike > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikhilka585 at gmail.com Mon Nov 13 11:00:29 2017 From: nikhilka585 at gmail.com (nikhil kaushik) Date: Mon, 13 Nov 2017 16:30:29 +0530 Subject: [Haskell-beginners] Resource-recommendation Message-ID: Hello, I have just started learning Haskell and I am really enjoying it. As I do not have a good mathematical background and a little experience with programming in general, which book is recommended for me? I started learning haskell from LYAH website and I completed 6 chapters but there are no exercises in that book so I want a book which is beginner friendly and has exercises. Please recommended some books considering my situation. Thank you -- ~Nikhil Kaushik -------------- next part -------------- An HTML attachment was scrubbed... URL: From brutallesale at gmail.com Mon Nov 13 11:11:21 2017 From: brutallesale at gmail.com (sasa bogicevic) Date: Mon, 13 Nov 2017 12:11:21 +0100 Subject: [Haskell-beginners] Resource-recommendation In-Reply-To: References: Message-ID: <62B822DB-71B0-4E0B-8AAF-B1CD8DEE64A4@gmail.com> Hello Nikhil, I found this to be a really good book http://haskellbook.com/ { name: Bogicevic Sasa phone: +381606006200 } > On Nov 13, 2017, at 12:00, nikhil kaushik wrote: > > Hello, > I have just started learning Haskell and I am really enjoying it. As I do not have a good mathematical background and a little experience with programming in general, > which book is recommended for me? I started learning haskell from LYAH website and I completed 6 chapters but there are no exercises in that book so I want a book which > is beginner friendly and has exercises. > Please recommended some books considering my situation. > > Thank you > > -- > ~Nikhil Kaushik > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Nov 13 12:02:36 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 13 Nov 2017 13:02:36 +0100 Subject: [Haskell-beginners] Resource-recommendation In-Reply-To: References: Message-ID: <20171113120236.on4u4too4gjyezfk@x60s.casa> On Mon, Nov 13, 2017 at 04:30:29PM +0530, nikhil kaushik wrote: > which book is recommended for me? Hi Nikhil, CIS 194 [1] has plenty of exercises, very well written and free of charge [1] http://www.seas.upenn.edu/~cis194/fall16/ From raabe at froglogic.com Mon Nov 13 12:50:09 2017 From: raabe at froglogic.com (Frerich Raabe) Date: Mon, 13 Nov 2017 13:50:09 +0100 Subject: [Haskell-beginners] Resource-recommendation In-Reply-To: References: Message-ID: <283cb9a44b554d8b4c132c69031b710a@froglogic.com> On 2017-11-13 12:00, nikhil kaushik wrote: > Please recommended some books considering my situation. I very much recommend Graham Hutton's "Programming in Haskell", see http://www.cs.nott.ac.uk/~pszgmh/pih.html -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From leiva.steven at gmail.com Mon Nov 13 14:25:58 2017 From: leiva.steven at gmail.com (Steven Leiva) Date: Mon, 13 Nov 2017 14:25:58 +0000 Subject: [Haskell-beginners] Resource-recommendation In-Reply-To: <283cb9a44b554d8b4c132c69031b710a@froglogic.com> References: <283cb9a44b554d8b4c132c69031b710a@froglogic.com> Message-ID: <497b43d1-8456-8667-08b8-7cc36308fd5d@mixmax.com> Chris Allen (co-author of Haskell From First Principles) has a post regarding exactly this question. Don't get too bogged down in the details. The only reason I bring it up is because he suggests the spring 13 version of CIS 194. Haven't taken either though (and maybe he just hasn't seen the new one??). - Steven On Mon, Nov 13, 2017 7:50 AM, Frerich Raabe raabe at froglogic.com wrote: On 2017-11-13 12:00, nikhil kaushik wrote: > Please recommended some books considering my situation. I very much recommend Graham Hutton's "Programming in Haskell", see http://www.cs.nott.ac.uk/~pszgmh/pih.html -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners Steven Leiva 305.528.6038 leiva.steven at gmail.com http://www.linkedin.com/in/stevenleiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From theedge456 at free.fr Tue Nov 14 07:25:55 2017 From: theedge456 at free.fr (Fabien R) Date: Tue, 14 Nov 2017 08:25:55 +0100 Subject: [Haskell-beginners] Resource-recommendation In-Reply-To: References: Message-ID: <118d8e1f-153f-e5ea-947d-8b275ef15b48@free.fr> On 13/11/2017 12:00, nikhil kaushik wrote: > Hello, > I have just started learning Haskell and I am really enjoying it. As I do > not have a good mathematical background and a little experience with > programming in general, Since you have a math background, this book may suit: The Haskell Road to Logic, Math and Programming -- Fabien From nikhilka585 at gmail.com Tue Nov 14 18:23:17 2017 From: nikhilka585 at gmail.com (nikhil kaushik) Date: Tue, 14 Nov 2017 23:53:17 +0530 Subject: [Haskell-beginners] Beginners Digest, Vol 113, Issue 8 In-Reply-To: References: Message-ID: Thank you all for the guidance. ~ Nikhil On Tue, Nov 14, 2017 at 5:30 PM, wrote: > Send Beginners mailing list submissions to > beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > or, via email, send a message with subject or body 'help' to > beginners-request at haskell.org > > You can reach the person managing the list at > beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > Today's Topics: > > 1. Re: Resource-recommendation (Frerich Raabe) > 2. Re: Resource-recommendation (Steven Leiva) > 3. Re: Resource-recommendation (Fabien R) > > > ---------- Forwarded message ---------- > From: Frerich Raabe > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Cc: > Bcc: > Date: Mon, 13 Nov 2017 13:50:09 +0100 > Subject: Re: [Haskell-beginners] Resource-recommendation > On 2017-11-13 12:00, nikhil kaushik wrote: > >> Please recommended some books considering my situation. >> > > I very much recommend Graham Hutton's "Programming in Haskell", see > > http://www.cs.nott.ac.uk/~pszgmh/pih.html > > -- > Frerich Raabe - raabe at froglogic.com > www.froglogic.com - Multi-Platform GUI Testing > > > > ---------- Forwarded message ---------- > From: Steven Leiva > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Cc: > Bcc: > Date: Mon, 13 Nov 2017 14:25:58 +0000 > Subject: Re: [Haskell-beginners] Resource-recommendation > Chris Allen (co-author of Haskell From First Principles) has a post > regarding exactly this > question. > > Don't get too bogged down in the details. The only reason I bring it up is > because he suggests the spring 13 > version of CIS 194. > Haven't taken either though (and maybe he just hasn't seen the new one??). > > - Steven > > > > On Mon, Nov 13, 2017 7:50 AM, Frerich Raabe raabe at froglogic.com wrote: > >> On 2017-11-13 12:00, nikhil kaushik wrote: >> >> > Please recommended some books considering my situation. >> >> >> I very much recommend Graham Hutton's "Programming in Haskell", see >> >> >> http://www.cs.nott.ac.uk/~pszgmh/pih.html >> >> >> -- >> >> Frerich Raabe - raabe at froglogic.com >> >> www.froglogic.com - Multi-Platform GUI Testing >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > > Steven Leiva > 305.528.6038 > leiva.steven at gmail.com > http://www.linkedin.com/in/stevenleiva > > > ---------- Forwarded message ---------- > From: Fabien R > To: beginners at haskell.org > Cc: > Bcc: > Date: Tue, 14 Nov 2017 08:25:55 +0100 > Subject: Re: [Haskell-beginners] Resource-recommendation > On 13/11/2017 12:00, nikhil kaushik wrote: > > Hello, > > I have just started learning Haskell and I am really enjoying it. As I do > > not have a good mathematical background and a little experience with > > programming in general, > Since you have a math background, this book may suit: > The Haskell Road to Logic, Math and Programming > > -- > Fabien > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- ~Nikhil Kaushik -------------- next part -------------- An HTML attachment was scrubbed... URL: From jphedley at gmail.com Tue Nov 14 18:53:37 2017 From: jphedley at gmail.com (jphedley .) Date: Tue, 14 Nov 2017 10:53:37 -0800 Subject: [Haskell-beginners] Beginners Digest, Vol 113, Issue 8 In-Reply-To: References: Message-ID: Nice lecture series to go along with Hutton's "Programming in Haskell"- https://channel9.msdn.com/Series/C9-Lectures-Erik-Meijer-Functional-Programming-Fundamentals/Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1 On Tue, Nov 14, 2017 at 10:23 AM, nikhil kaushik wrote: > Thank you all for the guidance. > > ~ Nikhil > > On Tue, Nov 14, 2017 at 5:30 PM, wrote: > >> Send Beginners mailing list submissions to >> beginners at haskell.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> or, via email, send a message with subject or body 'help' to >> beginners-request at haskell.org >> >> You can reach the person managing the list at >> beginners-owner at haskell.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Beginners digest..." >> >> Today's Topics: >> >> 1. Re: Resource-recommendation (Frerich Raabe) >> 2. Re: Resource-recommendation (Steven Leiva) >> 3. Re: Resource-recommendation (Fabien R) >> >> >> ---------- Forwarded message ---------- >> From: Frerich Raabe >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> Cc: >> Bcc: >> Date: Mon, 13 Nov 2017 13:50:09 +0100 >> Subject: Re: [Haskell-beginners] Resource-recommendation >> On 2017-11-13 12:00, nikhil kaushik wrote: >> >>> Please recommended some books considering my situation. >>> >> >> I very much recommend Graham Hutton's "Programming in Haskell", see >> >> http://www.cs.nott.ac.uk/~pszgmh/pih.html >> >> -- >> Frerich Raabe - raabe at froglogic.com >> www.froglogic.com - Multi-Platform GUI Testing >> >> >> >> ---------- Forwarded message ---------- >> From: Steven Leiva >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> Cc: >> Bcc: >> Date: Mon, 13 Nov 2017 14:25:58 +0000 >> Subject: Re: [Haskell-beginners] Resource-recommendation >> Chris Allen (co-author of Haskell From First Principles) has a post >> regarding exactly this >> question. >> >> Don't get too bogged down in the details. The only reason I bring it up >> is because he suggests the spring 13 >> version of CIS 194. >> Haven't taken either though (and maybe he just hasn't seen the new one??). >> >> - Steven >> >> >> >> On Mon, Nov 13, 2017 7:50 AM, Frerich Raabe raabe at froglogic.com wrote: >> >>> On 2017-11-13 12:00, nikhil kaushik wrote: >>> >>> > Please recommended some books considering my situation. >>> >>> >>> I very much recommend Graham Hutton's "Programming in Haskell", see >>> >>> >>> http://www.cs.nott.ac.uk/~pszgmh/pih.html >>> >>> >>> -- >>> >>> Frerich Raabe - raabe at froglogic.com >>> >>> www.froglogic.com - Multi-Platform GUI Testing >>> >>> _______________________________________________ >>> >>> Beginners mailing list >>> >>> Beginners at haskell.org >>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >> >> Steven Leiva >> 305.528.6038 <(305)%20528-6038> >> leiva.steven at gmail.com >> http://www.linkedin.com/in/stevenleiva >> >> >> ---------- Forwarded message ---------- >> From: Fabien R >> To: beginners at haskell.org >> Cc: >> Bcc: >> Date: Tue, 14 Nov 2017 08:25:55 +0100 >> Subject: Re: [Haskell-beginners] Resource-recommendation >> On 13/11/2017 12:00, nikhil kaushik wrote: >> > Hello, >> > I have just started learning Haskell and I am really enjoying it. As I >> do >> > not have a good mathematical background and a little experience with >> > programming in general, >> Since you have a math background, this book may suit: >> The Haskell Road to Logic, Math and Programming >> >> -- >> Fabien >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > ~Nikhil Kaushik > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Wed Nov 15 12:15:13 2017 From: aquagnu at gmail.com (PY) Date: Wed, 15 Nov 2017 14:15:13 +0200 Subject: [Haskell-beginners] Relation between Effects, Indexed monads, Free monads Message-ID: Hello, All! I'm not sure is it question for Cafe or Beginners List, so first I'll try here. There are kind of errors related to wrong execution sequence. They are good known in OOP: object keeps state internally and check it before to execute got message - to prevent wrong execution sequence. Best implementation is: state machine, also can be used Markov's algorithm, more complex can be done with Petri nets, etc. Example: if I have complex inserting into DB (consisting of several inserts), I can check done of previous step before to start next, etc. After read of different Haskell resources I found solution for it: Indexed Monads. They (if I got it rightly) are monads with additional type parameter which "marks" monad, gives it more specific qualification, for example instead of monad "Opening" (action) we have monad "Opening-of-closed", exactly what I'm talking: type-level check of correct actions sequence (allowed transition). After more research I found Free Monads and Effects and something like  "free monad can be used to proof your program". How?! Free monads  make "active" (executable) code into "passive" code (data instead of code), which can be interpreted separately, so program becomes like Lisp program: code is a data (so, can be modified, checked, etc, etc) and what exactly will be executing - decides interpreter of such code. But do they allow to proof right sequence of actions in such data-like code? What are the Effects I don't understand yet. Somewhere I find something like: Eff = Free Monad + indexed monad (may be I'm not right here). So  my questions are: - how Effects, Free Monad, Indexed Monads are related? - can effects replace indexed monads? - are indexed monad yet usable/modern concept or they are abandoned and replaced by Effects or something else? Do you use indexed monads in real projects? - can I (and how) to use both of them? Or: can I use only FreeMonads / Effects to solve the same problem (control of correct sequence of actions) like with indexed monads help? === Best regards, Paul From mihai.maruseac at gmail.com Wed Nov 15 15:58:06 2017 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Wed, 15 Nov 2017 07:58:06 -0800 Subject: [Haskell-beginners] ANNOUNCE: Haskell Communities and Activities Report (33rd ed., November 2017) Message-ID: On behalf of all the contributors, we are pleased to announce that the Haskell Communities and Activities Report (33rd edition, November 2017) is now available, in PDF and HTML formats: http://haskell.org/communities/11-2017/report.pdf http://haskell.org/communities/11-2017/html/report.html All previous editions of HCAR can be accessed on the wiki at https://wiki.haskell.org/Haskell_Communities_and_Activities_Report Many thanks go to all the people that contributed to this report, both directly, by sending in descriptions, and indirectly, by doing all the interesting things that are reported. We hope you will find it as interesting a read as we did. If you have not encountered the Haskell Communities and Activities Reports before, you may like to know that the first of these reports was published in November 2001. Their goal is to improve the communication between the increasingly diverse groups, projects, and individuals working on, with, or inspired by Haskell. The idea behind these reports is simple: Every six months, a call goes out to all of you enjoying Haskell to contribute brief summaries of your own area of work. Many of you respond (eagerly, unprompted, and sometimes in time for the actual deadline) to the call. The editors collect all the contributions into a single report and feed that back to the community. When we try for the next update, six months from now, you might want to report on your own work, project, research area or group as well. So, please put the following into your diaries now: ======================================== End of February 2018: target deadline for contributions to the May 2018 edition of the HCAR Report ======================================== Unfortunately, many Haskellers working on interesting projects are so busy with their work that they seem to have lost the time to follow the Haskell related mailing lists and newsgroups, and have trouble even finding time to report on their work. If you are a member, user or friend of a project so burdened, please find someone willing to make time to report and ask them to "register" with the editors for a simple e-mail reminder in November (you could point us to them as well, and we can then politely ask if they want to contribute, but it might work better if you do the initial asking). Of course, they will still have to find the ten to fifteen minutes to draw up their report, but maybe we can increase our coverage of all that is going on in the community. Feel free to circulate this announcement further in order to reach people who might otherwise not see it. Enjoy! -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya From jeffbrown.the at gmail.com Wed Nov 15 19:04:38 2017 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Wed, 15 Nov 2017 11:04:38 -0800 Subject: [Haskell-beginners] [Haskell-cafe] ANNOUNCE: Haskell Communities and Activities Report (33rd ed., November 2017) In-Reply-To: References: Message-ID: This treasure trove almost flew under my radar! From the title I thought it was just going to be the results of the recent survey. When I started reading, I thought it would only be plans for changes to the language. Finally I made it to the list (section 4) of tools that exist now and was like woah. On Wed, Nov 15, 2017 at 7:58 AM, Mihai Maruseac wrote: > On behalf of all the contributors, we are pleased to announce that the > > Haskell Communities and Activities Report > (33rd edition, November 2017) > > is now available, in PDF and HTML formats: > > http://haskell.org/communities/11-2017/report.pdf > http://haskell.org/communities/11-2017/html/report.html > > All previous editions of HCAR can be accessed on the wiki at > https://wiki.haskell.org/Haskell_Communities_and_Activities_Report > > Many thanks go to all the people that contributed to this report, > both directly, by sending in descriptions, and indirectly, by doing > all the interesting things that are reported. We hope you will find > it as interesting a read as we did. > > If you have not encountered the Haskell Communities and Activities > Reports before, you may like to know that the first of these reports > was published in November 2001. Their goal is to improve the > communication between the increasingly diverse groups, projects, and > individuals working on, with, or inspired by Haskell. The idea behind > these reports is simple: > > Every six months, a call goes out to all of you enjoying Haskell to > contribute brief summaries of your own area of work. Many of you > respond (eagerly, unprompted, and sometimes in time for the actual > deadline) to the call. The editors collect all the contributions > into a single report and feed that back to the community. > > When we try for the next update, six months from now, you might want > to report on your own work, project, research area or group as well. > So, please put the following into your diaries now: > > ======================================== > End of February 2018: > target deadline for contributions to the > May 2018 edition of the HCAR Report > ======================================== > > Unfortunately, many Haskellers working on interesting projects are so > busy with their work that they seem to have lost the time to follow > the Haskell related mailing lists and newsgroups, and have trouble even > finding time to report on their work. If you are a member, user or > friend of a project so burdened, please find someone willing to make > time to report and ask them to "register" with the editors for a simple > e-mail reminder in November (you could point us to them as well, and we > can then politely ask if they want to contribute, but it might work > better if you do the initial asking). Of course, they will still have to > find the ten to fifteen minutes to draw up their report, but maybe we > can increase our coverage of all that is going on in the community. > > Feel free to circulate this announcement further in order to > reach people who might otherwise not see it. Enjoy! > > > -- > Mihai Maruseac (MM) > "If you can't solve a problem, then there's an easier problem you can > solve: find it." -- George Polya > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- 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 leiva.steven at gmail.com Wed Nov 15 20:02:16 2017 From: leiva.steven at gmail.com (Steven Leiva) Date: Wed, 15 Nov 2017 15:02:16 -0500 Subject: [Haskell-beginners] [Haskell-cafe] ANNOUNCE: Haskell Communities and Activities Report (33rd ed., November 2017) In-Reply-To: References: Message-ID: I'd also like to express my gratitude for this publication. Treasury trove is the most appropriate term for it indeed. (Going to go check out yesod-rest now). - Steven On Wed, Nov 15, 2017 at 2:04 PM, Jeffrey Brown wrote: > This treasure trove almost flew under my radar! From the title I thought > it was just going to be the results of the recent survey. When I started > reading, I thought it would only be plans for changes to the language. > Finally I made it to the list (section 4) of tools that exist now and was > like woah. > > On Wed, Nov 15, 2017 at 7:58 AM, Mihai Maruseac > wrote: > >> On behalf of all the contributors, we are pleased to announce that the >> >> Haskell Communities and Activities Report >> (33rd edition, November 2017) >> >> is now available, in PDF and HTML formats: >> >> http://haskell.org/communities/11-2017/report.pdf >> http://haskell.org/communities/11-2017/html/report.html >> >> All previous editions of HCAR can be accessed on the wiki at >> https://wiki.haskell.org/Haskell_Communities_and_Activities_Report >> >> Many thanks go to all the people that contributed to this report, >> both directly, by sending in descriptions, and indirectly, by doing >> all the interesting things that are reported. We hope you will find >> it as interesting a read as we did. >> >> If you have not encountered the Haskell Communities and Activities >> Reports before, you may like to know that the first of these reports >> was published in November 2001. Their goal is to improve the >> communication between the increasingly diverse groups, projects, and >> individuals working on, with, or inspired by Haskell. The idea behind >> these reports is simple: >> >> Every six months, a call goes out to all of you enjoying Haskell to >> contribute brief summaries of your own area of work. Many of you >> respond (eagerly, unprompted, and sometimes in time for the actual >> deadline) to the call. The editors collect all the contributions >> into a single report and feed that back to the community. >> >> When we try for the next update, six months from now, you might want >> to report on your own work, project, research area or group as well. >> So, please put the following into your diaries now: >> >> ======================================== >> End of February 2018: >> target deadline for contributions to the >> May 2018 edition of the HCAR Report >> ======================================== >> >> Unfortunately, many Haskellers working on interesting projects are so >> busy with their work that they seem to have lost the time to follow >> the Haskell related mailing lists and newsgroups, and have trouble even >> finding time to report on their work. If you are a member, user or >> friend of a project so burdened, please find someone willing to make >> time to report and ask them to "register" with the editors for a simple >> e-mail reminder in November (you could point us to them as well, and we >> can then politely ask if they want to contribute, but it might work >> better if you do the initial asking). Of course, they will still have to >> find the ten to fifteen minutes to draw up their report, but maybe we >> can increase our coverage of all that is going on in the community. >> >> Feel free to circulate this announcement further in order to >> reach people who might otherwise not see it. Enjoy! >> >> >> -- >> Mihai Maruseac (MM) >> "If you can't solve a problem, then there's an easier problem you can >> solve: find it." -- George Polya >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > > > > -- > 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 > > -- Steven Leiva 305.528.6038 leiva.steven at gmail.com http://www.linkedin.com/in/stevenleiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From quentin.liu.0415 at gmail.com Thu Nov 16 00:21:57 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Wed, 15 Nov 2017 19:21:57 -0500 Subject: [Haskell-beginners] Programming with Singletons Message-ID: Hi all, I was doing the “Singletons” problem at codewars[1]. The basic idea is to use dependent types to encode the length of the vector in types. It uses  data Nat = Zero | Succ Nat  data SNat a where    SZero :: SNat Zero    SSucc :: SNat a -> SNat (Succ a) to do the encoding. The vector is defined based on the natural number encoding:  data Vec a n where    VNil :: Vec a Zero    VCons :: a -> Vec a n -> Vec a (Succ n) There are some type families declared for manipulating the natural numbers, and one of them that is relevant to the question is  type family (Add (a :: Nat) (b :: Nat)) :: Nat   type instance Add Zero b = b   type instance Add a    Zero = a   type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) where the `Add` function adds natural numbers. The problem I am stuck with is the concatenation of two vectors:  (++) :: Vec v m -> Vec v n -> Vec v (Add m n)  VNil ++ b = b  (VCons x xs) ++ b = VCons x $ xs ++ b The program would not compile because the compiler found that `VCons x $ xs ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m n’ that the type does not match? I read Brent Yorgey’s blog on type-level programming[2] and he mentioned that would not automatically expand types. But the posted time of the blog is 2010 and I am wondering if there is any improvement to the situation since then? Besides, what would be the solution to this problem Warm Regards, Qingbo Liu [1] https://www.codewars.com/kata/singletons/train/haskell [2] https://byorgey.wordpress.com/2010/07/06/typed-type-level-programming-in-haskell-part-ii-type-families/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mukeshtiwari.iiitm at gmail.com Thu Nov 16 00:50:31 2017 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Thu, 16 Nov 2017 11:50:31 +1100 Subject: [Haskell-beginners] Programming with Singletons In-Reply-To: References: Message-ID: Hi Quentin, I changed your pattern little bit in Add function and it is working fine. I think the problem was that type of (VCons x xs) ++++ b is Vec v (Add (Succ m1) + n) which was not present in your Add function pattern. {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE InstanceSigs #-} module Tmp where data Nat = Zero | Succ Nat data SNat a where   SZero :: SNat Zero   SSucc :: SNat a -> SNat (Succ a) data Vec a n where   VNil :: Vec a Zero   VCons :: a -> Vec a n -> Vec a (Succ n) type family (Add (a :: Nat) (b :: Nat)) :: Nat type instance Add Zero b = b type instance Add (Succ a) b = Succ (Add a b) (++++) :: Vec v m -> Vec v n -> Vec v (Add m n) VNil ++++ b = b (VCons x xs) ++++ b = VCons x $ xs ++++ b On Thu, Nov 16, 2017 at 11:21 AM, Quentin Liu wrote: > Hi all, > > I was doing the “Singletons” problem at codewars[1]. The basic idea is to > use dependent types to encode the length of the vector in types. > > It uses >  data Nat = Zero | Succ Nat > >  data SNat a where >   SZero :: SNat Zero >   SSucc :: SNat a -> SNat (Succ a) > to do the encoding. > > The vector is defined based on the natural number encoding: >  data Vec a n where >   VNil :: Vec a Zero >   VCons :: a -> Vec a n -> Vec a (Succ n) > > > There are some type families declared for manipulating the natural numbers, > and one of them that is relevant to the question is >  type family (Add (a :: Nat) (b :: Nat)) :: Nat >   type instance Add Zero b = b >   type instance Add a Zero = a >   type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) > where the `Add` function adds natural numbers. > > The problem I am stuck with is the concatenation of two vectors: >  (++) :: Vec v m -> Vec v n -> Vec v (Add m n) >  VNil ++ b = b >  (VCons x xs) ++ b = VCons x $ xs ++ b > > The program would not compile because the compiler found that `VCons x $ xs > ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the > declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m n’ > that the type does not match? I read Brent Yorgey’s blog on type-level > programming[2] and he mentioned that would not automatically expand types. > But the posted time of the blog is 2010 and I am wondering if there is any > improvement to the situation since then? Besides, what would be the solution > to this problem > > > Warm Regards, > Qingbo Liu > > [1] https://www.codewars.com/kata/singletons/train/haskell > [2] > https://byorgey.wordpress.com/2010/07/06/typed-type-level-programming-in-haskell-part-ii-type-families/ > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From traqueofziche at gmail.com Thu Nov 16 02:29:08 2017 From: traqueofziche at gmail.com (=?UTF-8?B?6bKN5Yev5paH?=) Date: Wed, 15 Nov 2017 18:29:08 -0800 Subject: [Haskell-beginners] Relation between Effects, Indexed monads, Free monads (PY) Message-ID: Hi, Disclaimer: I am not a lawyer. Nor do I claim to understand all this stuff. The enforcement of sequential ordering is sort of baked into monads; the haskell (read: do-notation) way of combining monadic computations is using bind (i.e. in the "fancy list of instructions with a way to bind results"). This is only for the structure of the computation, though. Every monadic computation is still a pure function, so in the end the RTS, well, executes parts of those at a time, just as pure functions. The ordering guarantee that more corresponds to imperative programming is most obvious (to me) with ST, IO, and State; data dependencies ensure that things "later" in the monadic chain cannot be executed until everything "before". But those effects all involve (mutable) state. Monadic chaining, i.e. combining effectful computations, is separate from the concept of mutable state, etc. It seems more like just an algebra for effects. If you're talking about marked monads as in those with extra type information or phantom params, like when used in tandem with the rank-2 type trick (used in ST, region-based IO, etc.), I think that's a little different, or at least beyond what monads are. Those were created to handle things like guaranteeing that state is only modified single-threadedly (ST), or to ensure that you can't do things like forget to close a handle or leak a ref to a closed one (regions). I think Free monads and (Kiselyov's) Eff monad are still different. They still appeal to the "monads as sequence of instructions" view, but uh, especially with the Eff monad, they're pretty fancy. As in at least personally, for "normal" programming, I haven't felt the need to delve into them. I think the important upshot is: what are you working on? Do monadic computations model what you want to do naturally? If they do, do you need something stronger than what they provide? It's hard to answer the latter questions without answering the first. Sorry for rambling, toz On Wed, Nov 15, 2017 at 4:00 AM, wrote: > Send Beginners mailing list submissions to > beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > or, via email, send a message with subject or body 'help' to > beginners-request at haskell.org > > You can reach the person managing the list at > beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > > Today's Topics: > > 1. Relation between Effects, Indexed monads, Free monads (PY) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 15 Nov 2017 14:15:13 +0200 > From: PY > To: beginners at haskell.org > Subject: [Haskell-beginners] Relation between Effects, Indexed monads, > Free monads > Message-ID: > Content-Type: text/plain; charset=utf-8; format=flowed > > Hello, All! > > I'm not sure is it question for Cafe or Beginners List, so first I'll > try here. > > There are kind of errors related to wrong execution sequence. They are > good known in OOP: object keeps state internally and check it before to > execute got message - to prevent wrong execution sequence. Best > implementation is: state machine, also can be used Markov's algorithm, > more complex can be done with Petri nets, etc. > > Example: if I have complex inserting into DB (consisting of several > inserts), I can check done of previous step before to start next, etc. > After read of different Haskell resources I found solution for it: > Indexed Monads. They (if I got it rightly) are monads with additional > type parameter which "marks" monad, gives it more specific > qualification, for example instead of monad "Opening" (action) we have > monad "Opening-of-closed", exactly what I'm talking: type-level check of > correct actions sequence (allowed transition). > > After more research I found Free Monads and Effects and something like > "free monad can be used to proof your program". How?! Free monads make > "active" (executable) code into "passive" code (data instead of code), > which can be interpreted separately, so program becomes like Lisp > program: code is a data (so, can be modified, checked, etc, etc) and > what exactly will be executing - decides interpreter of such code. But > do they allow to proof right sequence of actions in such data-like code? > > What are the Effects I don't understand yet. > > Somewhere I find something like: Eff = Free Monad + indexed monad (may > be I'm not right here). So my questions are: > > - how Effects, Free Monad, Indexed Monads are related? > > - can effects replace indexed monads? > > - are indexed monad yet usable/modern concept or they are abandoned and > replaced by Effects or something else? Do you use indexed monads in real > projects? > > - can I (and how) to use both of them? Or: can I use only FreeMonads / > Effects to solve the same problem (control of correct sequence of > actions) like with indexed monads help? > > > === > > Best regards, Paul > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 113, Issue 10 > ****************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Thu Nov 16 09:28:41 2017 From: aquagnu at gmail.com (PY) Date: Thu, 16 Nov 2017 11:28:41 +0200 Subject: [Haskell-beginners] Relation between Effects, Indexed monads, Free monads (PY) In-Reply-To: References: Message-ID: <4ae468c4-fae1-4caa-fca9-b267ff7c0904@gmail.com> Hello, Toz, I apologize for my little bit confused question. The root of my interest to such approaches is the situation when order is not possible to be done in one code fragment (such function under monad) because "ordered" steps should happens not immediately one after one, but with time gap, possible in different location of the program. For example, if you do: 1. open file 2. read data 3. close file all these actions are ordered and are located on time axis near one to one, happening immediately. But another case can be: 1. insert info about class rooms 2. do different things (may be exit application even) 3. insert info about pupils It's fictitious example and is targeting by RDBMS but this example is only to illustrate what I'm talking about. I found good example on SO with DVD control: https://stackoverflow.com/questions/28690448/what-is-indexed-monad Also I found that indexed monads can be used to change type of the state "on the fly". So, for me, it's interesting to control allowed transitions between monad actions: do   action1   action2   -- action3 is denied because "action2 => action3" is denied transition/sequence And I'm agree with you that Eff + Free monads looks different from this goal. But I found somewhere that Free monad can be used as proof assistance (there was some lecture on Youtube in Ljubljana university, but I can't find it more) and I'm thinking: may be it's possible to use Free monads for something similar like indexed monads? I found indexed free monads but such abstraction looks very complex and hard to me. === Best regards, Paul 16.11.2017 04:29, 鲍凯文 wrote: > Hi, > > Disclaimer: I am not a lawyer. Nor do I claim to understand all this > stuff. > > The enforcement of sequential ordering is sort of baked into monads; > the haskell (read: do-notation) way of combining monadic computations > is using bind (i.e. in the "fancy list of instructions with a way to > bind results"). This is only for the structure of the computation, > though. Every monadic computation is still a pure function, so in the > end the RTS, well, executes parts of those at a time, just as pure > functions. > > The ordering guarantee that more corresponds to imperative programming > is most obvious (to me) with ST, IO, and State; data dependencies > ensure that things "later" in the monadic chain cannot be executed > until everything "before". But those effects all involve (mutable) > state. Monadic chaining, i.e. combining effectful computations, is > separate from the concept of mutable state, etc. It seems more like > just an algebra for effects. > > If you're talking about marked monads as in those with extra type > information or phantom params, like when used in tandem with the > rank-2 type trick (used in ST, region-based IO, etc.), I think that's > a little different, or at least beyond what monads are. Those were > created to handle things like guaranteeing that state is only modified > single-threadedly (ST), or to ensure that you can't do things like > forget to close a handle or leak a ref to a closed one (regions). > > I think Free monads and (Kiselyov's) Eff monad are still different. > They still appeal to the "monads as sequence of instructions" view, > but uh, especially with the Eff monad, they're pretty fancy. As in at > least personally, for "normal" programming, I haven't felt the need to > delve into them. > > I think the important upshot is: what are you working on? Do monadic > computations model what you want to do naturally? If they do, do you > need something stronger than what they provide? It's hard to answer > the latter questions without answering the first. > > Sorry for rambling, > > toz > > On Wed, Nov 15, 2017 at 4:00 AM, > wrote: > > Send Beginners mailing list submissions to > beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > or, via email, send a message with subject or body 'help' to > beginners-request at haskell.org > > You can reach the person managing the list at > beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > > Today's Topics: > >    1.  Relation between Effects, Indexed monads,   Free monads (PY) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 15 Nov 2017 14:15:13 +0200 > From: PY > > To: beginners at haskell.org > Subject: [Haskell-beginners] Relation between Effects, Indexed monads, >         Free monads > Message-ID: > > Content-Type: text/plain; charset=utf-8; format=flowed > > Hello, All! > > I'm not sure is it question for Cafe or Beginners List, so first I'll > try here. > > There are kind of errors related to wrong execution sequence. They are > good known in OOP: object keeps state internally and check it > before to > execute got message - to prevent wrong execution sequence. Best > implementation is: state machine, also can be used Markov's algorithm, > more complex can be done with Petri nets, etc. > > Example: if I have complex inserting into DB (consisting of several > inserts), I can check done of previous step before to start next, etc. > After read of different Haskell resources I found solution for it: > Indexed Monads. They (if I got it rightly) are monads with additional > type parameter which "marks" monad, gives it more specific > qualification, for example instead of monad "Opening" (action) we have > monad "Opening-of-closed", exactly what I'm talking: type-level > check of > correct actions sequence (allowed transition). > > After more research I found Free Monads and Effects and something > like > "free monad can be used to proof your program". How?! Free monads  > make > "active" (executable) code into "passive" code (data instead of code), > which can be interpreted separately, so program becomes like Lisp > program: code is a data (so, can be modified, checked, etc, etc) and > what exactly will be executing - decides interpreter of such code. But > do they allow to proof right sequence of actions in such data-like > code? > > What are the Effects I don't understand yet. > > Somewhere I find something like: Eff = Free Monad + indexed monad (may > be I'm not right here). So  my questions are: > > - how Effects, Free Monad, Indexed Monads are related? > > - can effects replace indexed monads? > > - are indexed monad yet usable/modern concept or they are > abandoned and > replaced by Effects or something else? Do you use indexed monads > in real > projects? > > - can I (and how) to use both of them? Or: can I use only FreeMonads / > Effects to solve the same problem (control of correct sequence of > actions) like with indexed monads help? > > > === > > Best regards, Paul > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > ------------------------------ > > End of Beginners Digest, Vol 113, Issue 10 > ****************************************** > > > > > _______________________________________________ > 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 quentin.liu.0415 at gmail.com Fri Nov 17 01:01:06 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Thu, 16 Nov 2017 20:01:06 -0500 Subject: [Haskell-beginners] Programming with Singletons In-Reply-To: References: Message-ID: Thank you so much! Indeed changing the definition of `Add` helps solve the problem. Following this idea, I changed the definition of `Minus` and `Min` also. Now they are defined as > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > type instance Sub (Succ a) Zero       = Succ a > type instance Sub Zero     b               = Zero > type instance Sub (Succ a) (Succ b) = Sub a b > > type family (Min (a :: Nat) (b :: Nat)) :: Nat > type instance Min Zero     Zero      = Zero > type instance Min Zero     (Succ b)  = Zero > type instance Min (Succ a) Zero      = Zero > type instance Min (Succ a) (Succ b)  = Succ (Min a b) The change, however, breaks the `tail` and `drop` function. > drop :: SNat a -> Vec s b -> Vec s (Sub b a) > drop SZero     vcons        = vcons > drop (SSucc a) (VCons x xs) = drop a xs > > tail :: ((Zero :< a) ~ True) => Vec s a -> Vec s (Sub a (Succ Zero)) > tail (VCons x xs) = xs So why does the code break and what would be the solution? The error message seems to confirm that even right now GHD still does not support type expansion. Regards, Qingbo Liu On Nov 15, 2017, 19:51 -0500, mukesh tiwari , wrote: > Hi Quentin, > I changed your pattern little bit in Add function and it is working > fine. I think the problem was that type of (VCons x xs) ++++ b is Vec > v (Add (Succ m1) + n) which was not present in your > Add function pattern. > > > > {-# LANGUAGE TypeFamilies #-} > {-# LANGUAGE DataKinds #-} > {-# LANGUAGE KindSignatures #-} > {-# LANGUAGE GADTs #-} > {-# LANGUAGE InstanceSigs #-} > module Tmp where > > data Nat = Zero | Succ Nat > > data SNat a where >   SZero :: SNat Zero >   SSucc :: SNat a -> SNat (Succ a) > > data Vec a n where >   VNil :: Vec a Zero >   VCons :: a -> Vec a n -> Vec a (Succ n) > > type family (Add (a :: Nat) (b :: Nat)) :: Nat > type instance Add Zero b = b > type instance Add (Succ a) b = Succ (Add a b) > > (++++) :: Vec v m -> Vec v n -> Vec v (Add m n) > VNil ++++ b = b > (VCons x xs) ++++ b = VCons x $ xs ++++ b > > On Thu, Nov 16, 2017 at 11:21 AM, Quentin Liu > wrote: > > Hi all, > > > > I was doing the “Singletons” problem at codewars[1]. The basic idea is to > > use dependent types to encode the length of the vector in types. > > > > It uses > >  data Nat = Zero | Succ Nat > > > >  data SNat a where > >   SZero :: SNat Zero > >   SSucc :: SNat a -> SNat (Succ a) > > to do the encoding. > > > > The vector is defined based on the natural number encoding: > >  data Vec a n where > >   VNil :: Vec a Zero > >   VCons :: a -> Vec a n -> Vec a (Succ n) > > > > > > There are some type families declared for manipulating the natural numbers, > > and one of them that is relevant to the question is > >  type family (Add (a :: Nat) (b :: Nat)) :: Nat > >   type instance Add Zero b = b > >   type instance Add a Zero = a > >   type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) > > where the `Add` function adds natural numbers. > > > > The problem I am stuck with is the concatenation of two vectors: > >  (++) :: Vec v m -> Vec v n -> Vec v (Add m n) > >  VNil ++ b = b > >  (VCons x xs) ++ b = VCons x $ xs ++ b > > > > The program would not compile because the compiler found that `VCons x $ xs > > ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the > > declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m n’ > > that the type does not match? I read Brent Yorgey’s blog on type-level > > programming[2] and he mentioned that would not automatically expand types. > > But the posted time of the blog is 2010 and I am wondering if there is any > > improvement to the situation since then? Besides, what would be the solution > > to this problem > > > > > > Warm Regards, > > Qingbo Liu > > > > [1] https://www.codewars.com/kata/singletons/train/haskell > > [2] > > https://byorgey.wordpress.com/2010/07/06/typed-type-level-programming-in-haskell-part-ii-type-families/ > > > > > > _______________________________________________ > > 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 mukeshtiwari.iiitm at gmail.com Fri Nov 17 02:08:15 2017 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 17 Nov 2017 13:08:15 +1100 Subject: [Haskell-beginners] Programming with Singletons In-Reply-To: References: Message-ID: Changed your Sub code to this and drop works now. You drop function drop SZero vcons = vcons so you are returning the second vector if first one is empty (length Zero). type family (Sub (a :: Nat) (b :: Nat)) :: Nat type instance Sub a Zero = a type instance Sub Zero b = b type instance Sub (Succ a) (Succ b) = Sub a b No use of Min in your code, but I changed it anyway. type family (Min (a :: Nat) (b :: Nat)) :: Nat type instance Min Zero b = Zero type instance Min a Zero = Zero type instance Min (Succ a) (Succ b) = Succ (Min a b) I am not able to compile your tail code, so could you please paste your whole code github, or any preferred link which you like. I am getting *Not in scope: type constructor or class ‘:<’* On Fri, Nov 17, 2017 at 12:01 PM, Quentin Liu wrote: > Thank you so much! Indeed changing the definition of `Add` helps solve the > problem. > > Following this idea, I changed the definition of `Minus` and `Min` also. > Now they are defined as > > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > type instance Sub (Succ a) Zero = Succ a > type instance Sub Zero b = Zero > type instance Sub (Succ a) (Succ b) = Sub a b > > type family (Min (a :: Nat) (b :: Nat)) :: Nat > type instance Min Zero Zero = Zero > type instance Min Zero (Succ b) = Zero > type instance Min (Succ a) Zero = Zero > type instance Min (Succ a) (Succ b) = Succ (Min a b) > > > The change, however, breaks the `tail` and `drop` function. > > drop :: SNat a -> Vec s b -> Vec s (Sub b a) > drop SZero vcons = vcons > drop (SSucc a) (VCons x xs) = drop a xs > > tail :: ((Zero :< a) ~ True) => Vec s a -> Vec s (Sub a (Succ Zero)) > tail (VCons x xs) = xs > > > So why does the code break and what would be the solution? The error > message seems to confirm that even right now GHD still does not support > type expansion. > > Regards, > Qingbo Liu > > On Nov 15, 2017, 19:51 -0500, mukesh tiwari , > wrote: > > Hi Quentin, > I changed your pattern little bit in Add function and it is working > fine. I think the problem was that type of (VCons x xs) ++++ b is Vec > v (Add (Succ m1) + n) which was not present in your > Add function pattern. > > > > {-# LANGUAGE TypeFamilies #-} > {-# LANGUAGE DataKinds #-} > {-# LANGUAGE KindSignatures #-} > {-# LANGUAGE GADTs #-} > {-# LANGUAGE InstanceSigs #-} > module Tmp where > > data Nat = Zero | Succ Nat > > data SNat a where > SZero :: SNat Zero > SSucc :: SNat a -> SNat (Succ a) > > data Vec a n where > VNil :: Vec a Zero > VCons :: a -> Vec a n -> Vec a (Succ n) > > type family (Add (a :: Nat) (b :: Nat)) :: Nat > type instance Add Zero b = b > type instance Add (Succ a) b = Succ (Add a b) > > (++++) :: Vec v m -> Vec v n -> Vec v (Add m n) > VNil ++++ b = b > (VCons x xs) ++++ b = VCons x $ xs ++++ b > > On Thu, Nov 16, 2017 at 11:21 AM, Quentin Liu > wrote: > > Hi all, > > I was doing the “Singletons” problem at codewars[1]. The basic idea is to > use dependent types to encode the length of the vector in types. > > It uses > data Nat = Zero | Succ Nat > > data SNat a where > SZero :: SNat Zero > SSucc :: SNat a -> SNat (Succ a) > to do the encoding. > > The vector is defined based on the natural number encoding: > data Vec a n where > VNil :: Vec a Zero > VCons :: a -> Vec a n -> Vec a (Succ n) > > > There are some type families declared for manipulating the natural numbers, > and one of them that is relevant to the question is > type family (Add (a :: Nat) (b :: Nat)) :: Nat > type instance Add Zero b = b > type instance Add a Zero = a > type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) > where the `Add` function adds natural numbers. > > The problem I am stuck with is the concatenation of two vectors: > (++) :: Vec v m -> Vec v n -> Vec v (Add m n) > VNil ++ b = b > (VCons x xs) ++ b = VCons x $ xs ++ b > > The program would not compile because the compiler found that `VCons x $ xs > ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the > declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m > n’ > that the type does not match? I read Brent Yorgey’s blog on type-level > programming[2] and he mentioned that would not automatically expand types. > But the posted time of the blog is 2010 and I am wondering if there is any > improvement to the situation since then? Besides, what would be the > solution > to this problem > > > Warm Regards, > Qingbo Liu > > [1] https://www.codewars.com/kata/singletons/train/haskell > [2] > https://byorgey.wordpress.com/2010/07/06/typed-type-level- > programming-in-haskell-part-ii-type-families/ > > > _______________________________________________ > 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 mukeshtiwari.iiitm at gmail.com Fri Nov 17 08:06:36 2017 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 17 Nov 2017 19:06:36 +1100 Subject: [Haskell-beginners] Programming with Singletons In-Reply-To: References: Message-ID: Disregard my previous mail, because I realized that your Sub is correct except (Succ a). Sorry for the confusion. New definition below type family (Sub (a :: Nat) (b :: Nat)) :: Nat type instance Sub a Zero = a type instance Sub Zero b = Zero type instance Sub (Succ a) (Succ b) = Sub a b On Fri, Nov 17, 2017 at 1:08 PM, mukesh tiwari wrote: > Changed your Sub code to this and drop works now. You drop function > drop SZero vcons = vcons so you are returning the second > vector if first one is empty (length Zero). > > > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > type instance Sub a Zero = a > type instance Sub Zero b = b > type instance Sub (Succ a) (Succ b) = Sub a b > > No use of Min in your code, but I changed it anyway. > > type family (Min (a :: Nat) (b :: Nat)) :: Nat > type instance Min Zero b = Zero > type instance Min a Zero = Zero > type instance Min (Succ a) (Succ b) = Succ (Min a b) > > I am not able to compile your tail code, so could you please paste your > whole code github, or any preferred link which you like. > I am getting > > *Not in scope: type constructor or class ‘:<’* > > On Fri, Nov 17, 2017 at 12:01 PM, Quentin Liu > wrote: > >> Thank you so much! Indeed changing the definition of `Add` helps solve >> the problem. >> >> Following this idea, I changed the definition of `Minus` and `Min` also. >> Now they are defined as >> >> type family (Sub (a :: Nat) (b :: Nat)) :: Nat >> type instance Sub (Succ a) Zero = Succ a >> type instance Sub Zero b = Zero >> type instance Sub (Succ a) (Succ b) = Sub a b >> >> type family (Min (a :: Nat) (b :: Nat)) :: Nat >> type instance Min Zero Zero = Zero >> type instance Min Zero (Succ b) = Zero >> type instance Min (Succ a) Zero = Zero >> type instance Min (Succ a) (Succ b) = Succ (Min a b) >> >> >> The change, however, breaks the `tail` and `drop` function. >> >> drop :: SNat a -> Vec s b -> Vec s (Sub b a) >> drop SZero vcons = vcons >> drop (SSucc a) (VCons x xs) = drop a xs >> >> tail :: ((Zero :< a) ~ True) => Vec s a -> Vec s (Sub a (Succ Zero)) >> tail (VCons x xs) = xs >> >> >> So why does the code break and what would be the solution? The error >> message seems to confirm that even right now GHD still does not support >> type expansion. >> >> Regards, >> Qingbo Liu >> >> On Nov 15, 2017, 19:51 -0500, mukesh tiwari > >, wrote: >> >> Hi Quentin, >> I changed your pattern little bit in Add function and it is working >> fine. I think the problem was that type of (VCons x xs) ++++ b is Vec >> v (Add (Succ m1) + n) which was not present in your >> Add function pattern. >> >> >> >> {-# LANGUAGE TypeFamilies #-} >> {-# LANGUAGE DataKinds #-} >> {-# LANGUAGE KindSignatures #-} >> {-# LANGUAGE GADTs #-} >> {-# LANGUAGE InstanceSigs #-} >> module Tmp where >> >> data Nat = Zero | Succ Nat >> >> data SNat a where >> SZero :: SNat Zero >> SSucc :: SNat a -> SNat (Succ a) >> >> data Vec a n where >> VNil :: Vec a Zero >> VCons :: a -> Vec a n -> Vec a (Succ n) >> >> type family (Add (a :: Nat) (b :: Nat)) :: Nat >> type instance Add Zero b = b >> type instance Add (Succ a) b = Succ (Add a b) >> >> (++++) :: Vec v m -> Vec v n -> Vec v (Add m n) >> VNil ++++ b = b >> (VCons x xs) ++++ b = VCons x $ xs ++++ b >> >> On Thu, Nov 16, 2017 at 11:21 AM, Quentin Liu >> wrote: >> >> Hi all, >> >> I was doing the “Singletons” problem at codewars[1]. The basic idea is to >> use dependent types to encode the length of the vector in types. >> >> It uses >> data Nat = Zero | Succ Nat >> >> data SNat a where >> SZero :: SNat Zero >> SSucc :: SNat a -> SNat (Succ a) >> to do the encoding. >> >> The vector is defined based on the natural number encoding: >> data Vec a n where >> VNil :: Vec a Zero >> VCons :: a -> Vec a n -> Vec a (Succ n) >> >> >> There are some type families declared for manipulating the natural >> numbers, >> and one of them that is relevant to the question is >> type family (Add (a :: Nat) (b :: Nat)) :: Nat >> type instance Add Zero b = b >> type instance Add a Zero = a >> type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) >> where the `Add` function adds natural numbers. >> >> The problem I am stuck with is the concatenation of two vectors: >> (++) :: Vec v m -> Vec v n -> Vec v (Add m n) >> VNil ++ b = b >> (VCons x xs) ++ b = VCons x $ xs ++ b >> >> The program would not compile because the compiler found that `VCons x $ >> xs >> ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the >> declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m >> n’ >> that the type does not match? I read Brent Yorgey’s blog on type-level >> programming[2] and he mentioned that would not automatically expand types. >> But the posted time of the blog is 2010 and I am wondering if there is any >> improvement to the situation since then? Besides, what would be the >> solution >> to this problem >> >> >> Warm Regards, >> Qingbo Liu >> >> [1] https://www.codewars.com/kata/singletons/train/haskell >> [2] >> https://byorgey.wordpress.com/2010/07/06/typed-type-level-pr >> ogramming-in-haskell-part-ii-type-families/ >> >> >> _______________________________________________ >> 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 guthrie at mum.edu Fri Nov 17 08:35:00 2017 From: guthrie at mum.edu (Gregory Guthrie) Date: Fri, 17 Nov 2017 02:35:00 -0600 Subject: [Haskell-beginners] argument counts... Message-ID: <08EF9DA445C4B5439C4733E1F35705BA0678889B2B1B@MAIL.cs.mum.edu> I have a simple function: revFn (x:xs) = (revFn xs) . (x:) Of course GHCi correctly infers the type as: revFn :: [a] -> [a] -> c Adding the base case: revFn [] xs = xs Now gives an error; "Equations for 'revF' have different numbers of arguments" Of course this can be "fixed" by either adding the cancelled argument to the first clause, or converting the base case to only have one explicit argument, and a RHS of a lambda or identity function. But since the interpreter already correctly inferred that the first clause has two arguments (with only one explicit), why does it then ignore this and give an error when the second clause shows two explicit arguments? The types are all correct in either case - why require explicit arguments? Or, perhaps I am missing something simple? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimbo4350 at gmail.com Sat Nov 18 17:15:51 2017 From: jimbo4350 at gmail.com (Jim) Date: Sat, 18 Nov 2017 13:15:51 -0400 Subject: [Haskell-beginners] Non-exhaustive patterns Message-ID: Hey guys, Thiis is my function below: notThe :: String -> Maybe String notThe word       | word /= "the" = Just word       | word == [] = Just []       | otherwise = Nothing replaceThe :: String -> String replaceThe word = go (words word)       where go (x:xs)               | notThe x == Just [] = []               | notThe x == Just word = word ++ go xs               | notThe word == Nothing = " a " ++ go xs > replaceThe "what" "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns in function go I thought I covered all the potential patterns in my replaceThe function. I'm not sure what pattern I've missed, any thoughts? Best regards, Jim From brodyberg at gmail.com Sat Nov 18 17:48:11 2017 From: brodyberg at gmail.com (Brody Berg) Date: Sat, 18 Nov 2017 17:48:11 +0000 Subject: [Haskell-beginners] Non-exhaustive patterns In-Reply-To: References: Message-ID: Made some changes to replaceThe to handle the possibility of empty list: replaceThe :: String -> String replaceThe word = go $ words word where go [] = “” go (x:xs) = case (notThe x) of Just x -> x ++ “ “ ++ go xs Nothing -> “ a “ ++ go xs Typed this on a phone, sorry On Sat, Nov 18, 2017 at 09:16 Jim wrote: > Hey guys, > > Thiis is my function below: > > notThe :: String -> Maybe String > notThe word > | word /= "the" = Just word > | word == [] = Just [] > | otherwise = Nothing > > replaceThe :: String -> String > replaceThe word = go (words word) > where go (x:xs) > | notThe x == Just [] = [] > | notThe x == Just word = word ++ go xs > | notThe word == Nothing = " a " ++ go xs > > > > replaceThe "what" > "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns > in function go > > I thought I covered all the potential patterns in my replaceThe > function. I'm not sure what pattern I've missed, any thoughts? > > Best regards, > > Jim > > _______________________________________________ > 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 brodyberg at gmail.com Sat Nov 18 18:46:04 2017 From: brodyberg at gmail.com (Brody Berg) Date: Sat, 18 Nov 2017 10:46:04 -0800 Subject: [Haskell-beginners] Non-exhaustive patterns In-Reply-To: References: Message-ID: My complete code: notThe :: String -> Maybe String notThe word | word == "the" = Nothing | otherwise = Just word replaceThe :: String -> String replaceThe word = go $ words word where go [] = "" go (x:xs) = case (notThe x) of Just x -> x ++ " " ++ go xs Nothing -> " a " ++ go xs On Sat, Nov 18, 2017 at 9:48 AM, Brody Berg wrote: > Made some changes to replaceThe to handle the possibility of empty list: > > replaceThe :: String -> String > replaceThe word = go $ words word > where > go [] = “” > go (x:xs) = > case (notThe x) of > Just x -> x ++ “ “ ++ go xs > Nothing -> “ a “ ++ go xs > > Typed this on a phone, sorry > > On Sat, Nov 18, 2017 at 09:16 Jim wrote: > >> Hey guys, >> >> Thiis is my function below: >> >> notThe :: String -> Maybe String >> notThe word >> | word /= "the" = Just word >> | word == [] = Just [] >> | otherwise = Nothing >> >> replaceThe :: String -> String >> replaceThe word = go (words word) >> where go (x:xs) >> | notThe x == Just [] = [] >> | notThe x == Just word = word ++ go xs >> | notThe word == Nothing = " a " ++ go xs >> >> >> > replaceThe "what" >> "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns >> in function go >> >> I thought I covered all the potential patterns in my replaceThe >> function. I'm not sure what pattern I've missed, any thoughts? >> >> Best regards, >> >> Jim >> >> _______________________________________________ >> 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 jeffbrown.the at gmail.com Sat Nov 18 19:15:23 2017 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 18 Nov 2017 11:15:23 -0800 Subject: [Haskell-beginners] Non-exhaustive patterns In-Reply-To: References: Message-ID: It looks like your latest version works. This also works: *Temp> let replaceThe = unwords . map (\i -> if i=="the" then "a" else i) . words *Temp> replaceThe "is the bat" "is a bat" *Temp> On Sat, Nov 18, 2017 at 10:46 AM, Brody Berg wrote: > My complete code: > > notThe :: String -> Maybe String > notThe word > | word == "the" = Nothing > | otherwise = Just word > > replaceThe :: String -> String > replaceThe word = go $ words word > where > go [] = "" > go (x:xs) = > case (notThe x) of > Just x -> x ++ " " ++ go xs > Nothing -> " a " ++ go xs > > On Sat, Nov 18, 2017 at 9:48 AM, Brody Berg wrote: > >> Made some changes to replaceThe to handle the possibility of empty list: >> >> replaceThe :: String -> String >> replaceThe word = go $ words word >> where >> go [] = “” >> go (x:xs) = >> case (notThe x) of >> Just x -> x ++ “ “ ++ go xs >> Nothing -> “ a “ ++ go xs >> >> Typed this on a phone, sorry >> >> On Sat, Nov 18, 2017 at 09:16 Jim wrote: >> >>> Hey guys, >>> >>> Thiis is my function below: >>> >>> notThe :: String -> Maybe String >>> notThe word >>> | word /= "the" = Just word >>> | word == [] = Just [] >>> | otherwise = Nothing >>> >>> replaceThe :: String -> String >>> replaceThe word = go (words word) >>> where go (x:xs) >>> | notThe x == Just [] = [] >>> | notThe x == Just word = word ++ go xs >>> | notThe word == Nothing = " a " ++ go xs >>> >>> >>> > replaceThe "what" >>> "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns >>> in function go >>> >>> I thought I covered all the potential patterns in my replaceThe >>> function. I'm not sure what pattern I've missed, any thoughts? >>> >>> Best regards, >>> >>> Jim >>> >>> _______________________________________________ >>> 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 quentin.liu.0415 at gmail.com Sat Nov 18 22:04:21 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Sat, 18 Nov 2017 17:04:21 -0500 Subject: [Haskell-beginners] Programming with Singletons In-Reply-To: References: Message-ID: Thanks a lot! Conceptually pattern matching against (Succ a) and then returning (Succ a) is equivalent to directly matching against a, but why is the compiler unable to recognize this? Regards, Qingbo Liu On Nov 17, 2017, 03:15 -0500, mukesh tiwari , wrote: > Disregard my previous mail, because I realized that your Sub is correct except (Succ a). Sorry for the confusion. New definition below > > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > type instance Sub a Zero = a > type instance Sub Zero b = Zero > type instance Sub (Succ a) (Succ b) = Sub a b > > > > On Fri, Nov 17, 2017 at 1:08 PM, mukesh tiwari wrote: > > > Changed your Sub code to this and drop works now.  You drop function > > > drop SZero     vcons        = vcons  so you are returning the second vector if first one is empty (length Zero). > > > > > > > > > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > > > type instance Sub a Zero = a > > > type instance Sub Zero     b = b > > > type instance Sub (Succ a) (Succ b) = Sub a b > > > > > > No use of Min in your code, but I changed it anyway. > > > > > > type family (Min (a :: Nat) (b :: Nat)) :: Nat > > > type instance Min Zero b = Zero > > > type instance Min a Zero = Zero > > > type instance Min (Succ a) (Succ b) = Succ (Min a b) > > > > > > I am not able to compile your tail code, so could you please paste your whole code github, or any preferred link which you like. > > > I am getting  Not in scope: type constructor or class ‘:<’ > > > > > > > > > > On Fri, Nov 17, 2017 at 12:01 PM, Quentin Liu wrote: > > > > > Thank you so much! Indeed changing the definition of `Add` helps solve the problem. > > > > > > > > > > Following this idea, I changed the definition of `Minus` and `Min` also. Now they are defined as > > > > > > > > > > > type family (Sub (a :: Nat) (b :: Nat)) :: Nat > > > > > > type instance Sub (Succ a) Zero       = Succ a > > > > > > type instance Sub Zero     b               = Zero > > > > > > type instance Sub (Succ a) (Succ b) = Sub a b > > > > > > > > > > > > type family (Min (a :: Nat) (b :: Nat)) :: Nat > > > > > > type instance Min Zero     Zero      = Zero > > > > > > type instance Min Zero     (Succ b)  = Zero > > > > > > type instance Min (Succ a) Zero      = Zero > > > > > > type instance Min (Succ a) (Succ b)  = Succ (Min a b) > > > > > > > > > > The change, however, breaks the `tail` and `drop` function. > > > > > > > > > > > drop :: SNat a -> Vec s b -> Vec s (Sub b a) > > > > > > drop SZero     vcons        = vcons > > > > > > drop (SSucc a) (VCons x xs) = drop a xs > > > > > > > > > > > > tail :: ((Zero :< a) ~ True) => Vec s a -> Vec s (Sub a (Succ Zero)) > > > > > > tail (VCons x xs) = xs > > > > > > > > > > So why does the code break and what would be the solution? The error message seems to confirm that even right now GHD still does not support type expansion. > > > > > > > > > > Regards, > > > > > Qingbo Liu > > > > > > > > > > On Nov 15, 2017, 19:51 -0500, mukesh tiwari , wrote: > > > > > > Hi Quentin, > > > > > > I changed your pattern little bit in Add function and it is working > > > > > > fine. I think the problem was that type of (VCons x xs) ++++ b is Vec > > > > > > v (Add (Succ m1) + n) which was not present in your > > > > > > Add function pattern. > > > > > > > > > > > > > > > > > > > > > > > > {-# LANGUAGE TypeFamilies #-} > > > > > > {-# LANGUAGE DataKinds #-} > > > > > > {-# LANGUAGE KindSignatures #-} > > > > > > {-# LANGUAGE GADTs #-} > > > > > > {-# LANGUAGE InstanceSigs #-} > > > > > > module Tmp where > > > > > > > > > > > > data Nat = Zero | Succ Nat > > > > > > > > > > > > data SNat a where > > > > > >   SZero :: SNat Zero > > > > > >   SSucc :: SNat a -> SNat (Succ a) > > > > > > > > > > > > data Vec a n where > > > > > >   VNil :: Vec a Zero > > > > > >   VCons :: a -> Vec a n -> Vec a (Succ n) > > > > > > > > > > > > type family (Add (a :: Nat) (b :: Nat)) :: Nat > > > > > > type instance Add Zero b = b > > > > > > type instance Add (Succ a) b = Succ (Add a b) > > > > > > > > > > > > (++++) :: Vec v m -> Vec v n -> Vec v (Add m n) > > > > > > VNil ++++ b = b > > > > > > (VCons x xs) ++++ b = VCons x $ xs ++++ b > > > > > > > > > > > > On Thu, Nov 16, 2017 at 11:21 AM, Quentin Liu > > > > > > wrote: > > > > > > > Hi all, > > > > > > > > > > > > > > I was doing the “Singletons” problem at codewars[1]. The basic idea is to > > > > > > > use dependent types to encode the length of the vector in types. > > > > > > > > > > > > > > It uses > > > > > > >  data Nat = Zero | Succ Nat > > > > > > > > > > > > > >  data SNat a where > > > > > > >   SZero :: SNat Zero > > > > > > >   SSucc :: SNat a -> SNat (Succ a) > > > > > > > to do the encoding. > > > > > > > > > > > > > > The vector is defined based on the natural number encoding: > > > > > > >  data Vec a n where > > > > > > >   VNil :: Vec a Zero > > > > > > >   VCons :: a -> Vec a n -> Vec a (Succ n) > > > > > > > > > > > > > > > > > > > > > There are some type families declared for manipulating the natural numbers, > > > > > > > and one of them that is relevant to the question is > > > > > > >  type family (Add (a :: Nat) (b :: Nat)) :: Nat > > > > > > >   type instance Add Zero b = b > > > > > > >   type instance Add a Zero = a > > > > > > >   type instance Add (Succ a) (Succ b) = Succ (Succ (Add a b)) > > > > > > > where the `Add` function adds natural numbers. > > > > > > > > > > > > > > The problem I am stuck with is the concatenation of two vectors: > > > > > > >  (++) :: Vec v m -> Vec v n -> Vec v (Add m n) > > > > > > >  VNil ++ b = b > > > > > > >  (VCons x xs) ++ b = VCons x $ xs ++ b > > > > > > > > > > > > > > The program would not compile because the compiler found that `VCons x $ xs > > > > > > > ++ b`gives type `Vec v (Succ (Add n1 n))`, which does not follow the > > > > > > > declared type `Vec v (Add m n)`. Is it because ghc does not expand `Add m n’ > > > > > > > that the type does not match? I read Brent Yorgey’s blog on type-level > > > > > > > programming[2] and he mentioned that would not automatically expand types. > > > > > > > But the posted time of the blog is 2010 and I am wondering if there is any > > > > > > > improvement to the situation since then? Besides, what would be the solution > > > > > > > to this problem > > > > > > > > > > > > > > > > > > > > > Warm Regards, > > > > > > > Qingbo Liu > > > > > > > > > > > > > > [1] https://www.codewars.com/kata/singletons/train/haskell > > > > > > > [2] > > > > > > > https://byorgey.wordpress.com/2010/07/06/typed-type-level-programming-in-haskell-part-ii-type-families/ > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > Beginners mailing list > > > > > > > Beginners at haskell.org > > > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > > > > > > _______________________________________________ > > > > > > Beginners mailing list > > > > > > Beginners at haskell.org > > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > > > _______________________________________________ > > > > > Beginners mailing list > > > > > Beginners at haskell.org > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From trent.shipley at gmail.com Tue Nov 21 06:55:57 2017 From: trent.shipley at gmail.com (trent shipley) Date: Tue, 21 Nov 2017 06:55:57 +0000 Subject: [Haskell-beginners] mail.haskell.org Archive search Message-ID: Are the Haskell mail archives searchable? If so how? Trent -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Tue Nov 21 07:32:51 2017 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 21 Nov 2017 14:32:51 +0700 Subject: [Haskell-beginners] mail.haskell.org Archive search In-Reply-To: References: Message-ID: > > Are the Haskell mail archives searchable? If so how? > Two options: 1. Leverage google's site search feature: "site:https://mail.haskell.org monads" 2. Use Nabble forum search: http://haskell.1045720.n5.nabble.com The latter also rummages through google groups not based on haskell.org. -- Kim-Ee > Trent > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From trent.shipley at gmail.com Tue Nov 21 22:49:18 2017 From: trent.shipley at gmail.com (trent shipley) Date: Tue, 21 Nov 2017 22:49:18 +0000 Subject: [Haskell-beginners] mail.haskell.org Archive search In-Reply-To: References: Message-ID: Thanks! On Tue, Nov 21, 2017 at 12:33 AM Kim-Ee Yeoh wrote: > Are the Haskell mail archives searchable? If so how? >> > > Two options: > > 1. Leverage google's site search feature: "site:https://mail.haskell.org > monads" > > 2. Use Nabble forum search: http://haskell.1045720.n5.nabble.com > > The latter also rummages through google groups not based on haskell.org. > > -- Kim-Ee > > >> Trent >> > > > -- > -- Kim-Ee > _______________________________________________ > 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 patrik.mrx at gmail.com Wed Nov 22 21:15:59 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Wed, 22 Nov 2017 22:15:59 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? Message-ID: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> Hi, I'm following the Real World Haskell book and in chapter three came across the exercise to sort a list of lists. I attach what i have so far. My question is the following. Why do i need to add "Eq a =>" to the type definition of sortListOfLists? The type of a should be irrelevant as i see it, my function couldn't care less what the type of the contents of the lists in the list are, or? All my function cares about is the length of those lists in the list. The designator a in the type declaration for sortListOfLists denote the type of the contents in the lists of lists as i understand it. So a list of lists containing object i can test for equality. Another thought i have is if i really have to specify that i expect list of lists. Couldn't that be list of something else with a length, a string perhaps, just as well? In other words a type like sortListOfLists :: a -> a. As i see it that should be just as valid as the type of what i return is the same as that which i get as input regardless of it being a list or not. -- Patrik Iselind -------------- next part -------------- A non-text attachment was scrubbed... Name: exercises.hs Type: text/x-haskell Size: 1007 bytes Desc: not available URL: From quentin.liu.0415 at gmail.com Wed Nov 22 21:40:13 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Wed, 22 Nov 2017 16:40:13 -0500 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> Message-ID: <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> Hi Patrik, The reason for the requirement of “Eq a” in your `sortListOfLists` is that you are calling myOrderFunc which carries the signature “Eq a”. If you remove the `Eq` declaration in `myOrderFunc` the compiler then would not complain about the absence of `Eq` in `sortListOfLists`. For a detailed explanation you could reference chapter 6 of Real World Haskell. Yes, you could pass the function a list of strings as well. A string is just a list of Chars. The type signature `a` does not restrict the range of types you could pass to the function. A list of lists of lists would even work. e.g. > ghci> sortListOfLists [["hello"], ["this", "is"], ["just", "a", "test”]] > [["hello"],["this","is"],["just","a","test"]] Regards, Qingbo Liu On Nov 22, 2017, 16:17 -0500, Patrik Iselind , wrote: > Hi, > > I'm following the Real World Haskell book and in chapter three came > across the exercise to sort a list of lists. I attach what i have so far. > > My question is the following. Why do i need to add "Eq a =>" to the type > definition of sortListOfLists? The type of a should be irrelevant as i > see it, my function couldn't care less what the type of the contents of > the lists in the list are, or? All my function cares about is the length > of those lists in the list. The designator a in the type declaration for > sortListOfLists denote the type of the contents in the lists of lists as > i understand it. So a list of lists containing object i can test for > equality. > > Another thought i have is if i really have to specify that i expect list > of lists. Couldn't that be list of something else with a length, a > string perhaps, just as well? In other words a type like sortListOfLists > :: a -> a. As i see it that should be just as valid as the type of what > i return is the same as that which i get as input regardless of it being > a list or not. > > -- > Patrik Iselind > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Nov 22 21:47:13 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 22 Nov 2017 22:47:13 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> Message-ID: <20171122214713.by7pw2dohlj7spyt@x60s.casa> Hello Patrik, On Wed, Nov 22, 2017 at 10:15:59PM +0100, Patrik Iselind wrote: > My question is the following. Why do i need to add "Eq a =>" to the type > definition of sortListOfLists? Like you guessed, it doesn't! Just change the signature of `myOrderFunc` to: myOrderFunc :: [a] -> [a] -> Ordering (Eq isn't needed, as the implementation shows). Remember that you can arbitrarily write more restrictive signatures than the inferred ones! It is useful to state your intent, in this case it serves no purpose, so it's correct to get rid of the `Eq` constraint. > Another thought i have is if i really have to specify that i expect list of > lists. Couldn't that be list of something else with a length, a string > perhaps, just as well? In other words a type like sortListOfLists :: a -> a. > As i see it that should be just as valid as the type of what i return is the > same as that which i get as input regardless of it being a list or not. `sortBy` signature is sortBy :: (a -> a -> Ordering) -> [a] -> [a] It demands a list of something (prelude Strings are lists too, specifically `[Char]`). That "something" is dictated by myOrderFunc (`[a]`), hence [[a]], no way around it. Was this clear? Inferring type while writing code can be a tad difficult at first, but then it becomes second nature -F From patrik.mrx at gmail.com Thu Nov 23 08:18:05 2017 From: patrik.mrx at gmail.com (mrx) Date: Thu, 23 Nov 2017 09:18:05 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> Message-ID: On Wed, Nov 22, 2017 at 10:40 PM, Quentin Liu wrote: > Hi Patrik, > > The reason for the requirement of “Eq a” in your `sortListOfLists` is that > you are calling myOrderFunc which carries the signature “Eq a”. If you > remove the `Eq` declaration in `myOrderFunc` the compiler then would not > complain about the absence of `Eq` in `sortListOfLists`. For a detailed > explanation you could reference chapter 6 of Real World Haskell. > Thanks a lot for the reference. I'll make sure to read that chapter soon. > > Yes, you could pass the function a list of strings as well. A string is > just a list of Chars. The type signature `a` does not restrict the range of > types you could pass to the function. > That seem strange to me. Wouldn't that mean that i could write the declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? GHCI give me an error on this though so obviously it's wrong. I just don't see why. Why cannot a represent [b]? // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrik.mrx at gmail.com Thu Nov 23 08:22:50 2017 From: patrik.mrx at gmail.com (mrx) Date: Thu, 23 Nov 2017 09:22:50 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <20171122214713.by7pw2dohlj7spyt@x60s.casa> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <20171122214713.by7pw2dohlj7spyt@x60s.casa> Message-ID: On Wed, Nov 22, 2017 at 10:47 PM, Francesco Ariis wrote: > Hello Patrik, > > On Wed, Nov 22, 2017 at 10:15:59PM +0100, Patrik Iselind wrote: > > My question is the following. Why do i need to add "Eq a =>" to the type > > definition of sortListOfLists? > > Like you guessed, it doesn't! Just change the signature of `myOrderFunc` > to: > > myOrderFunc :: [a] -> [a] -> Ordering > > (Eq isn't needed, as the implementation shows). > Remember that you can arbitrarily write more restrictive signatures > than the inferred ones! It is useful to state your intent, in this > case it serves no purpose, so it's correct to get rid of the `Eq` > constraint. > > > Another thought i have is if i really have to specify that i expect list > of > > lists. Couldn't that be list of something else with a length, a string > > perhaps, just as well? In other words a type like sortListOfLists :: a > -> a. > > As i see it that should be just as valid as the type of what i return is > the > > same as that which i get as input regardless of it being a list or not. > > `sortBy` signature is > > sortBy :: (a -> a -> Ordering) -> [a] -> [a] > > It demands a list of something (prelude Strings are lists too, specifically > `[Char]`). That "something" is dictated by myOrderFunc (`[a]`), hence > [[a]], no way around it. > > Was this clear? Yes please, thank you. // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From iconsize at gmail.com Thu Nov 23 17:19:51 2017 From: iconsize at gmail.com (Marcus Manning) Date: Thu, 23 Nov 2017 18:19:51 +0100 Subject: [Haskell-beginners] Multiple letters between -> -> Message-ID: <41a13638-e655-5539-f8f5-2a2dad9adab6@gmail.com> Hi, Original I thought a Signature like: f :: h a -> h a means that h is a higher kinded type just like in Type Classes ( for instance f in Functor f). But I heard such a meaning is not allowed in normal Haskell functions. What instead is the meaning of h a? Cheers, Marcus. From fa-ml at ariis.it Thu Nov 23 17:27:15 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 23 Nov 2017 18:27:15 +0100 Subject: [Haskell-beginners] Multiple letters between -> -> In-Reply-To: <41a13638-e655-5539-f8f5-2a2dad9adab6@gmail.com> References: <41a13638-e655-5539-f8f5-2a2dad9adab6@gmail.com> Message-ID: <20171123172715.cwrtywpia47o5mmz@x60s.casa> On Thu, Nov 23, 2017 at 06:19:51PM +0100, Marcus Manning wrote: > Hi, > > Original I thought a Signature like: > > f :: h a -> h a > > means that h is a higher kinded type just like in Type Classes ( for > instance f in Functor f). > > But I heard such a meaning is not allowed in normal Haskell functions. What > instead is the meaning of h a? Hello Marcus, you can write that but, since we know nothing about `h` and `a`, the only possible (non-undefined) function to implement that signature is: f :: h a -> h a f = id Any other implementation would require us to know something about h, hence a typeclass-constraint (e.g. Functor h =>) on h. From aquagnu at gmail.com Fri Nov 24 12:30:49 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 24 Nov 2017 14:30:49 +0200 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types Message-ID: <20171124143049.2cae557e@Pavel> Hello All! As I understand to use Text.Printf.printf with custom types or to return result as Text instead of String I must implement some class instances: PrintfType, PrintfArg. But how to do this if they are exported from module as type-names only - without its methods (i.e. not "Printf (..)", but "Printf") ? I tried to import Text.Printf.Internal but seems that no such submodule... Any ideas? === Best regards, Paul From timmelzer at gmail.com Fri Nov 24 12:53:55 2017 From: timmelzer at gmail.com (Norbert Melzer) Date: Fri, 24 Nov 2017 12:53:55 +0000 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: <20171124143049.2cae557e@Pavel> References: <20171124143049.2cae557e@Pavel> Message-ID: According to https://hackage.haskell.org/package/base-4.10.0.0/docs/Text-Printf.html#g:2, you only need to implement `PrintfArg`. There is also an example for `()`. Baa schrieb am Fr., 24. Nov. 2017 um 13:33 Uhr: > Hello All! > > As I understand to use Text.Printf.printf with custom types or to > return result as Text instead of String I must implement some > class instances: PrintfType, PrintfArg. But how to do this if they are > exported from module as type-names only - without its methods (i.e. not > "Printf (..)", but "Printf") ? > > I tried to import Text.Printf.Internal but seems that no such > submodule... > > Any ideas? > > === > 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 Fri Nov 24 13:19:40 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 24 Nov 2017 15:19:40 +0200 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: References: <20171124143049.2cae557e@Pavel> Message-ID: <20171124151940.2bae3550@Pavel> But how to do it if "methods" are not exporting? > According to > https://hackage.haskell.org/package/base-4.10.0.0/docs/Text-Printf.html#g:2, > you only need to implement `PrintfArg`. There is also an example for > `()`. > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 Uhr: > > > Hello All! > > > > As I understand to use Text.Printf.printf with custom types or to > > return result as Text instead of String I must implement some > > class instances: PrintfType, PrintfArg. But how to do this if they > > are exported from module as type-names only - without its methods > > (i.e. not "Printf (..)", but "Printf") ? > > > > I tried to import Text.Printf.Internal but seems that no such > > submodule... > > > > Any ideas? > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From timmelzer at gmail.com Fri Nov 24 13:23:54 2017 From: timmelzer at gmail.com (Norbert Melzer) Date: Fri, 24 Nov 2017 13:23:54 +0000 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: <20171124151940.2bae3550@Pavel> References: <20171124143049.2cae557e@Pavel> <20171124151940.2bae3550@Pavel> Message-ID: Which methods? Just doing this should be sufficient: ``` instance PrintfArg YourType where formatArg _ _ = Text.pack "It works (well, nearly)" ``` Baa schrieb am Fr., 24. Nov. 2017 um 14:20 Uhr: > But how to do it if "methods" are not exporting? > > > According to > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/Text-Printf.html#g:2 > , > > you only need to implement `PrintfArg`. There is also an example for > > `()`. > > > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 Uhr: > > > > > Hello All! > > > > > > As I understand to use Text.Printf.printf with custom types or to > > > return result as Text instead of String I must implement some > > > class instances: PrintfType, PrintfArg. But how to do this if they > > > are exported from module as type-names only - without its methods > > > (i.e. not "Printf (..)", but "Printf") ? > > > > > > I tried to import Text.Printf.Internal but seems that no such > > > submodule... > > > > > > Any ideas? > > > > > > === > > > 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 toad3k at gmail.com Fri Nov 24 13:24:54 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 24 Nov 2017 08:24:54 -0500 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: <20171124151940.2bae3550@Pavel> References: <20171124143049.2cae557e@Pavel> <20171124151940.2bae3550@Pavel> Message-ID: It appears PrintfArg and its methods are fully exported. On Fri, Nov 24, 2017 at 8:19 AM, Baa wrote: > But how to do it if "methods" are not exporting? > > > According to > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > Text-Printf.html#g:2, > > you only need to implement `PrintfArg`. There is also an example for > > `()`. > > > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 Uhr: > > > > > Hello All! > > > > > > As I understand to use Text.Printf.printf with custom types or to > > > return result as Text instead of String I must implement some > > > class instances: PrintfType, PrintfArg. But how to do this if they > > > are exported from module as type-names only - without its methods > > > (i.e. not "Printf (..)", but "Printf") ? > > > > > > I tried to import Text.Printf.Internal but seems that no such > > > submodule... > > > > > > Any ideas? > > > > > > === > > > 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 Fri Nov 24 14:07:19 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 24 Nov 2017 16:07:19 +0200 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: References: <20171124143049.2cae557e@Pavel> <20171124151940.2bae3550@Pavel> Message-ID: <20171124160719.7292469f@Pavel> I talked about PrintfType and its method `hspr`. With PrintfArgs the same problem: instance PrintfArg JobEvent where toUPrintf _ = UString "aaa" ^^^ toUPrintf is not visible ERROR here... Header of this file looks like: module Text.Printf( printf, hPrintf, PrintfType, HPrintfType, PrintfArg, IsChar ) where so methods are not exported? And I don't see any Internal subpackage... OK, no problem, I switched already to very cool `formatting` library :) Thanks a lot! > It appears PrintfArg and its methods are fully exported. > > On Fri, Nov 24, 2017 at 8:19 AM, Baa wrote: > > > But how to do it if "methods" are not exporting? > > > > > According to > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > Text-Printf.html#g:2, > > > you only need to implement `PrintfArg`. There is also an example > > > for `()`. > > > > > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 > > > Uhr: > > > > Hello All! > > > > > > > > As I understand to use Text.Printf.printf with custom types or > > > > to return result as Text instead of String I must implement some > > > > class instances: PrintfType, PrintfArg. But how to do this if > > > > they are exported from module as type-names only - without its > > > > methods (i.e. not "Printf (..)", but "Printf") ? > > > > > > > > I tried to import Text.Printf.Internal but seems that no such > > > > submodule... > > > > > > > > Any ideas? > > > > > > > > === > > > > 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 timmelzer at gmail.com Fri Nov 24 15:36:25 2017 From: timmelzer at gmail.com (Norbert Melzer) Date: Fri, 24 Nov 2017 15:36:25 +0000 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: <20171124160719.7292469f@Pavel> References: <20171124143049.2cae557e@Pavel> <20171124151940.2bae3550@Pavel> <20171124160719.7292469f@Pavel> Message-ID: PrintfArg does not have toUPrint. The functions in there are formatArg and parseFormat. PrintfType is according to its documentation, an interface that you shall not implement yourself. Baa schrieb am Fr., 24. Nov. 2017 um 15:08 Uhr: > I talked about PrintfType and its method `hspr`. > > With PrintfArgs the same problem: > > instance PrintfArg JobEvent where > toUPrintf _ = UString "aaa" > > ^^^ toUPrintf is not visible ERROR here... > > Header of this file looks like: > > module Text.Printf( > printf, hPrintf, > PrintfType, HPrintfType, PrintfArg, IsChar > ) where > > so methods are not exported? And I don't see any Internal subpackage... > OK, no problem, I switched already to very cool `formatting` library :) > > Thanks a lot! > > > > It appears PrintfArg and its methods are fully exported. > > > > On Fri, Nov 24, 2017 at 8:19 AM, Baa wrote: > > > > > But how to do it if "methods" are not exporting? > > > > > > > According to > > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > > Text-Printf.html#g:2, > > > > you only need to implement `PrintfArg`. There is also an example > > > > for `()`. > > > > > > > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 > > > > Uhr: > > > > > Hello All! > > > > > > > > > > As I understand to use Text.Printf.printf with custom types or > > > > > to return result as Text instead of String I must implement some > > > > > class instances: PrintfType, PrintfArg. But how to do this if > > > > > they are exported from module as type-names only - without its > > > > > methods (i.e. not "Printf (..)", but "Printf") ? > > > > > > > > > > I tried to import Text.Printf.Internal but seems that no such > > > > > submodule... > > > > > > > > > > Any ideas? > > > > > > > > > > === > > > > > 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 Fri Nov 24 16:23:55 2017 From: aquagnu at gmail.com (Baa) Date: Fri, 24 Nov 2017 18:23:55 +0200 Subject: [Haskell-beginners] How to use Text.Printf w/ custom types In-Reply-To: References: <20171124143049.2cae557e@Pavel> <20171124151940.2bae3550@Pavel> <20171124160719.7292469f@Pavel> Message-ID: <20171124182355.7a8b0726@Pavel> Oh, seems that it's my error! You are right. > PrintfArg does not have toUPrint. The functions in there are > formatArg and parseFormat. > > PrintfType is according to its documentation, an interface that you > shall not implement yourself. > > Baa schrieb am Fr., 24. Nov. 2017 um 15:08 Uhr: > > > I talked about PrintfType and its method `hspr`. > > > > With PrintfArgs the same problem: > > > > instance PrintfArg JobEvent where > > toUPrintf _ = UString "aaa" > > > > ^^^ toUPrintf is not visible ERROR here... > > > > Header of this file looks like: > > > > module Text.Printf( > > printf, hPrintf, > > PrintfType, HPrintfType, PrintfArg, IsChar > > ) where > > > > so methods are not exported? And I don't see any Internal > > subpackage... OK, no problem, I switched already to very cool > > `formatting` library :) > > > > Thanks a lot! > > > > > > > It appears PrintfArg and its methods are fully exported. > > > > > > On Fri, Nov 24, 2017 at 8:19 AM, Baa wrote: > > > > > > > But how to do it if "methods" are not exporting? > > > > > > > > > According to > > > > > https://hackage.haskell.org/package/base-4.10.0.0/docs/ > > > > Text-Printf.html#g:2, > > > > > you only need to implement `PrintfArg`. There is also an > > > > > example for `()`. > > > > > > > > > > Baa schrieb am Fr., 24. Nov. 2017 um 13:33 > > > > > Uhr: > > > > > > Hello All! > > > > > > > > > > > > As I understand to use Text.Printf.printf with custom types > > > > > > or to return result as Text instead of String I must > > > > > > implement some class instances: PrintfType, PrintfArg. But > > > > > > how to do this if they are exported from module as > > > > > > type-names only - without its methods (i.e. not "Printf > > > > > > (..)", but "Printf") ? > > > > > > > > > > > > I tried to import Text.Printf.Internal but seems that no > > > > > > such submodule... > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > === > > > > > > 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 quentin.liu.0415 at gmail.com Fri Nov 24 19:04:39 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Fri, 24 Nov 2017 14:04:39 -0500 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> Message-ID: <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark> > > > Yes, you could pass the function a list of strings as well. A string is just a list of Chars. The type signature `a` does not restrict the range of types you could pass to the function. > > > > That seem strange to me. Wouldn't that mean that i could write the declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? GHCI give me an error on this though so obviously it's wrong. I just don't see why. Why cannot a represent [b]? Could you copy and paste the error message here? The type signature `a` means it could be anything, `String`, `[String]`, or any ADT you could come up with. So in a type signature if you write   func :: a -> a -> a      func a b = a this funciton is telling ghc that I have a function that accepts two parameters that must be of the same type, whatever the type is. So `a` could be an ADT, a list, a list of lists, etc. But if you write   func :: a -> [b] -> a   func a bs = a you are essentially saying this function would only take two parameters of two types (`a` and `b` could be of the same type) and the second parameter must be a list. This, however, does not suggest mean that `[b]` could not be `[[String]]`, for `[String]` could just be thought of as a `b`. The way I use to think about type signature is, when you trying to substitute type variables such as `a`, substitute it into a concrete type that you are working with. Regards, Qingbo Liu On Nov 23, 2017, 03:19 -0500, mrx , wrote: > > On Wed, Nov 22, 2017 at 10:40 PM, Quentin Liu wrote: > > > Hi Patrik, > > > > > > The reason for the requirement of “Eq a” in your `sortListOfLists` is that you are calling myOrderFunc which carries the signature “Eq a”. If you remove the `Eq` declaration in `myOrderFunc` the compiler then would not complain about the absence of `Eq` in `sortListOfLists`. For a detailed explanation you could reference chapter 6 of Real World Haskell. > > > > Thanks a lot for the reference. I'll make sure to read that chapter soon. > > > > > > > > Yes, you could pass the function a list of strings as well. A string is just a list of Chars. The type signature `a` does not restrict the range of types you could pass to the function. > > > > That seem strange to me. Wouldn't that mean that i could write the declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? GHCI give me an error on this though so obviously it's wrong. I just don't see why. Why cannot a represent [b]? > > > // Patrik > _______________________________________________ > 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 patrik.mrx at gmail.com Fri Nov 24 21:32:17 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Fri, 24 Nov 2017 22:32:17 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark> Message-ID: <0b94896c-7d1f-bd65-2177-3b0f2d54a4ff@gmail.com> Den 2017-11-24 kl. 20:04, skrev Quentin Liu: > >> Yes, you could pass the function a list of strings as well. A >> string is just a list of Chars. The type signature `a` does not >> restrict the range of types you could pass to the function. >> >> That seem strange to me. Wouldn't that mean that i could write the >> declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as >> well? GHCI give me an error on this though so obviously it's wrong. I >> just don't see why. Why cannot a represent [b]? > > Could you copy and paste the error message here? Sure, the error i get follows ``` exercises.hs:33:13:     Couldn't match expected type ‘[b0]’ with actual type ‘a’       ‘a’ is a rigid type variable bound by           the type signature for myOrderFunc :: a -> a -> Ordering           at exercises.hs:31:16     Relevant bindings include       y :: a (bound at exercises.hs:32:15)       x :: a (bound at exercises.hs:32:13)       myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1)     In the first argument of ‘myLen’, namely ‘x’     In the first argument of ‘(<)’, namely ‘myLen x’ Failed, modules loaded: none. ``` Attaching the updated exercises.hs for reference. I'm still not very good at interpreting Haskell's error messages, they are quite cryptic to me. My interpretation/guess of the above is that my `a` is too 'wide' or how you express it. Haskell seem to expect some form of list. Most likely since i want a length and lists are perhaps everything in Haskell that can produce a length. I've hardly scratched the surface of what i imagine is Haskell so i cannot say anything for sure yet. > > The way I use to think about type signature is, when you trying to > substitute type variables such as `a`, substitute it into a concrete > type that you are working with. I'm having a hard time understanding your way of thinking about type signatures. Could you perhaps elaborate a bit more on it? // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: exercises.hs Type: text/x-haskell Size: 987 bytes Desc: not available URL: From iconsize at gmail.com Sat Nov 25 12:06:03 2017 From: iconsize at gmail.com (Marcus Manning) Date: Sat, 25 Nov 2017 13:06:03 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> Message-ID: -------- Forwarded Message -------- Subject: Re: [Haskell-beginners] Multiple letters between -> -> Date: Sat, 25 Nov 2017 13:05:25 +0100 From: Marcus Manning To: Francesco Ariis Sorry, for the long break. Thanks for replying. I do not believe that h is a higher kinded type. What I want to express is that a function f could take a type constructor as argument and simply returns it, but f Maybe throws an Error :13:3: error:     • Data constructor not in scope: Maybe :: h a     • Perhaps you meant variable ‘maybe’ (imported from Prelude) So what instead does h a mean in a function declaration? Cheers, Marcus. On 11/23/2017 06:27 PM, Francesco Ariis wrote: > On Thu, Nov 23, 2017 at 06:19:51PM +0100, Marcus Manning wrote: >> Hi, >> >> Original I thought a Signature like: >> >> f :: h a -> h a >> >> means that h is a higher kinded type just like in Type Classes ( for >> instance f in Functor f). >> >> But I heard such a meaning is not allowed in normal Haskell functions. What >> instead is the meaning of h a? > Hello Marcus, > you can write that but, since we know nothing about `h` and `a`, > the only possible (non-undefined) function to implement that > signature is: > > f :: h a -> h a > f = id > > Any other implementation would require us to know something about h, > hence a typeclass-constraint (e.g. Functor h =>) on h. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sat Nov 25 12:48:32 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 25 Nov 2017 13:48:32 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> Message-ID: <20171125124832.2aosbp247cp6ibgg@x60s.casa> On Sat, Nov 25, 2017 at 01:06:03PM +0100, Marcus Manning wrote: > I do not believe that h is a higher kinded type. What I want to express > is that a function f could take a type constructor as argument and > simply returns it, but > > f Maybe > > throws an Error Hello Marcus, you cannot pass type constructors (Maybe) to functions! Only *data* constructors (Just, Nothing). Hence the reason why the compiler complains, there is no *data* constructor named `Maybe`. Even in ghci, to inspect type constructors, we use a different command λ> :type Maybe :1:1: error: • Data constructor not in scope: Maybe • Perhaps you meant variable ‘maybe’ (imported from Prelude) λ> :kind Maybe Maybe :: * -> * From iconsize at gmail.com Sat Nov 25 14:03:26 2017 From: iconsize at gmail.com (Marcus Manning) Date: Sat, 25 Nov 2017 15:03:26 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <20171125124832.2aosbp247cp6ibgg@x60s.casa> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> Message-ID: Ok, but what is h in: f :: h a -> ... is "h" a data constructor or a type constructor or a normal function? What is j in f:: j k l -> ... and hwat is the difference between j and h? On 11/25/2017 01:48 PM, Francesco Ariis wrote: > On Sat, Nov 25, 2017 at 01:06:03PM +0100, Marcus Manning wrote: >> I do not believe that h is a higher kinded type. What I want to express >> is that a function f could take a type constructor as argument and >> simply returns it, but >> >> f Maybe >> >> throws an Error > Hello Marcus, > you cannot pass type constructors (Maybe) to functions! Only *data* > constructors (Just, Nothing). > Hence the reason why the compiler complains, there is no *data* constructor > named `Maybe`. Even in ghci, to inspect type constructors, we use a > different command > > λ> :type Maybe > > :1:1: error: > • Data constructor not in scope: Maybe > • Perhaps you meant variable ‘maybe’ (imported from Prelude) > λ> :kind Maybe > Maybe :: * -> * > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fa-ml at ariis.it Sat Nov 25 14:34:47 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 25 Nov 2017 15:34:47 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> Message-ID: <20171125143447.gznsf63rh6put7cq@x60s.casa> On Sat, Nov 25, 2017 at 03:03:26PM +0100, Marcus Manning wrote: > Ok, > > but what is h in: > > f :: h a -> ... > > is "h" a data constructor or a type constructor or a normal function? > What is j in > > f:: j k l -> ... > > and hwat is the difference between j and h? `h` is a type constructor and `h a` denotes a kind of `* -> *`, hence λ> :t f f :: h s -> h s λ> :t f (Just 8) f (Just 8) :: Num s => Maybe s -- because Maybe :: * -> * λ> :t f Bool :1:3: error: Data constructor not in scope: Bool :: h s Similarly, `f :: j k l -> j k l` would only work on kinds `* -> * -> *` (tuples, etc.) and not on Maybes (* -> *). From iconsize at gmail.com Sat Nov 25 15:19:04 2017 From: iconsize at gmail.com (Marcus Manning) Date: Sat, 25 Nov 2017 16:19:04 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <20171125143447.gznsf63rh6put7cq@x60s.casa> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> Message-ID: Ah thanks, I get confused with instance and declaration level. But why I can call g with Just: let g :: h a b -> h a b; g a = a g Just but Just is a->Maybe a On 11/25/2017 03:34 PM, Francesco Ariis wrote: > On Sat, Nov 25, 2017 at 03:03:26PM +0100, Marcus Manning wrote: >> Ok, >> >> but what is h in: >> >> f :: h a -> ... >> >> is "h" a data constructor or a type constructor or a normal function? >> What is j in >> >> f:: j k l -> ... >> >> and hwat is the difference between j and h? > `h` is a type constructor and `h a` denotes a kind of `* -> *`, hence > > λ> :t f > f :: h s -> h s > λ> :t f (Just 8) > f (Just 8) :: Num s => Maybe s > -- because Maybe :: * -> * > λ> :t f Bool > :1:3: error: > Data constructor not in scope: Bool :: h s > > Similarly, `f :: j k l -> j k l` would only work on kinds > `* -> * -> *` (tuples, etc.) and not on Maybes (* -> *). > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fa-ml at ariis.it Sat Nov 25 16:39:54 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 25 Nov 2017 17:39:54 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> Message-ID: <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> On Sat, Nov 25, 2017 at 04:19:04PM +0100, Marcus Manning wrote: > But why I can call g with Just: > > > let g :: h a b -> h a b; g a = a > > g Just > > but Just is a->Maybe a Because (->) is a type constructor itself, just with convenient infix syntax: λ> :k (->) (->) :: TYPE q -> TYPE r -> * From jeffbrown.the at gmail.com Sat Nov 25 17:56:50 2017 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 25 Nov 2017 09:56:50 -0800 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> Message-ID: I don't know if this is helpful, but I've abbreviated and elaborated on what Francesco said. > Original I thought a Signature like: > > f :: h a -> h a > > means that h is a higher kinded type just like in Type Classes ( for instance f in Functor f). > > But I heard such a meaning is not allowed in normal Haskell functions. What instead is the meaning of h a? Let's take a concrete example: Prelude> let f = fmap id Prelude> :t f f :: Functor f => f b -> f b Prelude> The (->) symbol goes between types (it takes one type to another), so f b must be a type, and therefore f is a type constructor. > f Maybe > > throws an Error Maybe is a type constructor, not a value constructor. Functions in Haskell can only take types. Value constructors are types; type constructors are not. > but what is h in: > > f :: h a -> ... > > is "h" a data constructor or a type constructor or a normal function? What is j in > > f:: j k l -> ... > > and hwat is the difference between j and h? h and j in those examples are both type constructors. One of them takes two arguments, the other only takes one. > But why I can call g with Just: > > > let g :: h a b -> h a b; g a = a > > g Just > > but Just is a->Maybe a Just has type "(->) a (Maybe a)", a.k.a. type "a -> Maybe a". (->) is a two-argument type constructor. On Sat, Nov 25, 2017 at 8:39 AM, Francesco Ariis wrote: > On Sat, Nov 25, 2017 at 04:19:04PM +0100, Marcus Manning wrote: > > But why I can call g with Just: > > > > > > let g :: h a b -> h a b; g a = a > > > > g Just > > > > but Just is a->Maybe a > > Because (->) is a type constructor itself, just with > convenient infix syntax: > > λ> :k (->) > (->) :: TYPE q -> TYPE r -> * > > _______________________________________________ > 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 patrik.mrx at gmail.com Sun Nov 26 13:50:30 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Sun, 26 Nov 2017 14:50:30 +0100 Subject: [Haskell-beginners] Type declarations Message-ID: Hi, What's the difference between `delta :: (Point t) => t -> t -> Double` and `delta :: Point p -> Point q -> Double`. The later one is accepted by GHCI when i do :load. As i see it the first one would make better sense to me. I want two Point as in-parameters and delta will produce a Double, but GHCI refuse this saying ``` nine.hs:10:11:     Expected a constraint, but ‘Point t’ has kind ‘*’     In the type signature for ‘delta’:       delta :: (Point t) => t -> t -> Double Failed, modules loaded: none. ``` Is this saying that Point t match 'everything' (*)? In the second version, which is accepted by GHCI, i don't see the point of p and q. Can i use these somehow? All of delta using the accepted type declaration looks like this for reference: ``` data Direction d = LEFT                 | RIGHT                 | STRAIGHT                   deriving (Show) data Point a = Coordinate Double Double              deriving (Show) -- Calculate the slope between two points (dy/dx) delta :: Point p -> Point q -> Double delta (Coordinate a b) (Coordinate c d)         | (a == c) = 0         | otherwise = (d-b)/(c-a) angle (Coordinate g h) (Coordinate i d) (Coordinate e f)         | (delta a b) > (delta b c) = RIGHT         | (delta a b) < (delta b c) = LEFT         | otherwise = STRAIGHT         where a = Coordinate g h               b = Coordinate i d               c = Coordinate e f ``` I'm also wondering if there is a simpler way than recreating the Coordinate as a, b, and c in angle. It seems to work ok to me, i just feel that a, b, and c in angle should be possible to express in a better way. -- Patrik Iselind From fa-ml at ariis.it Sun Nov 26 14:07:36 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Nov 2017 15:07:36 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: References: Message-ID: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> On Sun, Nov 26, 2017 at 02:50:30PM +0100, Patrik Iselind wrote: > Hi, > > What's the difference between `delta :: (Point t) => t -> t -> Double` and > `delta :: Point p -> Point q -> Double`. The later one is accepted by GHCI > when i do :load. Hello Patrik, `delta :: (Point t) => t -> t -> Double` means Point is a typeclass and t is an instance of a typeclass. In your case point is a datatype (data Point a etc. etc.) so the second signature is the correct one. > In the second version, which is accepted by GHCI, i don't see the point of p > and q. Can i use these somehow? `p` and `q` are the parameter of `Point a`, but since the definition of Point is: data Point a = Coordinate Double Double              deriving (Show) that `a` most likely has... no point (ueueuee pardon the pun) and would better be written as data Point = Coordinate Double Double              deriving (Show) Does this make sense? From patrik.mrx at gmail.com Sun Nov 26 18:02:36 2017 From: patrik.mrx at gmail.com (mrx) Date: Sun, 26 Nov 2017 19:02:36 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> Message-ID: Den 26 nov 2017 15:08 skrev "Francesco Ariis" : On Sun, Nov 26, 2017 at 02:50:30PM +0100, Patrik Iselind wrote: > Hi, > > What's the difference between `delta :: (Point t) => t -> t -> Double` and > `delta :: Point p -> Point q -> Double`. The later one is accepted by GHCI > when i do :load. Hello Patrik, `delta :: (Point t) => t -> t -> Double` means Point is a typeclass and t is an instance of a typeclass. In your case point is a datatype (data Point a etc. etc.) so the second signature is the correct one. > In the second version, which is accepted by GHCI, i don't see the point of p > and q. Can i use these somehow? `p` and `q` are the parameter of `Point a`, What do you mean by parameter of Point a? but since the definition of Point is: data Point a = Coordinate Double Double deriving (Show) that `a` most likely has... no point (ueueuee pardon the pun) and would better be written as data Point = Coordinate Double Double deriving (Show) Does this make sense? I think I'll have to chew that until I reach the chapter on type classes in real world haskell. Hopefully I'll get it then. Do you think it would be a mistake to simply skip writing the type declarations completely until I've reached type classes? // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun Nov 26 18:20:16 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Nov 2017 19:20:16 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> Message-ID: <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> On Sun, Nov 26, 2017 at 07:02:36PM +0100, mrx wrote: > What do you mean by parameter of Point a? Let's start with a type you probably know, Maybe: data Maybe a = Just a | Nothing The `a` in `Maybe a` is a type parameter, as the whole thing can be a `Maybe Int`, `Maybe String`, etc. Now let's check what `Point a` does data Point a = Coordinate Double Double Uhhh, suspicious, there is an `a` on the left side, but it's pretty useless, because there is no `a` on the right side. This is most likely not correct. Better to write -- this, concrete data Point = Coordinate Double Double -- or parametric data Point a = Coordinate a a > Do you think it would be a mistake to simply skip writing the type > declarations completely until I've reached type classes? As now you know how write signatures like `something :: Int -> [String]`, when you meet `Something a => etc.` tread with care until you reach the chapter on typeclasses. From patrik.mrx at gmail.com Sun Nov 26 18:39:49 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Sun, 26 Nov 2017 19:39:49 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> Message-ID: <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> Den 2017-11-26 kl. 19:20, skrev Francesco Ariis: > On Sun, Nov 26, 2017 at 07:02:36PM +0100, mrx wrote: >> What do you mean by parameter of Point a? > Let's start with a type you probably know, Maybe: > > data Maybe a = Just a > | Nothing Sorry, i've not used Maybe yet. Chapter 3 that i'm trying to get through now mention a Maybe ever so briefly. I've heard of a Maybe monad, is that it? > The `a` in `Maybe a` is a type parameter, as the whole thing can > be a `Maybe Int`, `Maybe String`, etc. > > Now let's check what `Point a` does > > data Point a = Coordinate Double Double > > Uhhh, suspicious, there is an `a` on the left side, but it's pretty > useless, because there is no `a` on the right side. This is > most likely not correct. Ah, i see. Thanks for the clarification. > Better to write > > -- this, concrete > data Point = Coordinate Double Double > -- or parametric > data Point a = Coordinate a a Does this mean that i can write `delta :: Point Double t -> Point Double t -> Direction d` as a type declaration. Then i would require `Coordinate Double Double` as in parameters. Correct? >> Do you think it would be a mistake to simply skip writing the type >> declarations completely until I've reached type classes? > As now you know how write signatures like `something :: Int -> [String]`, > when you meet `Something a => etc.` tread with care until you reach > the chapter on typeclasses. When i write type declarations, then i should stick with the non-`(Foo f) =>` version until i've reached that chapter on type classes. It's stilla few chapters until i reach it, i'm on chapter 3 and type classes are chapter 6. // Patrik From quentin.liu.0415 at gmail.com Sun Nov 26 19:48:22 2017 From: quentin.liu.0415 at gmail.com (Quentin Liu) Date: Sun, 26 Nov 2017 14:48:22 -0500 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <0b94896c-7d1f-bd65-2177-3b0f2d54a4ff@gmail.com> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark> <0b94896c-7d1f-bd65-2177-3b0f2d54a4ff@gmail.com> Message-ID: <883dc5c3-2c67-4c9c-a71a-cab090337426@Spark> > ``` > exercises.hs:33:13: >     Couldn't match expected type ‘[b0]’ with actual type ‘a’ >       ‘a’ is a rigid type variable bound by >           the type signature for myOrderFunc :: a -> a -> Ordering >           at exercises.hs:31:16 >     Relevant bindings include >       y :: a (bound at exercises.hs:32:15) >       x :: a (bound at exercises.hs:32:13) >       myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1) >     In the first argument of ‘myLen’, namely ‘x’ >     In the first argument of ‘(<)’, namely ‘myLen x’ > Failed, modules loaded: none. > ``` Your guess is correct. The problem is, Haskell does not consider `a` in `myOrderFunc` and `[b]` in `myLen` equivalent. `a` means you feed the function any type, while `[b]` means it must be a list of values of the same type. So changing `a` to `[a]` woud eliminate the error. Regards, Qingbo Liu On Nov 24, 2017, 16:33 -0500, Patrik Iselind , wrote: > > Den 2017-11-24 kl. 20:04, skrev Quentin Liu: > > > > > > > Yes, you could pass the function a list of strings as well. A string is just a list of Chars. The type signature `a` does not restrict the range of types you could pass to the function. > > > > > > > > That seem strange to me. Wouldn't that mean that i could write the declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well? GHCI give me an error on this though so obviously it's wrong. I just don't see why. Why cannot a represent [b]? > > > > Could you copy and paste the error message here? > Sure, the error i get follows > ``` > exercises.hs:33:13: >     Couldn't match expected type ‘[b0]’ with actual type ‘a’ >       ‘a’ is a rigid type variable bound by >           the type signature for myOrderFunc :: a -> a -> Ordering >           at exercises.hs:31:16 >     Relevant bindings include >       y :: a (bound at exercises.hs:32:15) >       x :: a (bound at exercises.hs:32:13) >       myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1) >     In the first argument of ‘myLen’, namely ‘x’ >     In the first argument of ‘(<)’, namely ‘myLen x’ > Failed, modules loaded: none. > ``` > Attaching the updated exercises.hs for reference. > > I'm still not very good at interpreting Haskell's error messages, they are quite cryptic to me. My interpretation/guess of the above is that my `a` is too 'wide' or how you express it. Haskell seem to expect some form of list. Most likely since i want a length and lists are perhaps everything in Haskell that can produce a length. I've hardly scratched the surface of what i imagine is Haskell so i cannot say anything for sure yet. > > > > > The way I use to think about type signature is, when you trying to substitute type variables such as `a`, substitute it into a concrete type that you are working with. > I'm having a hard time understanding your way of thinking about type signatures. Could you perhaps elaborate a bit more on it? > > // Patrik > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun Nov 26 20:24:01 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Nov 2017 21:24:01 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> Message-ID: <20171126202401.jppfe6tmm67lflwh@x60s.casa> On Sun, Nov 26, 2017 at 07:39:49PM +0100, Patrik Iselind wrote: > Does this mean that i can write `delta :: Point Double t -> Point Double t > -> Direction d` as a type declaration. Then i would require `Coordinate > Double Double` as in parameters. Correct? Careful there! Let's take a simple data declaration data Point = Point Int Float On the right you have *the type*, on the left you have *the (data) constructor*. When you are writing signatures you are writing types, so f :: Point -> Point and not f :: Point Int Float -> Point Int Float Much like you write `addition :: Int -> Int -> Int` and not `addition :: 7 -> 2 -> 9`. From patrik.mrx at gmail.com Sun Nov 26 21:21:39 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Sun, 26 Nov 2017 22:21:39 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <20171126202401.jppfe6tmm67lflwh@x60s.casa> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> <20171126202401.jppfe6tmm67lflwh@x60s.casa> Message-ID: Den 2017-11-26 kl. 21:24, skrev Francesco Ariis: > On Sun, Nov 26, 2017 at 07:39:49PM +0100, Patrik Iselind wrote: >> Does this mean that i can write `delta :: Point Double t -> Point Double t >> -> Direction d` as a type declaration. Then i would require `Coordinate >> Double Double` as in parameters. Correct? > Careful there! Let's take a simple data declaration > > data Point = Point Int Float > > On the right you have *the type*, on the left you have *the (data) > constructor*. But if the type Point have a parameter, `data Point p = Coordinate p p`. Then i must be able to tell which `p` when i use Point in a type declaration right? Like `delta :: Point Double a -> Point Double b -> Double` would say that p is Double. How else am i supposed to specify p in type declaration? // Patrik From fa-ml at ariis.it Sun Nov 26 21:41:35 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Nov 2017 22:41:35 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> <20171126202401.jppfe6tmm67lflwh@x60s.casa> Message-ID: <20171126214135.732pblhx4ouym6fb@x60s.casa> On Sun, Nov 26, 2017 at 10:21:39PM +0100, Patrik Iselind wrote: > But if the type Point have a parameter, `data Point p = Coordinate p p`. > Then i must be able to tell which `p` when i use Point in a type declaration > right? Like `delta :: Point Double a -> Point Double b -> Double` would say > that p is Double. How else am i supposed to specify p in type declaration? If the type has a parameter, like data Point a = Coordinates a a it will specified *once* in the signature, like this: f :: Point Double -> Point Double -> String implementation looking something like f (Coordinates x y) (Coordinates m q) = x + 7 -- etc. etc. From patrik.mrx at gmail.com Sun Nov 26 21:46:29 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Sun, 26 Nov 2017 22:46:29 +0100 Subject: [Haskell-beginners] Why do i need to specify the class of a here at all? In-Reply-To: <883dc5c3-2c67-4c9c-a71a-cab090337426@Spark> References: <2132becd-3108-7048-35cd-802c143fb98f@gmail.com> <63573bd3-f846-419d-af36-c8e2c9bae0e3@Spark> <5fdec6dc-aeb8-4083-9782-114c0c1c8b6c@Spark> <0b94896c-7d1f-bd65-2177-3b0f2d54a4ff@gmail.com> <883dc5c3-2c67-4c9c-a71a-cab090337426@Spark> Message-ID: <3baa5db0-8901-0029-1366-eb06e2359488@gmail.com> Den 2017-11-26 kl. 20:48, skrev Quentin Liu: >> ``` >> exercises.hs:33:13: >>     Couldn't match expected type ‘[b0]’ with actual type ‘a’ >>       ‘a’ is a rigid type variable bound by >>           the type signature for myOrderFunc :: a -> a -> Ordering >>           at exercises.hs:31:16 >>     Relevant bindings include >>       y :: a (bound at exercises.hs:32:15) >>       x :: a (bound at exercises.hs:32:13) >>       myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1) >>     In the first argument of ‘myLen’, namely ‘x’ >>     In the first argument of ‘(<)’, namely ‘myLen x’ >> Failed, modules loaded: none. >> ``` > > Your guess is correct. The problem is, Haskell does not consider `a` > in `myOrderFunc` and `[b]` in `myLen` equivalent. `a` means you feed > the function any type, while `[b]` means it must be a list of values > of the same type. So changing `a` to `[a]` woud eliminate the error. Thanks a lot for the clarification. // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrik.mrx at gmail.com Sun Nov 26 21:51:26 2017 From: patrik.mrx at gmail.com (Patrik Iselind) Date: Sun, 26 Nov 2017 22:51:26 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <20171126214135.732pblhx4ouym6fb@x60s.casa> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> <20171126202401.jppfe6tmm67lflwh@x60s.casa> <20171126214135.732pblhx4ouym6fb@x60s.casa> Message-ID: Patrik Iselind Den 2017-11-26 kl. 22:41, skrev Francesco Ariis: > On Sun, Nov 26, 2017 at 10:21:39PM +0100, Patrik Iselind wrote: >> But if the type Point have a parameter, `data Point p = Coordinate p p`. >> Then i must be able to tell which `p` when i use Point in a type declaration >> right? Like `delta :: Point Double a -> Point Double b -> Double` would say >> that p is Double. How else am i supposed to specify p in type declaration? > If the type has a parameter, like > > data Point a = Coordinates a a > > it will specified *once* in the signature, like this: > > f :: Point Double -> Point Double -> String So what you're saying is that the `a` and `b` characters in my examples should not be there. Other than that it's correct? // Patrik From fa-ml at ariis.it Sun Nov 26 22:31:05 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 26 Nov 2017 23:31:05 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> <20171126202401.jppfe6tmm67lflwh@x60s.casa> <20171126214135.732pblhx4ouym6fb@x60s.casa> Message-ID: <20171126223104.btdjdyinmdvgpeia@x60s.casa> On Sun, Nov 26, 2017 at 10:51:26PM +0100, Patrik Iselind wrote: > So what you're saying is that the `a` and `b` characters in my examples > should not be there. Other than that it's correct? Indeed :) From patrik.mrx at gmail.com Mon Nov 27 08:01:19 2017 From: patrik.mrx at gmail.com (mrx) Date: Mon, 27 Nov 2017 09:01:19 +0100 Subject: [Haskell-beginners] Type declarations In-Reply-To: <20171126223104.btdjdyinmdvgpeia@x60s.casa> References: <20171126140736.gnpice6l3qa7h7ge@x60s.casa> <20171126182016.q3aqfnmcd5a5zlvr@x60s.casa> <74ddf555-9c14-cd18-5c0d-1b3062efc4c7@gmail.com> <20171126202401.jppfe6tmm67lflwh@x60s.casa> <20171126214135.732pblhx4ouym6fb@x60s.casa> <20171126223104.btdjdyinmdvgpeia@x60s.casa> Message-ID: Den 26 nov 2017 23:32 skrev "Francesco Ariis" : On Sun, Nov 26, 2017 at 10:51:26PM +0100, Patrik Iselind wrote: > So what you're saying is that the `a` and `b` characters in my examples > should not be there. Other than that it's correct? Indeed :) Awesome, thanks a lot! // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From iconsize at gmail.com Thu Nov 30 11:37:12 2017 From: iconsize at gmail.com (Marcus Manning) Date: Thu, 30 Nov 2017 12:37:12 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> Message-ID: <08469b21-975c-f0e5-3911-ea1459cc9580@gmail.com> Sorry again fo the long break, and thanks for explanation. Three Questions: 1.) Because (->) is defined with itself, it is also a Meta Type Constructor (TYPE == variable Rank Type == a Meta Type ?) 2.) How do I define a function which takes a 3-Kinded Type: let f:: h (g a); f a = a where g * -> * and h (*->*)->*, but it did not work as: h is deduced to be h * -> *. Prelude> let f:: h (g a); f a = a :42:18: error:     • Couldn't match type ‘h’ with ‘(->) (g a)’       ‘h’ is a rigid type variable bound by         the type signature for:           f :: forall (h :: * -> *) (g :: * -> *) a. h (g a)         at :42:5-15       Expected type: h (g a)         Actual type: g a -> g a     • The equation(s) for ‘f’ have one argument,       but its type ‘h (g a)’ has none     • Relevant bindings include         f :: h (g a) (bound at :42:18) What can I do? 3.) Is there any tool in Haskel where I can see which function parameter is bound to the given input, for instance something like a function showBinds: showBinds const (\c -> "s") (\(b,c) -> "c") Prelude> Param a gets (\c -> "s")                            b gets (\(b,c) -> "c") This is a simple example, but it gets more complicated with massive use of autocurrying. On 11/25/2017 05:39 PM, Francesco Ariis wrote: > On Sat, Nov 25, 2017 at 04:19:04PM +0100, Marcus Manning wrote: >> But why I can call g with Just: >> >> >> let g :: h a b -> h a b; g a = a >> >> g Just >> >> but Just is a->Maybe a > Because (->) is a type constructor itself, just with > convenient infix syntax: > > λ> :k (->) > (->) :: TYPE q -> TYPE r -> * > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Nov 30 11:49:10 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 30 Nov 2017 12:49:10 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <08469b21-975c-f0e5-3911-ea1459cc9580@gmail.com> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> <08469b21-975c-f0e5-3911-ea1459cc9580@gmail.com> Message-ID: <20171130114910.2m6c6yzlyegodsyj@x60s.casa> Hello Marcus, On Thu, Nov 30, 2017 at 12:37:12PM +0100, Marcus Manning wrote: > 2.) How do I define a function which takes a 3-Kinded Type: > > let f:: h (g a); f a = a > > where g * -> * and h (*->*)->*, but it did not work as: > > h is deduced to be h * -> *. h hasn't got kind * -> * -> *, as Maybe hasn't got kind * -> * -> * but * -> *. A simple type constructor like the one you are searching for is Either λ> :k Either Either :: * -> * -> * or a tuple λ> :k (,) (,) :: * -> * -> * From aquagnu at gmail.com Thu Nov 30 12:08:28 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 30 Nov 2017 14:08:28 +0200 Subject: [Haskell-beginners] How to parse hetero-list Message-ID: <20171130140828.6404b219@Pavel> Hello, All! I have types A, B, C... They have instances of class Read, Show, SomethingElse, ... I want to keep them as one collection. For example, I can use such datatype for it: data Tags = forall a. Read a => Tags [a] Now I want to parse "some-string" into A or B or C or ... but without to create type's sum of A|B|C|...! All those types have `Read` instance but Haskell will not find what instance to use, right? How to parse string with alternatives where each alternative returns `ReadP A` or `ReadP B`, etc? My intuition is that I should make `x <|> y <|> z <|> ...` where x,y,z - parses string into A, B, C, ... so they are expressions like `readPrec :: ReadPrec A`, etc. But how to pass types into such expression? I must to make expression folding (with `<|>`) `readPrec::someType`, where `someType` is item of types list `{A, B, C, ...}` May be it's possible to be done with HList-like types, like: HSet, HVect or similar, but I don't know: - how to iterate/fold over types - I'm not sure that HSet/HVect keeps types (like `A ::: B ::: C ::: ...`) My idea is to have some function which can parse string into one of A|B|C|... with call like: myParse "some-string" :: (Something A ::: B ::: C ::: D) (suppose `:::` is type-level "cons"). So, `myParse` is polymorphic and it can fold/iterate over type-list items (to call appropriate `readPrec`). Is it even possible? In languages with reflection I can pass list of types (type - is usual value) and call type's methods, but how to solve similar in Haskell? === Best regards, Paul From fa-ml at ariis.it Thu Nov 30 12:13:11 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 30 Nov 2017 13:13:11 +0100 Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> In-Reply-To: <8ddc9c31-897a-3125-351e-90dc1a7c6202@gmail.com> References: <60e30e28-89c8-3cf0-b515-b6b8405a64ed@gmail.com> <20171125124832.2aosbp247cp6ibgg@x60s.casa> <20171125143447.gznsf63rh6put7cq@x60s.casa> <20171125163954.5rlpyxcxxxjmzbyc@x60s.casa> <08469b21-975c-f0e5-3911-ea1459cc9580@gmail.com> <20171130114910.2m6c6yzlyegodsyj@x60s.casa> <8ddc9c31-897a-3125-351e-90dc1a7c6202@gmail.com> Message-ID: <20171130121311.5r4wgg3rseuom4nw@x60s.casa> On Thu, Nov 30, 2017 at 12:55:07PM +0100, Marcus Manning wrote: > But Either is not (*->*)->*, instead it is *->(*->*). Is (*->*)->* > expressable in Haskell functions? Yes, with an appropriate data declaration: λ> data FooType a = FooCons (a Int) λ> :k FooType FooType :: (* -> *) -> * From aquagnu at gmail.com Thu Nov 30 13:03:18 2017 From: aquagnu at gmail.com (Baa) Date: Thu, 30 Nov 2017 15:03:18 +0200 Subject: [Haskell-beginners] How to parse hetero-list In-Reply-To: <20171130140828.6404b219@Pavel> References: <20171130140828.6404b219@Pavel> Message-ID: <20171130150318.59f366cb@Pavel> Hmm, I done it with: infixl 9 ||| data a ||| b = A a|B b deriving Show instance (Read a, Read b) => Read (a ||| b) where readPrec = parens $ do a <- (A <$> readPrec) <|> (B <$> readPrec) return a so parse looks like: read "1" :: Int ||| Char ||| String but I'm not sure is other more classical way to do it... > Hello, All! > > I have types A, B, C... They have instances of class Read, Show, > SomethingElse, ... I want to keep them as one collection. For example, > I can use such datatype for it: > > data Tags = forall a. Read a => Tags [a] > > Now I want to parse "some-string" into A or B or C or ... but without > to create type's sum of A|B|C|...! All those types have `Read` > instance but Haskell will not find what instance to use, right? How > to parse string with alternatives where each alternative returns > `ReadP A` or `ReadP B`, etc? My intuition is that I should make `x > <|> y <|> z <|> ...` where x,y,z - parses string into A, B, C, ... so > they are expressions like `readPrec :: ReadPrec A`, etc. But how to > pass types into such expression? I must to make expression folding > (with `<|>`) `readPrec::someType`, where `someType` is item of types > list `{A, B, C, ...}` > > May be it's possible to be done with HList-like types, like: HSet, > HVect or similar, but I don't know: > > - how to iterate/fold over types > - I'm not sure that HSet/HVect keeps types (like `A ::: B ::: > C ::: ...`) > > My idea is to have some function which can parse string into one of > A|B|C|... with call like: > > myParse "some-string" :: (Something A ::: B ::: C ::: D) > > (suppose `:::` is type-level "cons"). So, `myParse` is polymorphic and > it can fold/iterate over type-list items (to call appropriate > `readPrec`). > > Is it even possible? > > In languages with reflection I can pass list of types (type - is usual > value) and call type's methods, but how to solve similar in Haskell? > > === > Best regards, Paul From 122234942 at qq.com Thu Nov 30 13:18:46 2017 From: 122234942 at qq.com (=?gb18030?B?UmF5?=) Date: Thu, 30 Nov 2017 21:18:46 +0800 Subject: [Haskell-beginners] how to undertand the function join (*) Message-ID: Hello Marcus, what does join (*) do? (*) :: Num a => a -> a -> a join (*) :: Num a => a -> a when we feed a number to join (*),for instance; λ> : join (*) 3 9 it seems thata join (*) become a square function. what does join do to (*) to make that happen? -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Thu Nov 30 13:47:37 2017 From: raabe at froglogic.com (Frerich Raabe) Date: Thu, 30 Nov 2017 14:47:37 +0100 Subject: [Haskell-beginners] how to undertand the function join (*) In-Reply-To: References: Message-ID: On 2017-11-30 14:18, Ray wrote: > what does JOIN (*) do? > > (*) :: Num a => a -> a -> a > > join (*) :: Num a => a -> a > > when we feed a number to join (*),for instance; > > λ> : join (*) 3 > > 9 > > it seems thata JOIN (*) become a square function. > > what does JOIN do to (*) to make that happen? You can figure it out by using equational reasoning and evaluating the expression manually: join (*) 3 Function application is left-associative, so this is equivalent to (join (*)) 3 The 'join' function is defined as (http://hackage.haskell.org/package/base-4.10.0.0/docs/src/GHC.Base.html#join) join x = x >>= id So we can replace 'join (*)' in our above expression with ((*) >>= id) 3 (>>=) for functions is defined as f >>= k = \ r -> k (f r) r So with that at hand, we get (\r -> id ((*) r) r) 3 'id x' is just 'x', so we get (\r -> (*) r r) 3 With infix syntax, this can be written as (\r -> r * r) 3 If you now apply that function, you get 3 * 3 Which gives your result '9'. -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing