Giter Site home page Giter Site logo

() -> a = a about koka HOT 2 CLOSED

koka-lang avatar koka-lang commented on August 23, 2024
() -> a = a

from koka.

Comments (2)

dhil avatar dhil commented on August 23, 2024

I am not sure whether you are asking an question or stating a falsehood. I shall assume the former.

Koka is a strict functional language with n-ary functions. By contrast Haskell is a lazy functional language with unary functions. It is possible to simulate n-ary functions (to some extent) in Haskell by using tuples.

The function type () -> a denotes a nullary function (often called a thunk) which returns an element of type a. In Haskell the type a denote a value of type. This value may be unevaluated, however, due to the lazy evaluation strategy. Furthermore, note that the Koka type () -> a is not the same as the Haskell type () -> a. The two types describe functions of different arities: the former describes a nullary function, while the latter describes an unary function. Formally,

[[-]] : Haskell type -> Koka type
[[() -> a]] = (unit) -> [[a]]

In Koka the function type (unit) -> a describes a function which accepts a single argument, namely, the unit argument, while the type () -> a describes a function that accepts no arguments.

from koka.

Pauan avatar Pauan commented on August 23, 2024

@zaoqi Haskell programs are lazy, which means values are only evaluated when they are needed. In addition, Haskell programs do not have side effects, so side effects are represented with the IO type. The IO type is only evaluated when needed.

Koka programs are not lazy, so everything is evaluated immediately. In addition, Koka programs do have side effects, and Koka does not have the IO type. Therefore in Koka the only way to trigger side effects is to call a function. And the only way to delay evaluation in Koka is to use a function.

In other words, Haskell programs are automatically delayed, but Koka programs must use functions to delay evaluation.

It is possible to create an IO type for Koka:

alias io'<a> = () -> io a

And then you can create io' types:

val my-print: io'<()> = fun() { println("Hi!") }

val main: io'<()> = my-print

This is the same as this Haskell program:

myPrint :: IO ()
myPrint = putStrLn "Hi!"

main :: IO ()
main = myPrint

As you can see, a () -> io a in Koka is exactly the same as an IO a in Haskell. The only difference is that we have to wrap things in fun() { ... } to delay evaluation.

Koka could wrap everything in fun() { ... }, that would give the same behavior as Haskell, but that is inefficient and unnecessary, which is why Koka doesn't do that.

from koka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.