Noobie questions - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Mikolaj Kubera

Ah, interesting :) Yea, LISP doesn't scare me. I can throw brackets at people any time, any day :>

Mikolaj Kubera

@Mason Mackaman Haskell is my goal atm, but I can see your point. Can you tell me why the move from Elm to PS, and does PS implement TEA or something equivalent?

Mikolaj Kubera

I'm just toying with Prelude's fns in ghci. https://hackage.haskell.org/package/Prelude-0.1.0.1/docs/Prelude.html#g:14
head,last,init,and tail all throw a value without Maybe, though. Is there something I do not know here? :)

Torsten Schmits

you should know never to use those!

Torsten Schmits

there are multiple alternative packages that provide a safer prelude, highly recommended

Torsten Schmits

not trivial to use with ghci though.

Torsten Schmits

bit of a problem area for haskell

Mikolaj Kubera

kk, thanks @Torsten Schmits I will poke around :)

TheMatten

Can you tell me why the move from Elm to PS, and does PS implement TEA or something equivalent?

Compared to PS/HS, Elm feels a little bit like a web-specific DSL - nothing is really stopping you from implementing Elm architecture in these, but at the same time you're free to implement completely different approaches.
Similarly, Elm only has few builtin typeclasses, while HS/PS let you implement and instantiate your own, in any way you like

Mason Mackaman

@Mikolaj Kubera as @TheMatten said, you can implement TEA in purescript (I've basically done this myself!). The more haskell you learn the more you'll see why I switched. The main reason I loved elm, other than ADTs, was the compiler could catch nearly all the errors for you. Well PS/Haskell also offer that benefit, but with many more capabilities.

bradrn

For completeness, I should mention that in your own code, you can throw errors without Maybe by using the error function, though as @Torsten Schmits says you shouldn’t usually use those. The one area where I regularly use it is for code paths which shouldn’t ever be reached, but I can’t statically ensure this. A contrived example: let x' = ("key","value") : x in case lookup "key" x' of { Just _ -> "worked" ; Nothing -> error "this part should never be reached" }.

bradrn

@Torsten Schmits Surely you don’t actually _need_ an alternative Prelude, right? I’ve always just used plain Preludeand never really had any problems with it.

TheMatten

It's good to treat error as equivalent of panic! from Rust

Mats Rauhala

Yeah. You don't need an alternative prelude. You need to be careful with those partial functions though. You can implement your own total headMaybe and the likes, I usually prefer going through the NonEmpty list if I want to stay in base

Georgi Lyubenov // googleson78

it's true that you don't need one, but you might as well use it, if you're going to be using those functions, especially if you're writing an application

Georgi Lyubenov // googleson78

(and for the other things a custom prelude provides of course)