Is Haskell truly pure (is any language that deals with input and output outside the system)?

后端 未结 8 973
名媛妹妹
名媛妹妹 2020-11-29 22:38

After touching on Monads in respect to functional programming, does the feature actually make a language pure, or is it just another \"get out of jail free card\" for reason

8条回答
  •  庸人自扰
    2020-11-29 22:51

    Is Haskell truly pure? [...]

    The Haskell language was pure; the last version being Haskell 1.2. Back then, the type of main was:

    main :: [Response] -> [Request]
    

    which was usually abbreviated to:

    main :: Dialogue
    

    where:

    type Dialogue = [Response] -> [Request]
    

    and Response along with Request were humble, albeit large datatypes:

    pared-down definitions of request and response datatypes for dialogue-based I/O

    The advent of I/O using the monadic interface in Haskell changed all that - no more visible datatypes, just an abstract specification. As a result, how IO, return, (>>=) etc are defined is now specific to each implementation of Haskell.

    So the question is now:

    • is I/O in your implementation of Haskell pure?

    As Owen Stephens notes in Approaches to Functional I/O:

    I/O is not a particularly active area of research, but new approaches are still being discovered [...]

    The Haskell language may once again have a pure, fully-defined model for I/O...

提交回复
热议问题