> On 20 Feb 2020, at 19:22, Keean Schupke <
ke...@fry-it.com> wrote:
>
> I don't think generators really have side effects. The output of a generator can be considered a lazy list, which is a fundamental type in purely functional languages like Haskell.
>
> The generator function itself may have side-effects, but that is separate from its output stream. My best understanding of this would be that 'initialising' the generator has side effects, but sending a stream to or reading a stream fr does not, it's just lazily processing a list.
I agree. It’s a good viewpoint. Thanks!
I think this is reflected in my intuition that a generator may have
effects on its internal state only, recording where it is up to in the stream so to speak.
The problem is really syntax. Generators get used “like functions”. As usual lots of things
do not fit into the functional syntax of expressions: it means an expression containing a generator
is not referentially transparent.
I think this is just fine provided it is syntactically observable.
To be sure, I’d also like to distinguish impure functions (which read variables
that can change) and pure functions, which always produce the same value
for given arguments.
But in a language you cannot have too many distinctions.
The real problem is that Felix has to model C/C++ and so has to properly
reflect some idiomic usage. The strictly correct modelling of almost every
Posix function, which has an effect on the environment but returns an
error code, is very hard unless we make allowance for this idiom somehow.
Felix functions actually already have the general form:
D ->[E] C
where D is the domain, C the codomain, and E is some type indicating effects.
I have never used E, it defaults to unit. The idea is that polymorphism functions and
subtyping rules might help manage effects in HOFS. The problem is I do not
believe in the FP community's idea of effects at all. I think they try to lump
entirely unrelated things that don’t fit into the naive FP model into the notion
of effects and that’s just wrong.
A mutation is an effect .. unless it is managed by linear typing or a monad.
Its nonsense. Exceptions: its not an effect, if you correctly model it with
CPS. Its just not the usual subroutine idea of control flow. I/O .. etc etc ..
these are all quite different IMHO.
Anyhow, a certain class of effects can be managed by effect type:
a polymorphic function can “inherit” the aggregate of argument
effects easily. The problem is that this model only works for some
kinds of effects. So in the end I gave up trying to find a sane
way to use E.
—
John Skaller
ska...@internode.on.net