Being smart is hard
Being not smart is also hard
Picking one of them also hard
So just be yourself and do not let AI to choose a way for you
Being not smart is also hard
Picking one of them also hard
So just be yourself and do not let AI to choose a way for you
How different languages handle the impossible states or errors?
Java/Python/PHP/C++ - throws an exception middle of the execution whenever developer wants
Go - panics like idiot everywhere or checks fucking error interface in every line of code
Haskell/Rust - if you use partial function panics and stops execution, but show warnings while compilation. If not, the compiler just not let you write impossible state
How other methods are there? Do you know?
Java/Python/PHP/C++ - throws an exception middle of the execution whenever developer wants
Go - panics like idiot everywhere or checks fucking error interface in every line of code
Haskell/Rust - if you use partial function panics and stops execution, but show warnings while compilation. If not, the compiler just not let you write impossible state
How other methods are there? Do you know?
Let’s pause here for a second, because there’s something very cool that’s easy to miss: we can control what a valid API looks like by NOT writing instances for HasLink. For example, it doesn’t make sense to create a link to something involving :<|>; for example, left :<|> right is for composing endpoints left and right into an API, but there’s no link that makes sense for left :<|> right itself. Well, if we don’t write an instance HasLink (a :<|> b), we’ll never be able to construct a link to a malformed endpoint, because toLink won’t compile! We’ve transformed the runtime error (Left "...") from our function endpointLink above, into a compile-time error. How awesome is that?!
Haskell has a mind-blowing power but we are not ready to use this power :)
Link
λ
New year with a new car 🤩🤩
This media is not supported in your browser
VIEW IN TELEGRAM
Time to say goodbye to my car😭
package main
type Nat enum {
zero
succ(Nat)
}
const one Nat = succ zero
const two Nat = succ one
const three Nat = succ two
const four Nat = succ three
const five Nat = succ four
func add(n Nat, m Nat) Nat {
switch n {
case zero:
return m
case succ(k):
return succ(add(k, m))
}
}
func fib_aux(n Nat, curr Nat, next Nat) Nat {
switch n {
case zero:
return curr
case succ(k):
return fib_aux(k, next, add(curr, next))
}
}
func fib(n Nat) Nat {
return fib_aux(n, zero, succ(zero))
}
@eval fib(zero)
@eval fib(one)
@eval fib(two)
@eval fib(three)
@eval fib(four)
@eval fib(five)
me trying to fix Go's type-system after Haskell 🧌
package main
type Bool enum {
false
true
}
type Maybe[A] enum {
nothing Maybe[A]
just(A) Maybe[A]
}
type Functor[F] class {
fmap[A, B] :: (A -> B) -> F[A] -> F[B]
}
func (Maybe) Functor {
fmap[A, B](f A -> B, x Maybe[A]) Maybe[B] {
switch x {
case nothing:
return nothing[B]
case just(a):
return just[B](f(a))
}
}
}
func not(b Bool) Bool {
switch b {
case false:
return true
case true:
return false
}
}
@check Functor
@check fmap
@eval fmap(not, just true)
@eval fmap(not, nothing)
things are getting interesting😁