Logs: liberachat/#haskell
| 2021-08-22 09:40:39 | <yahb> | dminuoso: 10 |
| 2021-08-22 09:41:02 | <dminuoso> | Is this enough to help you with the task? |
| 2021-08-22 09:41:16 | <dminuoso> | Mind you, `digits` is something I wrote myself in a private chat. |
| 2021-08-22 09:41:24 | <dminuoso> | So consider this one of the tasks for you to solve. |
| 2021-08-22 09:41:50 | <Guest9> | hi.. I have already written function for summation |
| 2021-08-22 09:44:27 | <Guest9> | digitSum = sum . map (read . return) . show |
| 2021-08-22 09:44:44 | <Guest9> | this takes any number and adds the digits in it.. |
| 2021-08-22 09:44:52 | <dminuoso> | Mmm, this is not idiomatic |
| 2021-08-22 09:44:56 | <dminuoso> | Try to avoid using `show` and `read`. |
| 2021-08-22 09:44:58 | × | jgeerds quits (~jgeerds@55d4b311.access.ecotel.net) (Ping timeout: 250 seconds) |
| 2021-08-22 09:45:24 | <Guest9> | I am looking for a way to apply it recursively... if the intermediate output is not a single digit no |
| 2021-08-22 09:45:47 | <dminuoso> | Guest9: The way you'd encode this, is by doing conditional recursion. |
| 2021-08-22 09:45:57 | <dminuoso> | i.e. thats how we encode loop conditionals |
| 2021-08-22 09:46:01 | <dminuoso> | for example: |
| 2021-08-22 09:46:48 | <dminuoso> | @src take |
| 2021-08-22 09:46:48 | <lambdabot> | take n _ | n <= 0 = [] |
| 2021-08-22 09:46:48 | <lambdabot> | take _ [] = [] |
| 2021-08-22 09:46:48 | <lambdabot> | take n (x:xs) = x : take (n-1) xs |
| 2021-08-22 09:47:18 | <dminuoso> | See how this, conditionally on n, either recurses or not? We stop recursing by simply not recursing. We also call this the base cae |
| 2021-08-22 09:47:55 | <dminuoso> | And by modifying this argument in each recursion, we modify it - very much akin to how you might decrement a loop variable each turn. |
| 2021-08-22 09:49:48 | <dminuoso> | Well, and conditionally on the list too, as if the list is empty, this also stops recursing. |
| 2021-08-22 09:50:14 | <dminuoso> | Guest9: And regarding avoiding `read` and `show`, try using: |
| 2021-08-22 09:50:16 | <dminuoso> | % :t divMod |
| 2021-08-22 09:50:16 | <yahb> | dminuoso: Integral a => a -> a -> (a, a) |
| 2021-08-22 09:51:10 | → | o1lo01ol1o joins (~o1lo01ol1@5.181.115.89.rev.vodafone.pt) |
| 2021-08-22 09:51:12 | <Guest9> | 2 querieas |
| 2021-08-22 09:51:45 | <Guest9> | 1. what is idiomatic ? .. I am sorry.. I am self taught and got only learn you a Haskell as a resource.. |
| 2021-08-22 09:51:49 | × | o1lo01ol1o quits (~o1lo01ol1@5.181.115.89.rev.vodafone.pt) (Remote host closed the connection) |
| 2021-08-22 09:52:14 | <Guest9> | The example you gave is for a list.. My struggle right now is how do I store the intermediate output? |
| 2021-08-22 09:52:22 | <dminuoso> | Think of "idiomatic haskell" as "what haskell programmers would normally write" |
| 2021-08-22 09:52:34 | <dminuoso> | Guest9: You store it in a function parameter. |
| 2021-08-22 09:52:40 | <dminuoso> | Guest9: Look at the implementation of `take` cited above. |
| 2021-08-22 09:52:50 | <Guest9> | because I need to apply the custom function to the intermediate output also if the output is less than 10 |
| 2021-08-22 09:53:01 | <dminuoso> | Note how in the recursive step we "drop" the head of the list, and pass down the tail instead? |
| 2021-08-22 09:53:05 | <dminuoso> | i.e. |
| 2021-08-22 09:53:09 | <dminuoso> | 11:46:48 lambdabot | take n (x:xs) = x : take (n-1) xs |
| 2021-08-22 09:53:51 | <dminuoso> | If this definition is taken, we pattern match the second argument to a list whose head is `x`, and whose tail is `xs`. In the recursive application of take the first parameter is (n-1), and the second parameter is just the tail |
| 2021-08-22 09:54:02 | <dminuoso> | So we "store/keep" intermediate values around in function arguments |
| 2021-08-22 09:54:40 | <dminuoso> | equivalently we might write sum as: |
| 2021-08-22 09:55:10 | <dminuoso> | % sum :: [Int] -> Int; sum [] = 0; sum (x:xs) = x + sum xs |
| 2021-08-22 09:55:11 | <yahb> | dminuoso: |
| 2021-08-22 09:55:14 | <dminuoso> | % sum [1,2,3] |
| 2021-08-22 09:55:14 | <yahb> | dminuoso: 6 |
| 2021-08-22 09:55:42 | <dminuoso> | This will expand into |
| 2021-08-22 09:55:49 | × | mnrmnaugh quits (~mnrmnaugh@68.162.206.56) (Quit: Leaving) |
| 2021-08-22 09:56:28 | <dminuoso> | sum 1:2:3:[] ---> 1 + sum 2:3:[] ---> 1 + 2 + sum 3:[] ---> 1 + 2 + 3 + sum [] ---> 1 + 2 + 3 + 0 |
| 2021-08-22 09:56:39 | <dminuoso> | Guest9: Does this make any sense to you? |
| 2021-08-22 09:57:25 | <Guest9> | this is partial application of function.. currying I think.. I am just on chap 6 ofLYAH |
| 2021-08-22 09:57:35 | <dminuoso> | No, this is not partial application. |
| 2021-08-22 09:57:48 | <dminuoso> | This is just plain function application |
| 2021-08-22 09:58:11 | <dminuoso> | Try to focus on understanding how `sum` works, maybe. |
| 2021-08-22 09:58:40 | <dminuoso> | How we use recursion to model loops, and function arguments to model loop variables. |
| 2021-08-22 10:00:11 | <Guest9> | ok .. let me try going through the recursion chapter again and see.. |
| 2021-08-22 10:00:15 | <Guest9> | thanks |
| 2021-08-22 10:03:13 | → | eggplantade joins (~Eggplanta@108-201-191-115.lightspeed.sntcca.sbcglobal.net) |
| 2021-08-22 10:06:36 | → | zer0bitz_ joins (~zer0bitz@dsl-hkibng31-58c384-213.dhcp.inet.fi) |
| 2021-08-22 10:07:13 | × | zer0bitz quits (~zer0bitz@dsl-hkibng31-58c384-213.dhcp.inet.fi) (Ping timeout: 252 seconds) |
| 2021-08-22 10:07:40 | × | eggplantade quits (~Eggplanta@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 240 seconds) |
| 2021-08-22 10:08:40 | × | xff0x quits (~xff0x@2001:1a81:52ba:f800:f4cf:86a:773:6851) (Ping timeout: 240 seconds) |
| 2021-08-22 10:09:43 | → | xff0x joins (~xff0x@2001:1a81:52ba:f800:ba30:5326:3556:79a1) |
| 2021-08-22 10:10:58 | × | kenran quits (~kenran@200116b82b8bf8007bc477e0c5eee3d0.dip.versatel-1u1.de) (Quit: WeeChat info:version) |
| 2021-08-22 10:11:04 | → | __monty__ joins (~toonn@user/toonn) |
| 2021-08-22 10:18:41 | × | Guest9 quits (~Guest9@115.96.241.44) (Quit: Ping timeout (120 seconds)) |
| 2021-08-22 10:25:31 | → | burnsidesLlama joins (~burnsides@dhcp168-023.wadham.ox.ac.uk) |
| 2021-08-22 10:26:24 | × | zer0bitz_ quits (~zer0bitz@dsl-hkibng31-58c384-213.dhcp.inet.fi) (Read error: Connection reset by peer) |
| 2021-08-22 10:28:31 | → | Guest9 joins (~Guest9@115.96.241.44) |
| 2021-08-22 10:28:39 | × | Guest9 quits (~Guest9@115.96.241.44) (Client Quit) |
| 2021-08-22 10:30:57 | × | haskl quits (~haskl@user/haskl) (Read error: Connection reset by peer) |
| 2021-08-22 10:31:55 | → | haskl joins (~haskl@98.37.78.63) |
| 2021-08-22 10:33:34 | <Gurkenglas> | ...installing lens-regex doesnt install regex? hmm. |
| 2021-08-22 10:34:48 | <Gurkenglas> | so i thought "every number in this string should be 2 higher". sounded like a lens oneliner. what's the proper workflow here? presumably not stack install lens, stack install lens-regex, stack install regex, stack ghci, import Control.Lens, import 3 more things, run oneliner |
| 2021-08-22 10:35:14 | <Gurkenglas> | and making a project for that also seems like overkill |
| 2021-08-22 10:35:38 | × | jtomas quits (~jtomas@233.red-83-34-2.dynamicip.rima-tde.net) (Remote host closed the connection) |
| 2021-08-22 10:38:45 | × | mc47 quits (~mc47@xmonad/TheMC47) (Remote host closed the connection) |
| 2021-08-22 10:39:27 | <Gurkenglas> | or is the proper workflow in fact to have a project with all the scripting utilities within which i ghci whenever i have a oneliner to execute? |
| 2021-08-22 10:40:19 | <[exa]> | Gurkenglas: maybe use cabal and runhaskell with -package :] |
| 2021-08-22 10:40:44 | <[exa]> | stack is inevitably project-ish |
| 2021-08-22 11:00:53 | → | alx741 joins (~alx741@181.196.68.120) |
| 2021-08-22 11:03:59 | × | tcard quits (~tcard@p2307053-ipngn17101hodogaya.kanagawa.ocn.ne.jp) (Quit: Leaving) |
| 2021-08-22 11:04:20 | → | raehik joins (~raehik@cpc95906-rdng25-2-0-cust156.15-3.cable.virginm.net) |
| 2021-08-22 11:07:42 | → | lavaman joins (~lavaman@98.38.249.169) |
| 2021-08-22 11:08:50 | → | tcard joins (~tcard@p2307053-ipngn17101hodogaya.kanagawa.ocn.ne.jp) |
| 2021-08-22 11:10:11 | → | hannessteffenhag joins (~hannesste@ip4d14ffc8.dynamic.kabel-deutschland.de) |
| 2021-08-22 11:11:15 | → | gehmehgeh joins (~user@user/gehmehgeh) |
| 2021-08-22 11:12:32 | × | lavaman quits (~lavaman@98.38.249.169) (Ping timeout: 268 seconds) |
| 2021-08-22 11:14:21 | → | mastarija joins (~mastarija@78-3-210-70.adsl.net.t-com.hr) |
| 2021-08-22 11:15:30 | → | kuribas joins (~user@ptr-25vy0iac19m0oa3eqv7.18120a2.ip6.access.telenet.be) |
| 2021-08-22 11:16:05 | <mastarija> | When documenting a type, how does one differentiate between a type constructor and value constructor with the same name? e.g. I have `MyName a = MyName a | OtherName a` |
| 2021-08-22 11:16:29 | <mastarija> | In Haddock I can use single quotes to link to a type or value constructor, but in this case, how do I differentiate? |
| 2021-08-22 11:18:11 | → | zer0bitz joins (~zer0bitz@dsl-hkibng31-58c384-213.dhcp.inet.fi) |
| 2021-08-22 11:18:13 | <mastarija> | I have a feeling it was something like MyName:MyName? Can't remember and the documentation is not very clear on this. |
| 2021-08-22 11:20:30 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2021-08-22 11:35:43 | <[exa]> | I'd try MyName.MyName but no idea really |
| 2021-08-22 11:36:02 | <[exa]> | perhaps check the markup generated at the target site |
| 2021-08-22 11:37:58 | × | dsrt^ quits (~dsrt@209.65.131.194) (Ping timeout: 252 seconds) |
| 2021-08-22 11:39:03 | × | hannessteffenhag quits (~hannesste@ip4d14ffc8.dynamic.kabel-deutschland.de) (Ping timeout: 268 seconds) |
| 2021-08-22 11:39:09 | <[exa]> | the hrefs seem to have v: and t: prefixes |
| 2021-08-22 11:39:57 | → | dsrt^ joins (~dsrt@209.65.131.194) |
| 2021-08-22 11:46:35 | <Arsen> | is there a base64encode :: [Char] -> [Char] anywhere? |
| 2021-08-22 11:47:02 | × | vysn quits (~vysn@user/vysn) (Ping timeout: 258 seconds) |
All times are in UTC.