Created
September 21, 2019 03:12
-
-
Save MarcelineVQ/1e969753cd6d8d94400a1d19bdcfa9b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <jellostahps> so doubling every char of a String is grow :: String -> String | |
| <jellostahps> grow(x:xs) = x:x:grow(xs) | |
| <jellostahps> what about every index of a character is repeated that many times | |
| <jellostahps> input=string output = s t t r r r i i i i n n n n n g g g g g g | |
| <pikajude> grow "string" = "sttrrriiiinnnnngggggg" | |
| <pikajude> may not work for all inputs | |
| <jellostahps> yeah, wondering what i can do to fix it | |
| <jellostahps> would it definitely require a second function | |
| <dmwit> > concat (zipWith replicate [1..] "string") | |
| <lambdabot> "sttrrriiiinnnnngggggg" | |
| <dmwit> ...but more helpfully: | |
| * o1lo01ol1o ([email protected]) has joined | |
| <dmwit> jellostahps: Try writing a function which takes *two* arguments: the current index, and the input string starting at that index. | |
| <jellostahps> I have to do it with a single string input | |
| <dmwit> So `foo n (x:xs) = ???`. | |
| <dmwit> Then you can write a single top-level wrapper like `wrapper = foo 1`. | |
| * conal has quit (Quit: Computer has gone to sleep.) | |
| <dmwit> (Or `wrapper xs = foo 1 xs` if that's more clear to you.) | |
| * conal ([email protected]) has joined | |
| * ddellacosta ([email protected]) has joined | |
| * conal has quit (Client Quit) | |
| <jellostahps> is a wrapper just f(g(x)) | |
| <jellostahps> or wrapper . foo 1 xs in this case | |
| <dmwit> No. | |
| <dmwit> It is `wrapper xs = foo 1 xs`. Which is why I wrote that. | |
| * georgie has quit (Quit: My MacBook has gone to sleep. ZZZzzz…) | |
| <jellostahps> foo runs with parameter 1 and xs=string, and returns a string i imagine | |
| * o1lo01ol1o has quit (Ping timeout: 245 seconds) | |
| <dmwit> Sounds right. | |
| <koz_> > bool 1 2 True | |
| <lambdabot> 2 | |
| <jellostahps> wouldnt a variable be better than using '1' here | |
| * falafel has quit (Ping timeout: 245 seconds) | |
| <jellostahps> since u have to iterate 1 for the next letter(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment