typelead / eta

The Eta Programming Language, a dialect of Haskell on the JVM
https://eta-lang.org
BSD 3-Clause "New" or "Revised" License
2.61k stars 145 forks source link

[eta-tour]: Improvement - AddElement #728

Open premek opened 6 years ago

premek commented 6 years ago

I think it is confusing without knowing what AddElement is

Source Code:

data IntList = Empty | AddElement Int IntList

myIntList :: IntList
myIntList = AddElement 1 (AddElement 2 Empty)

intListFirst :: IntList -> String
intListFirst Empty = ""
intListFirst (AddElement int _) = show int

main :: IO ()
main = print $ intListFirst myIntList
rahulmutt commented 6 years ago

@premek AddElement is a function that takes an Int and an IntList and produces a value of type IntList. If it is explained that way, is it clearer?

premek commented 6 years ago

Absolutely yes. It got clearer later in the tour. Maybe also mention where does it come from? Is it a part of standard library? Or just omitted from the example for simplicity?

rahulmutt commented 6 years ago

@premek It's a user defined type and AddElement becomes availble with this definition:

data IntList = Empty | AddElement Int IntList

Should that be more explicit as well?

premek commented 6 years ago

now it's less clear to me again :) sorry

I would expect this line to mean something like Let type IntList be an empty list or an Int followed by IntList

Does this line also defines AddElement?

rahulmutt commented 6 years ago

It means what you stated above - you can think of AddElement as a tag that signals that an Int and IntList must follow in that order right after. Empty and AddElement are like labels for each of the ways you can construct a value of type IntList.

Yes, the line also defines AddElement and Empty.

premek commented 6 years ago

All right, makes sense. So if you can explain it like this in one sentence in the tour I think it may help others too. Thanks

On Mon, 9 Apr 2018, 16:44 Rahul Muttineni, notifications@github.com wrote:

It means what you stated above - you can think of AddElement as a tag that signals that an Int and IntList must follow in that order right after. Empty and AddElement are like labels for each of the ways you can construct a value of type IntList.

Yes, the line also defines AddElement and Empty.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/typelead/eta/issues/728#issuecomment-379777117, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF6EWOMYNm753XlpJSVxxbE5fFgb1sCks5tm3PYgaJpZM4TMXnq .

rahulmutt commented 6 years ago

Thank you for letting us know it was confusing! :)