« first day (596 days earlier)      last day (297 days later) » 

11:31 AM
@FredOverflow this is nice: ideone.com/sOHuin
Apparently case classes also extend Product.
 
11:46 AM
@PolymorphicPotato Are you up for a brain teaser?
void knobelei()
{
    if (!onBeeper())
    {
        pickBeeper();
    }
    if (onBeeper())
    // warning: condition is always true
    {
        turnLeft();
    }
}
Why the warning? :)
 
@FredOverflow Because of a bug.
 
@PolymorphicPotato A bug in the above program or a bug in the analyzer?
 
12:17 PM
@FredOverflow analyzer.
Oh wait, I see.
If you are on a beeper, no beeper is picked.
 
 
2 hours later…
2:18 PM
@FredOverflow What was the answer?
@FredOverflow make it show the analyzer results like Xcode does (with those arrows):
 
@PolymorphicPotato If there is no beeper, the pickBeeper() will crash. Hence, control flow can only reach the second if in case there is a beeper; hence, the check is unnecessary.
It's a bit like checking p != null after having already dereferenced it.
 
@FredOverflow nice.
 
I was actually a bit surprised my analyzer was that powerful already :)
 
It would be nice if it showed the reason.
That would be very helpful.
"warning: condition is always true because pickBeeper() (two lines above) always crashes"
 
Well, it also complains about pickBeeper() leading to a crash, I just didn't tell you that beforehand so I wouldn't give away the solution ;)
 
2:28 PM
I like Odersky's avatar on GitHub:
 
It seems like he is not amused :)
 
Because he has used Java.
 
He can't be hating Java that much, he wrote a compiler for it.
 
I can't wait till Scala has a way to obtain the singleton type of a literal without macros.
 
What is "the singleton type of a literal"?
 
2:31 PM
So you can say var x: 42.type = 42; x = 42 /* ok */; x = 2 /* type error */;.
 
ah
I always thought about proposing that for C++, so I could overload operator+(1) and operator-(1) for bidirectional iterators :)
 
The singleton type of x is the type of which x is the only inhabitant. :)
You can get it with x.type in Scala, but that doesn't work when x is a literal.
There is a library that does it with macros, though.
 
What is your actual use case for this?
The 42 example isn't very compelling.
 
Generic statically-sized lists.
SizedList[T, 1.type] and SizedList[T, 2.type] would be distinct types.
 
Are you coming down with a dependent types fever? :)
 
2:37 PM
You could make tuples indexable with literals. :D
tup(2) instead of tup._2!
 
awsum
 
@FredOverflow I wonder what Sum would look like, in contrast with Product.
It would probably be awproduct.
 
@PolymorphicPotato Either
 
Hmm.
I want a more generic Either!
 
More than 2 type parameters?
 
2:46 PM
Either8!
Wooo.
It could even have nice syntax.
 
People name their houses, right?
If I ever get a bike shed, I'll call it "syntax".
 
trait Either[A] {
    type |[B] = Either2[A, B]
}

trait Either2[A, B] {
    type |[C] = Either3[A, B, C]
}

// etc

def f(x: Either[Int] | Double | String) = ???
Does that work? :P
 
Well, it works in the sense that it depletes my brain of blood which is needed in another organ.
2
 
@FredOverflow I know you can use De Morgan's law with the Curry-Howard isomorphism to make union types without Left and Right wrappers.
79
A: Does Scala have "type disjunction" (union types)?

michidMiles Sabin describes a very nice way to get union type in his recent blog post Unboxed union types in Scala via the Curry-Howard isomorphism: He first defines negation of types as type ¬[A] = A => Nothing using De Morgan's law this allows him to define union types type ∨[T, U] = ¬[¬[T] with...

And it doesn't even use reflection!
 
 
1 hour later…
user1804599
4:18 PM
@FredOverflow how did you implement the static analysis machinery?
 
@rightfold You want the full code (250 lines) or a rough description?
 
user1804599
Did you consider putting your Karel implementation on github.com/fredhub?
 
Yes. And the answer is: not until I have unit tests :)
 
user1804599
@FredOverflow There goes an old saying that 250 lines of code say more than a rough description.
 
hold on to yer butt, uploading...
 
user1804599
4:19 PM
@FredOverflow I write unit tests before I write the code that makes them pass. :D
 
@rightfold The core logic, I spared you the boring GUI parts ;)
 
user1804599
Nice.
 
user1804599
I might be able to do something similar for optimisations and warnings.
 
The first 100 lines are probably impenetrable without documentation, which I will have to write before I publish on github :)
 
user1804599
I don't allow monkey patching (modules and types are immutable) so static analysing can actually be fun. :)
 
4:27 PM
There is probably only one beautiful functional line of code, and that is line 206 :)
 
user1804599
Nice. :P
 
As you see, there are some hard TODOs in the code. I'll probably never come around to finishing them.
The next feasible check would probably some kind of "function is recursive on all control paths" or whatever the correct terminology is.
 
user1804599
I am still dealing with unknown types here and there, though (Styx is dynamically typed).
 
user1804599
But this can be fun:
 
user1804599
let f (x: Int) = x * x

let x = somethingWithNoKnownType ()
f x
// now I know that x: Int
 
4:31 PM
ah because no overloading?
 
user1804599
Well, f takes an integer.
 
And there could not be a second f that takes a float?
 
user1804599
No.
 
user1804599
f is not overloadable, since none of its parameters are declared virtual.
 
Virtual parameters? What have you been consuming? :)
 
user1804599
4:33 PM
You have to explicitly define a function to be overloadable, and on which parameters it can be overloaded.
 
user1804599
The virtual syntax is from Bjarne's multimethod paper.
 
But virtual is for overriding, not overloading?
 
user1804599
let f (x: virtual) = x * x

let x = somethingWithNoKnownType ()
f x
// now I do not know whether x: Int
 
user1804599
@FredOverflow example:
 
user1804599
let to_string (x: virtual) // body is optional if there are virtual parameters
overload to_string (x: Int) = (magic algorithm here)
overload to_string (x: String) = x
overload to_string (x: Name) = x.first_name ~ " " ~ x.last_name
 
4:39 PM
magic algorithm = "%d".format(x)
 
user1804599
lol
 
user1804599
You forgot x.
 
user1804599
Also that doesn't work.
 
user1804599
format is not a member of String.
 
Where did I forget x? The "magic algorithm =" part was pseudo-code.
@rightfold It is in Scala via extension methods ;)
 
user1804599
4:40 PM
I don't have methods.
 
user1804599
It's pretty much functions and structs like in C.
 
Hello Go?
 
user1804599
Go has methods.
 
oh
Go without methods... Stumble? Trip?
 
user1804599
I don't like methods.
 
4:43 PM
@rightfold I think my favorite line is line 8 though.
 
user1804599
:D
 
Only three operations to determine if one formula implies another.
Like onBeeper() && frontIsClear() implies onBeeper().
 
user1804599
Logical.
 
user1804599
As does onBeeper() || false.
 
Yes, || false is actually implemented as | 0 which does nothing.
 
user1804599
4:46 PM
I'm still not sure how I want to do type equality.
 
probably an unsolvable problem
 
user1804599
I thought of this:
 
user1804599
let Ref T = structure[T](getChannel: Channel T; setChannel: Channel T)
 
user1804599
The [T] syntax would add metadata to the structure type.
 
user1804599
And when checking equality, all metadata is also checked for equality.
 
user1804599
4:48 PM
Ref is just a function from Type to Type; types are values.
 
user1804599
5:02 PM
Time to write the parser. :D
 

« first day (596 days earlier)      last day (297 days later) »