HackerTrans
TopNewTrendsCommentsPastAskShowJobs

danidiaz

no profile record

Submissions

Machinery and English Style (1904)

theatlantic.com
9 points·by danidiaz·5 mesi fa·1 comments

comments

danidiaz
·8 anni fa·discuss
In the Idris language, one best practice is to relegate to the outer shell not only IO effects, but also "partiality"—in the sense of computations that might enter an unproductive infinite loop.

(In Haskell, one way of getting into unproductive infinite loops is by mistakenly asking "parse elements until the first failure" to a parser combinator that can always succeed without consuming input.)

The ideal is that the core of the application should be both pure and total, purity and totality being tracked by the type system. In fact, one can often relegate partiality to a single function of the outer shell.
danidiaz
·9 anni fa·discuss
I'm not 100% sure of what the author had in mind, but here's a possible (and possibly dumb) example.

Imagine you need a 2-parameter "Lasagna" datatype wich is a non-empty list of alternating "a" and "b" elements. It could be used to model something like a timeline, perhaps.

Instead of constructing it by hand, you could express it as a composition of other stuff:

    import Data.List.NonEmpty
    import Data.Bifunctor
    import Data.Bifunctor.Tannen

    type Lasagna = Tannen NonEmpty (,)

    example :: Lasagna Char Int
    example = Tannen $ ('a',3) :| [('b',4),('d',6)]
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-L...

https://hackage.haskell.org/package/bifunctors-5.4.2/docs/Da...

That type has a whole bunch of useful instances without even having to auto-derive them.

And you could have functions that manipulated the pairs without caring what shape the "outer functor" has.
danidiaz
·9 anni fa·discuss
I've seen mentioned the "streaming" package as an example of this: http://hackage.haskell.org/package/streaming

"streaming" provides a Stream type which is parameterized by a Functor. The main module in the package provides very general functions which work for any functor and often involve natural transformations and functor compositions and sums. http://hackage.haskell.org/package/streaming-0.1.4.5/docs/St...

The "Streaming.Prelude" instantiates the functor with a pair type and provides the more concrete API that one would expect from a streaming library. http://hackage.haskell.org/package/streaming-0.1.4.5/docs/St...