From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.ada Subject: Re: How to get Ada to ?cross the chasm?? Date: Tue, 08 May 2018 15:41:17 -0700 Organization: A noiseless patient Spider Message-ID: <87tvrh6a9e.fsf@nightsong.com> References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <87k1su7nag.fsf@nightsong.com> <87po2la2qt.fsf@nightsong.com> <87in8buttb.fsf@jacob-sparre.dk> <87wowqpowu.fsf@nightsong.com> <16406268-83df-4564-8855-9bd0fe9caac0@googlegroups.com> <87o9i2pkcr.fsf@nightsong.com> <87in88m43h.fsf@nightsong.com> <87efiuope8.fsf@nightsong.com> <87lgd1heva.fsf@nightsong.com> <87zi1gz3kl.fsf@nightsong.com> <878t8x7k1j.fsf@nightsong.com> <8736z4k4th.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="52b5ce8581a197e35f17678a348070d7"; logging-data="13078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7SNnv89r802PCd65Tw2Qm" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cancel-Lock: sha1:wPdDWUc36VHsu6AMMGWfMP0IWCI= sha1:+a/WGvfedBAK7eFcJ90DwWR66Po= Xref: reader02.eternal-september.org comp.lang.ada:52140 Date: 2018-05-08T15:41:17-07:00 List-Id: Niklas Holsti writes: > insertAt x (BC pb pa py (EC gb ga (R ul ua ur) gc))... > Quick, what is the meaning of the argument "py" to insertAt? Being used to Haskell, I see at a glance that "py" is in the expression "BC pb pa py ...". I know right away that BC is a data constructor, because Haskell is case-sensitive and types and data constructors start with capital letters while ordinary values use lower-case letters. So I look at where BC is defined, in the type definition for Context: -- we can go left or right from a red node hole, creating a hole for -- a black node BC :: Bool -> a -> Node Black n a -> Context m Red n a -> Context m Black n a So py is a black-colored subtree that goes into a red-colored hole in the surrounding tree, if I understand zippers properly. Fwiw, if I mis-remember which arg is which and make a mistake writing code, I'll almost certainly get a compile-time type error right away and figure out what went wrong. It's usual to write this sort of code interactively, so you type a few lines, invoke the compiler, fix any errors it reports, and repeat. If the module you're working on isn't too large, the compilation happens very fast. > The concepts of functional programming are attractive to me, but the > practical problems or long, position-specific argument lists, and the > style of using very short identifiers, scare me. The short-identifier style is helped out a lot by the type system catching simple mistakes. That moves the "cursor" of convenience vs verbosity more towards convenience than where a typeless language would have it, for a given level of error avoidance. Long, position-specific arg lists are usually a code smell to be avoided, but Haskell has a record syntax if you want to use named arguments. Instead of data Person = Person String String Int you can say data Person = Person { name :: String, address :: String, age :: Int } and then john = Person { name="John Jones", address="3 Main Street", age=25 } instead of john = Person "John Jones" "3 Main Street" 25 Haskell's record syntax has various drawbacks and is considered a weak spot in current versions of Haskell, but it is there if you want to use it. Also, because it's convenient to create new types in Haskell, you can give different types to the args of a function, so the type system will catch putting them in the wrong order. So the signature of the file-opening function is: openFile :: FilePath -> IOMode -> IO Handle In Python you'd use a string like "r", "w", or "r+w" to say the file opening mode, but in Haskell, IOMode is like an enumeration type in Ada: data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode So if you try to pass a string instead, you get a type error.