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

前端 未结 9 1685
滥情空心
滥情空心 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.

提交回复
热议问题