Comments (2)
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.
@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)
- Weird types when masking read,write,alloc effects
- Code Formatter HOT 4
- Reference counting local variables
- Constrained polymorphic effects
- Type variables not unique
- Collection / Vector Literals HOT 5
- String Interpolation HOT 34
- Extensible Matching via Implicits
- Versioned Identifiers
- Identifier hiding/showing and Qualified Modules
- Add let generalization HOT 1
- Structural Types & Newtype HOT 6
- Platform Imports
- Metaprogramming HOT 3
- Struct Constructor TitleCase
- Can't execute and Output "invalid argument"
- Formatting Error in last paragraph of "Tour of Koka -> Value Operations"
- LSP compatible with Eglot or lsp-mode HOT 2
- [Feature Proposal]Relocatable Sharable Memory (Zero-Copy Structural Data Packs) as an Effect
- Array programming HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koka.