How I Start: Haskell
howistart.org
How I Start: Haskell
1–10 of 61 posts
Re: How I Start: Haskell
#2I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
Re: How I Start: Haskell
#3Re: How I Start: Haskell
#4What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
Re: How I Start: Haskell
#5As of lately, I've been using a bundled GHC app for OSX development. Makes it quite easy to keep (and switch between) multiple Haskell environments.
Re: How I Start: Haskell
#6What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
It's useful, but the amount of magic in it can be off-putting. For average developers it's a tradeoff of magic for functionality. Debugging it can be a nightmare if you use too much of the magic, but using it for simple data access and setting can be pretty straightforward.
Re: How I Start: Haskell
#7What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
Re: How I Start: Haskell
#8What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
But lenses can do things that pointers can't do. Namely, they can be composed. If you have a lens that points to a person's birth date
dob :: Lens Person Date
...and a lens that points to a date's year field: year :: Lens Date Int
Then you can compose them like this: (dob . year) :: Lens Person Int
Normally it would be easy to retrieve the person's birth year with plain function composition. Lenses let you do that too. But setting the person's birth year is much more painful. This is where lenses shine. set (dob . year) 2004 personRe: How I Start: Haskell
#9What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.
You probably do want lenses. Learning to use them is its own "mind blowing" experience similar to learning functional programming itself. Better, they integrate smoothly with Haskell so once you've learned them the cost of using them is quite small.
Unfortunately, learning lenses from `lens` itself is quite hard. There is some amount of training materials (shameless plug here)
https://www.fpcomplete.com/user/tel/a-little-lens-starter-tutorial
https://www.fpcomplete.com/user/tel/lens-aeson-traversals-prisms
but the library itself is typically targeting a proficient user far better than a new one. I'd recommend trying to implement your own lenses as a learning task. If you don't bother generalizing it as far as Ed has then the core concept is very simple. I wrote up a CodeWars task for this using the Van Laarhoven style used in `lens`, but there are even simpler forms as well. http://www.codewars.com/kata/54258ffb430ca2e4b5000239