Hi, folks. Noobie Haskell question. How can I create this structure myself: Post {id = c2eacdc4-1828-40bd-921e-d7a939edc9c3, title = "Hello", body = "World", meta = MetaBag {annotations = [], touchedFields = []}}
I come from Elm, so I'm used to type Post = Post { ...record here... }. Thanks :)
@Mikolaj Kubera If you're just messing around with haskell to learn and you're coming from elm, I recommend taking a look a PureScript. I has a lot of the advanced FP stuff haskell has, but it also has records that work similar to elm's
@Mason Mackaman Hi. Thanks. Do you then suggetst to use PureScript as a kind of "intermediary" language for me? :) (Although, funny thing, learning a bit of Haskell has already made it easier for me to work with Elm :x)
Honestly, I can't really suggest that because personally I moved from elm to purescript, and I have not done any substantial work in haskell myself. If haskell is your end goal I would say just stick with haskell :+1:
but if your end goal is just to learn about and use advanced FP concepts, then either purescript or haskell will have tons to teach you, and you might find purescript a little nicer to work with.
Haskell has stronger documentation / community content, so that will probably make it easier to pick up
On the other hand, PureScript has more modern (that is, more sensible) standard libraries, because it's younger
LYAH is fine to get some idea about what language looks like, then Haskell wikibook, Typeclassopedia on Haskell Wiki and WIWIKWLH should cover most stuff you'll encounter and GHC Manual has great documentation when it comes to extensions and flags
@Georgi Lyubenov // googleson78 you really think PS's records make it closer to elm than haskell? I'm under the impression that PS and haskell are much closer to each other due to all the advanced concepts they share. I know haskell + extensions has more, but does it really have so many more features that PS isn't even past the halfway point between haskell and elm?
We should mention that Haskell does have a map data structure with dynamic key-value pairs, Data.Map. But it's used like an object in JS, not like a class.
Hi, folks. Noobie Haskell question. How can I create this structure myself:
Post {id = c2eacdc4-1828-40bd-921e-d7a939edc9c3, title = "Hello", body = "World", meta = MetaBag {annotations = [], touchedFields = []}}
I come from Elm, so I'm used to
type Post = Post { ...record here... }
. Thanks :)I guess you also need one for
MetaBag
because it's also a record
(because no anonymous records)
Motherfuck. Thanks :D Is
{ key = value }
structure also called a record in HS?I mean, I would use "record" to refer to the
Post
type from above, but if I were to be pedantic I would say{ key = value }
is a syntax erroryou always need the
Post
constructor herethen it's "just" creating a
Post
valuelet x = Post { id = "pesho" ...} in ...
maybe give a full example?
@Torsten Schmits I'm just playing around with
IHP
and was curious how to dig a bit into basic data types.@Mikolaj Kubera I meant Georgi :sweat_smile:
Oh, haha :sweat_smile:
so
like this!
Is this "the way" to structure data in Haskell?
yes!
Awesome. So there's nothing like a record or map or anything key/value specifically that can be used without a constructor?
no, even
Bool
is not a builtin typeI guess technically
[(k, v)]
is builtin (i.e. a list of tuples)uhum. OK. Thanks :) Much appreciated
I mean you can build your own
@Kampouse Expand the thought, pls :)
@Mikolaj Kubera If you're just messing around with haskell to learn and you're coming from elm, I recommend taking a look a PureScript. I has a lot of the advanced FP stuff haskell has, but it also has records that work similar to elm's
@Mason Mackaman Hi. Thanks. Do you then suggetst to use PureScript as a kind of "intermediary" language for me? :) (Although, funny thing, learning a bit of Haskell has already made it easier for me to work with Elm :x)
Honestly, I can't really suggest that because personally I moved from elm to purescript, and I have not done any substantial work in haskell myself. If haskell is your end goal I would say just stick with haskell :+1:
but if your end goal is just to learn about and use advanced FP concepts, then either purescript or haskell will have tons to teach you, and you might find purescript a little nicer to work with.
Haskell has stronger documentation / community content, so that will probably make it easier to pick up
On the other hand, PureScript has more modern (that is, more sensible) standard libraries, because it's younger
if you're goal is to learn Haskell, you should go to Haskell imo
I think they're close enough in "base" complexity (no extensions) that learning ps won't help too much
PureScript is definitely closer to Elm than Haskell is, thanks to its anonymous records
I have learn a bit of clojure prior haskell made much more sense
@TheMatten what's the best haskell documentation? do they have something like jordan's reference that is nearly exhaustive? I would love that.
LYAH is fine to get some idea about what language looks like, then Haskell wikibook, Typeclassopedia on Haskell Wiki and WIWIKWLH should cover most stuff you'll encounter and GHC Manual has great documentation when it comes to extensions and flags
lyah has no exercises though, I think Hutton's book is better in this regard
@Georgi Lyubenov // googleson78 you really think PS's records make it closer to elm than haskell? I'm under the impression that PS and haskell are much closer to each other due to all the advanced concepts they share. I know haskell + extensions has more, but does it really have so many more features that PS isn't even past the halfway point between haskell and elm?
no no
I meant that PS is closer to Elm, than Haskell is to Elm
oh, I see you edited the message. I didn't catch that difference on the reread :+1:
We should mention that Haskell does have a map data structure with dynamic key-value pairs,
Data.Map
. But it's used like an object in JS, not like a class.you can find maps and sets in the
containers
package.But again, not what you are looking for – @Torsten Schmits already showed the idiomatic way to structure data with a "known" structure in Haskell.