What's the next step to learning Haskell after monads?

前端 未结 9 1578
滥情空心
滥情空心 2021-01-29 18:02

I\'ve been gradually learning Haskell, and even feel like I\'ve got a hang of monads. However, there\'s still a lot of more exotic stuff that I barely understand, like Arrows, A

相关标签:
9条回答
  • 2021-01-29 18:22

    You know all you need to go forth and write code. But if you're looking for more Haskell-y things to learn about, may I suggest:

    • Type families. Very handy feature. It basically gives you a way to write functions on the level of types, which is handy when you're trying to write a function whose parameters are polymorphic in a very precise way. One such example:

    data TTrue = TTrue
    data FFalse = FFalse

    class TypeLevelIf tf a b where type If tf a b weirdIfStatement :: tf -> a -> b -> tf a b

    instance TypeLevelIf TTrue a b where type If TTrue a b = a weirdIfStatement TTrue a b = a

    instance TypeLevelIf FFalse a b where type If FFalse a b = b weirdIfStatement FFalse a b = a

    This gives you a function that behaves like an if statement, but is able to return different types based on the truth value it is given.

    If you're curious about type-level programming, type families provide one avenue into this topic.

    • Template Haskell. This is a huge subject. It gives you a power similar to macros in C, but with much more type safety.

    • Learn about some of the leading Haskell libraries. I can't count how many times parsec has enabled me to write an insanely useful utility quickly. dons periodically publishes a list of popular libraries on hackage; check it out.

    0 讨论(0)
  • 2021-01-29 18:30

    Typeclasses like Monad, Applicative, Arrow, Functor are great and all, and even more great for changing how you think about code than necessarily the convenience of having functions generic over them. But there's a common misconception that the "next step" in Haskell is learning about more typeclasses and ways of structuring control flow. The next step is in deciding what you want to write, and trying to write it, exploring what you need along the way.

    And even if you understand Monads, that doesn't mean you've scratched the surface of what you can do with monadically structured code. Play with parser combinator libraries, or write your own. Explore why applicative notation is sometimes easier for them. Explore why limiting yourself to applicative parsers might be more efficient.

    Look at logic or math problems and explore ways of implementing backtracking -- depth-first, breadth-first, etc. Explore the difference between ListT and LogicT and ChoiceT. Take a look at continuations.

    Or do something completely different!

    0 讨论(0)
  • 2021-01-29 18:33

    Contribute to GHC!

    0 讨论(0)
提交回复
热议问题