Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. about kind of (->) (Song Zhang) 2. Re: about kind of (->) (Ertugrul S?ylemez) 3. IO - getContents - putStrLn (Robert Heum?ller) 4. Re: IO - getContents - putStrLn (Tobias Brandt) 5. Re: IO - getContents - putStrLn (Michael Orlitzky) 6. Re: IO - getContents - putStrLn (Brandon Allbery) 7. Simplify (normalize) symbolic polynom-like expression (Daniel Hlynskyi) 8. Re: Simplify (normalize) symbolic polynom-like expression (M?t? Kov?cs) 9. problem with type (miro) ---------------------------------------------------------------------- Message: 1 Date: Sat, 16 Jun 2012 22:25:08 +0800 From: Song Zhang <vxan...@gmail.com> Subject: [Haskell-beginners] about kind of (->) To: beginners@haskell.org Message-ID: <CACGMEOk6Xcn8J+4KhU1fKh=qyu8t-kebp0j7fo-0x-n9t-l...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" a function has also a kind. According to haskell report 2010 4.1.2 it is * -> * -> *, which is easy to understand. However in ghci I type :k (->). the output is ?? -> ? -> *. I want to know what do ?? and ? mean. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120616/ab48d400/attachment-0001.htm> ------------------------------ Message: 2 Date: Sat, 16 Jun 2012 16:43:10 +0200 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] about kind of (->) To: beginners@haskell.org Message-ID: <20120616164310.1b177...@tritium.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Song Zhang <vxan...@gmail.com> wrote: > a function has also a kind. According to haskell report 2010 4.1.2 it > is * -> * -> *, which is easy to understand. However in ghci I type :k > (->). the output is ?? -> ? -> *. I want to know what do ?? and ? > mean. Thanks This has to do with primitive types like Int#. It basically says that the input type can be a primitive type, and if it is, then the output type must also be primitive. In fact since GHC 7.4 (or perhaps earlier) the kind is * -> * -> * as expected. Greets, Ertugrul -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120616/8f2973a5/attachment-0001.pgp> ------------------------------ Message: 3 Date: Sat, 16 Jun 2012 20:03:36 +0200 From: Robert Heum?ller <mail...@heum.de> Subject: [Haskell-beginners] IO - getContents - putStrLn To: beginners@haskell.org Message-ID: <20120616200336.7bd388cd@thor> Content-Type: text/plain; charset=US-ASCII Hi, this is probably an easy question, but i simply can't figure out, why this does not work: import Data.Char main = do contents <- getContents putStrLn $ show $ splitcomma contents splitcomma = split ',' split :: Char -> String -> [String] split _ "" = [""] split sp (c:cs) | c == sp = "": rest | otherwise = (c : head rest) : tail rest where rest = split sp cs The program compiles and runs without any problems. But there is absolutely no output, when f.eg. i type "hello, world" and hit return. Why would that be? Thank you very much ------------------------------ Message: 4 Date: Sat, 16 Jun 2012 20:10:01 +0200 From: Tobias Brandt <tob.bra...@googlemail.com> Subject: Re: [Haskell-beginners] IO - getContents - putStrLn To: Robert Heum?ller <mail...@heum.de> Cc: beginners@haskell.org Message-ID: <caoowqir7cubjgtwmcixpf9lrm6hrb6zb0gbgivebtt-esqi...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On 16 June 2012 20:03, Robert Heum?ller <mail...@heum.de> wrote: > The program compiles and runs without any problems. But there is > absolutely no output, when f.eg. i type "hello, world" and hit return. > Why would that be? getContents reads the entire input to the program. Under Linux you can terminate input with Ctrl-D. If you want to only read a single line, use getLine. ------------------------------ Message: 5 Date: Sat, 16 Jun 2012 14:10:55 -0400 From: Michael Orlitzky <mich...@orlitzky.com> Subject: Re: [Haskell-beginners] IO - getContents - putStrLn To: beginners@haskell.org Message-ID: <4fdccc2f.4090...@orlitzky.com> Content-Type: text/plain; charset=ISO-8859-1 On 06/16/12 14:03, Robert Heum?ller wrote: > Hi, > > this is probably an easy question, but i simply can't figure out, why > this does not work: > > ... > > The program compiles and runs without any problems. But there is > absolutely no output, when f.eg. i type "hello, world" and hit return. > Why would that be? > "Return" doesn't end the input. Try Control-D, which should work on Linux at least (it send end-of-file). $ runhaskell test.hs hello, world <ctrl+d> ["hello"," world\n"] ------------------------------ Message: 6 Date: Sat, 16 Jun 2012 14:24:56 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] IO - getContents - putStrLn To: Robert Heum?ller <mail...@heum.de> Cc: beginners@haskell.org Message-ID: <CAKFCL4VS0d9dBqcM-TDH=t5o2e+33_nf7zkyhpwihtvvpo-...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Sat, Jun 16, 2012 at 2:03 PM, Robert Heum?ller <mail...@heum.de> wrote: > The program compiles and runs without any problems. But there is > absolutely no output, when f.eg. i type "hello, world" and hit return. > Why would that be? > At a guess, your "split" is too strict and requires the entire input in order to do anything, so you'd need control-D on Unix or control-Z on Windows to mark the end of the input stream. You might prefer to use the functions from the "split" package on Hackage (cabal install split) which are appropriately lazy. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120616/7009e89c/attachment-0001.htm> ------------------------------ Message: 7 Date: Sun, 17 Jun 2012 00:17:11 +0300 From: Daniel Hlynskyi <abcz2.upr...@gmail.com> Subject: [Haskell-beginners] Simplify (normalize) symbolic polynom-like expression To: beginners@haskell.org Message-ID: <canzg+yfl6vbdq5wu80icj5cawssvkwr4xz8q62xyt0r_opj...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Hello. I am new to typefull programming, so I've got a question. I have a simple mathematical expression (addition, product and exponentiation only): > data Expr =?I Int -- integer constant > ? ? ? ? ? | V -- symbolic variable > ? ? ? ? ? | Sum [Expr] > ? ? ? ? ? | Prod [Expr] > ? ? ? ? ? | Pow Expr Expr What I want is normalize\simplify this expression. Eg `Prod [Pow V (I 0), Pow V (I 1)] ` must be simplified to just `V`. What techniques should I use to write `normalize` function? Simplification rules are quite simple: > normalize (Sum [a]) = normalize a > normalize (Sum xs) | (I 0) `elem` xs = map nomalize . Sum $ filter (/= I 0) xs > ? ? ? ? ? ? ? ? ? ? ? ? ?| otherwise = map normalize xs > normalize (Prod xs) | (I 0) `elem` xs = I 0 > normalize (Prod xs) | (I 1) `elem` xs = map nomalize . Prod $ filter (/= I 1) > xs > ? ? ? ? ? ? ? ? ? ? ? ? ?| otherwise = map normalize xs > normalize (Pow a (I 0)) = I 1 > normalize (Pow a (I 1)) = normalize a and so on. But rules like theese cannot simplify some expressions, for example, `Prod [Pow V (I 0), Pow V (I 1)] `. ------------------------------ Message: 8 Date: Sat, 16 Jun 2012 15:36:38 -0700 From: M?t? Kov?cs <mkov...@gmail.com> Subject: Re: [Haskell-beginners] Simplify (normalize) symbolic polynom-like expression To: Daniel Hlynskyi <abcz2.upr...@gmail.com> Cc: beginners@haskell.org Message-ID: <CAK4MsdrmLYhqnPoGsZbuXQ=rundwbnjcwksu4ng12cbf0zy...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi Daniel, It depends on what you want to use the normalized / canonical form for. If it's to reduce semantic equivalence testing to simple syntactic equality, e.g. (A == B) = (canonize(A) == canonize(B)), then you could just use the fully expanded form, which isn't really simplification. :) I'm doing something similar here (for polynomial expressions over an inner product space): https://github.com/mkovacs/ipoly/blob/master/Poly.hs Cheers, M?t? On Sat, Jun 16, 2012 at 2:17 PM, Daniel Hlynskyi <abcz2.upr...@gmail.com> wrote: > Hello. > > I am new to typefull programming, so I've got a question. > I have a simple mathematical expression (addition, product and > exponentiation only): > >> data Expr =?I Int -- integer constant >> ? ? ? ? ? | V -- symbolic variable >> ? ? ? ? ? | Sum [Expr] >> ? ? ? ? ? | Prod [Expr] >> ? ? ? ? ? | Pow Expr Expr > > What I want is normalize\simplify this expression. Eg `Prod [Pow V (I > 0), Pow V (I 1)] ` must be simplified to just `V`. What techniques > should I use to write `normalize` function? > Simplification rules are quite simple: > >> normalize (Sum [a]) = normalize a >> normalize (Sum xs) | (I 0) `elem` xs = map nomalize . Sum $ filter (/= I 0) >> xs >> ? ? ? ? ? ? ? ? ? ? ? ? ?| otherwise = map normalize xs >> normalize (Prod xs) | (I 0) `elem` xs = I 0 >> normalize (Prod xs) | (I 1) `elem` xs = map nomalize . Prod $ filter (/= I >> 1) xs >> ? ? ? ? ? ? ? ? ? ? ? ? ?| otherwise = map normalize xs >> normalize (Pow a (I 0)) = I 1 >> normalize (Pow a (I 1)) = normalize a > > and so on. But rules like theese cannot simplify some expressions, for > example, `Prod [Pow V (I 0), Pow V (I 1)] `. > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 9 Date: Sun, 17 Jun 2012 02:39:51 +0200 From: miro <miroslav.kar...@gmail.com> Subject: [Haskell-beginners] problem with type To: beginners@haskell.org Message-ID: <4fdd2757.2090...@gmail.com> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Am a bit stuck here,... please, what is wrong with this? checkNode :: String -> [String] -> Bool checkNode s nodes = [s == node | node <- nodes ] src/me.hs:3:4: Couldn't match expected type `Bool' with actual type `[t0]' [1 of 1] Compiling Main ( src/me.hs, interpreted ) In the expression: [s == node | node <- nodes] Failed, modules loaded: none. In an equation for `checkNode': checkNode s nodes = [s == node | node <- nodes] thanks, Miro -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120617/08a1e052/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 48, Issue 21 *****************************************