[Nix-dev] [***SPAM***] Re: Use Haskell for Shell Scripting

Michael Raskin 7c6f434c at mail.ru
Tue Feb 10 22:41:04 CET 2015


 >>> I don't really know TH either.  Occasionally I use TH actions defined
>>> in a library (for example to derive safecopy instances or, less
>>> commonly, to auto-generate lenses).  But TH somehow feels wrong and
>>> ugly.
>>
>> In both Julia and Common Lisp I use macros for many tasks and they
>> make life much more comfortable. Of course, Haskell type system may
>> make it hasrder to use macros.
>
>Oh, Common Lisp (CL) macros don't correspond to TH, but rather to
>regular functions in Haskell.  We have first class actions together with
>lazy evaluation.  What is "code is data is code" in CL is "actions are
>first class values" in Haskell.
>
>You only need TH when you need to generate something that is not first
>class, for example class instances.

And many actions are first class values in CL. But there are many things
that are not first class even in Haskell. Macros can manipulate lexical
environments in many convenient ways, for example.

Also, while you could make a function out of a complex iteration macro, 
it is guaranteed to be simpler to use.

>>>>> However, you may want to write type signatures anyway.  It doesn't
>>>>> increase your development time considerably.
>>>>
>>>> I also need to write matching to extract data from deep structures,
>>>> no?
>>>
>>> I'm not sure what you mean by that.  Perhaps you can drop me an
>>> off-list mail, so we can talk about your specific application.
>>
>> Well, it looks like field names are not scoped and if I use plain ADT
>> I have to write pattern matching to extract data from a member of a
>> member of a structure.
>
>You can chain both functions and lenses.  Extraction via functions:

Ah, so Haskell has no usable records without lenses?

>    (innerField . outerField) value
>
>Extraction via lenses:
>
>    value ^. outerField . innerField
>
>Update via lenses:
>
>    (outerField . innerField .~ 15) value
>
>You can even get completely imperative by using a state monad:
>
>    outerField . innerField .= 15
>    outerField . otherInnerField .= "blah"

Well, many Haskell tutorials teach writing Fortran into Haskell; that is
what I try to avoid, especially when it it not even needed.





More information about the nix-dev mailing list