jaberwacky Posted August 6, 2015 Share Posted August 6, 2015 (edited) This thread is intended to document my progress and small epiphanies as I learn this strange and wonderful language.So I'm following this tutorial: https://en.wikibooks.org/wiki/Yet_Another_Haskell_Tutorial which has been awesome so farI came across the following exercise:Define a recursive function mult that takes two positive integers a and b and returns a*b, but only uses addition (i.e., no fair just using multiplication). Begin by making a mathematical definition in the style of the previous exercise and the rest of this section.And I solved it! I know. I know. Big whoop. It's great for me as someone who started out as a non-math type. The solution I came up with isn't exactly like the official solution though, but it seems to work.rec a 0 = 0 rec a b = a + (rec a (b - 1)) Edited August 14, 2015 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jvanegmond Posted August 7, 2015 Share Posted August 7, 2015 Why did you pick Haskell as the next language to learn? github.com/jvanegmond Link to comment Share on other sites More sharing options...
jaberwacky Posted August 7, 2015 Author Share Posted August 7, 2015 Honestly being such a functional programming newb, I don't know exactly. I guess mostly because there are a lot of tutorials and other resources based on Haskell. I also see the syntax as being the most simple at this point. I could very well change from Haskell to something else as I learn. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted August 10, 2015 Author Share Posted August 10, 2015 (edited) FINALLY! After much hair pulling, forehead smashing, and crying I finally hacked up this haskell program that takes a sentence that the user enters and then reverses the inner letters of each word. For instance this sentence, "Why did you pick Haskell as the next language to learn" becomes this, "Why did you pcik Hleksal as the nxet lgaugnae to lraen".I'm so relieved. I can sleep now.expandcollapse popupmodule Main where import System.IO main = do hSetBuffering stdin LineBuffering main_rec main_rec = do putStrLn "Enter a sentence: " sentence <- getLine if toLower sentence == "exit" then do print "Bye!" else do let word_list = words sentence let scrambled = map thaScrambla word_list print scrambled main_rec -- Designed to scramble your internals. thaScrambla :: [Char] -> [Char] thaScrambla word | length word > 3 = [head word] ++ (reverse $ tail $ init word) ++ [last word] | otherwise = word toLower :: [Char] -> [Char] toLower word | word == "Exit" = "exit" | otherwise = wordexpandcollapse popupmodule Main where import System.IO main = do hSetBuffering stdin LineBuffering main_rec main_rec = do putStrLn "Enter a sentence: " sentence <- getLine if toLower sentence == "exit" then do print "Bye!" else do let word_list = words sentence let scrambled = map thaScrambla word_list print scrambled main_rec thaScrambla :: [Char] -> [Char] thaScrambla word = do if length word > 3 then do [head word] ++ (reverse $ tail $ init word) ++ [last word] else word toLower :: [Char] -> [Char] toLower "Exit" = "exit" toLower x = xmodule Main where import System.IO main = do hSetBuffering stdin LineBuffering putStrLn "Enter a sentence: " sentence <- getLine let word_list = words sentence let scrambled = map thaScrambla word_list print scrambled thaScrambla word = do if length word > 3 then do [head word] ++ reverse (tail (init word)) ++ [last word] else wordBizarro World: FLLANIY Aetfr mcuh hiar pnillug faeherod snihsamg and cniyrg I fllaniy hekcad up tihs hleksal pargorm taht tekas a scnetnee taht the uesr eretns and tehn resreves the iennr lrettes of ecah wrod Edited August 14, 2015 by jaberwacky better code Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jvanegmond Posted August 12, 2015 Share Posted August 12, 2015 I've always wanted to learn a pure functional language (seewhatididthere). Right now I just sprinkle the functional stuff on my imperative programs where it's really neat for solving a particular problem. How's Haskell for you so far (apart from the hair pulling)? github.com/jvanegmond Link to comment Share on other sites More sharing options...
TheDcoder Posted August 12, 2015 Share Posted August 12, 2015 Bizarro World: FLLANIY Aetfr mcuh hiar pnillug faeherod snihsamg and cniyrg I fllaniy hekcad up tihs hleksal pargorm taht tekas a scnetnee taht the uesr eretns and tehn resreves the iennr lrettes of ecah wrod Translato: Bizarre World: FINALLY After much hair pulling forehead smashing and crying I finally ?????? up this haskell program that takes a sentence that the user enters and then reverses the inner letters of each word I used a proprietary language which is used in a proprietary system to translate it back into English... That system is homo sapian and the lagauage is homo sapianian I think... TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
jaberwacky Posted August 12, 2015 Author Share Posted August 12, 2015 (edited) How's Haskell for you so far (apart from the hair pulling)?I wouldn't take my opinion as fact. I approach Haskell and functional programming from a place of little to no mathematical ability. It's been a hair pulling experience. Since my last post I haven't done much Haskell particular stuff. Just reading about general functional programming concepts. In my experience, I have been slowly arriving to a functional style in my imperative scripts. So I have been picking up on the concepts pretty well as long as they're explained from a practical view point. I don't do very well with the category theory stuff. Supposedly that stuff isn't necessary to program functionally though. Edited August 13, 2015 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted August 14, 2015 Author Share Posted August 14, 2015 (edited) It just occurred to me that Haskell is the first language that I've tried to learn where I did not give one thought to syntax highlighting.Edit:Actually, that's not entirely true. I did try to set up SciTE to use the Haskell syntax highlighter, but the option isn't there in the language drop down. Still, the point stands, it's not that big of a deal for some reason. Just a thought. Edited August 14, 2015 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jvanegmond Posted August 14, 2015 Share Posted August 14, 2015 Even Notepad++ supports Haskell highlighting, though I'm not sure how good it is.I've been thinking about learning F# for a while. TheDcoder 1 github.com/jvanegmond Link to comment Share on other sites More sharing options...
jaberwacky Posted August 14, 2015 Author Share Posted August 14, 2015 Here's a good link: http://fpbridge.co.uk/why-fsharp.html TheDcoder and jvanegmond 2 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jvanegmond Posted August 14, 2015 Share Posted August 14, 2015 Wow. Awesome. And look at the time.. Friday afternoon. Time for a pet project! github.com/jvanegmond Link to comment Share on other sites More sharing options...
TheDcoder Posted August 14, 2015 Share Posted August 14, 2015 (edited) Wow! F# is multi-platform, supports android & no spaghetti code! Just what I need! Thanks Manadar & Jaber for the link, TD Edited August 14, 2015 by TheDcoder blank line at the start EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now