Fork me on GitHub
#clojure-nl
<
2018-07-17
>
borkdude08:07:42

Yesterday I saw SPJ in Amsterdam… the dark side

borkdude08:07:28

Now back to hot weather coding…

lmergen08:07:01

who/what is SPJ?

borkdude08:07:25

Simon Peyton Jones, the Haskell guy

thomas08:07:55

I find him rather static....

borkdude08:07:11

His talk was about dynamic typing in Haskell

thomas08:07:21

shock horror!!!

thomas08:07:35

what happened... is he ill?

borkdude08:07:31

it’s a way to get dynamic typing in haskell with static guarantees

thomas08:07:51

sounds rather clever...

borkdude08:07:22

it’s kind of like storing something as Object in Java and then casting it back right when you need it to be of some type, but with the guarantee that you can never unsafely cast it to something it isn’t

chrisblom09:07:08

the checks to safely cast are runtime checks right?

lmergen09:07:09

this sounds like something only the Haskell community could come up with

chrisblom09:07:49

the haskellers very good at inventing complicating stuff to limit themselves, and then inventing even more complicated stuff to overcome these limitations

😂 4
chrisblom09:07:13

The first time is saw http://hackage.haskell.org/package/HList i though it was a joke

lmergen09:07:42

@borkdude what are the guarantees to the toStatic function in your code?

lmergen09:07:01

it looks like a runtime check?

borkdude09:07:17

that it will always result in a static type

chrisblom09:07:34

this can break as soon as you add another option to StringOrInt

lmergen09:07:50

only because it's a silly name 🙂

lmergen09:07:19

in reality, it will most like be FooType

borkdude09:07:26

@chris.blom that’s always the case in Haskell 😛

lmergen09:07:36

That's A Feature

borkdude09:07:57

@chrisblom that’s always the case in Haskell (hey, I mentioned the wrong chrisblom)

borkdude09:07:14

@lmergen the point is that you will never have a runtime exception as a result of casting to the wrong type

lmergen09:07:37

can't the runtime exception still occur when toStatic is executed?

borkdude09:07:10

No, it will always have something of the type Maybe StringOrInt, never an exception

borkdude09:07:39

well, I should have added a case for all other Dynamics that return a Nothing

lmergen09:07:49

but, but... then it's just the same like casting an Object to a StringOrInt, and wrapping the exception in a Maybe ?

borkdude09:07:09

but maybe this code isn’t the best example, I wrote this only when I discovered that you could do this, not when I properly understood this topic 🙂

lmergen09:07:36

yeah ok but these are not static guarantees

lmergen09:07:45

you can still feed it the wrong Dynamic

lmergen09:07:00

it's just that it's now a Nothing instead of an exception

borkdude09:07:21

there is no wrong Dynamic

lmergen09:07:39

a Dynamic that doesn't cast to Int or String, right ?

lmergen09:07:37

i think i'm still confused 🙂

borkdude09:07:44

fromDynamic returns a Nothing or a Just a of the type a you wanted. You also have unsafeCoerce in Haskell, this won’t get you an exception, but just returns bogus when applied wrongly.

Prelude Unsafe.Coerce> data Foo = A | B
Prelude Unsafe.Coerce> unsafeCoerce A :: Int
283479243147

borkdude09:07:09

I’m not an Haskell expert, so sorry for the confusion 🙂

lmergen09:07:23

i'm not a haskell expert either

lmergen09:07:26

no one is 🙂

lmergen09:07:43

but as far as i can see, it's mainly a way to wrap some arbitrary data in a Dynamic, and write your code that uses it with static guarantees

borkdude09:07:42

that’s right

borkdude09:07:26

One of my takeaways from this talk was how hard it is to do something like this in Haskell 😛

lmergen09:07:20

that's also a feature, eh 🙂