libera/#commonlisp - IRC Chatlog
Search
18:28:56
lisp123
stylewarning: I tried reading https://coalton-lang.github.io/20211212-typeclasses/ but unfortunately it was too advanced for me, but I am just curious where CLOS fall shorts as a type system? I saw some mention of "generic values"
18:32:12
Bike
the perhaps silly way that i think about it is that generic functions can't specialize on their return type.
18:35:36
Bike
the bit on this post in map sums it up: "Common Lisp does not allow map to deduce its return type based off the surrounding context", and indeed that's kind of a nonsensical proposition with the semantics of the language
18:36:04
lisp123
But wouldn't the return type be contingent upon the inputs to a function so one should just create distinct generic functions, depending on the input?
18:36:54
Bike
for map the return type is not continent on the inputs to the function (other than the specifier input). you can map a list to a vector, a list to a list, whatever.
18:37:48
Bike
in the example in this blog post, you could also consider how "identity" would work as a generic function
18:38:08
Bike
...it wouldn't, since it doesn't actually have any arguments. the only thing to "dispatch on" is the context
18:39:29
lisp123
I need to read that bit again, I didn't quite get it. What does "context" mean in this sense?
18:41:01
lisp123
The bit about specialising on return type, would that be more useful when coercing from one type to another? I saw mention something of that in the post, so that kinda makes sense to me
18:41:39
Bike
Consider the lisp form (+). that is defined to be an integer 0. If you write (+ 3.7 (+)), what that means (prior to optimization) is that you call +, that returns integer 0, that's coerced to a single float, and then added to the float 3.7
18:42:45
Bike
In a language like coalton, you could have (+) return a different zero depending on its inferred return type
18:46:21
yitzi
Seems like if you were actually trying to implement an algebra with generic functions you could just accomplish this by specializing on a "group" or "field" instance.
18:47:04
Bike
sure, people do that. and actually i think that's how coalton implements typeclasses under the hood.
18:55:59
jcowan
First-era industrial capitalism worked on the principle of "work fast and break people and other living things".
19:01:15
Bike
jcowan, when you respond to something hours later like i assume you're doing, can you give me some kind of hint so I don't sit for a minute trying to understand what coal mines have to do with computer algebra systems
19:03:30
_death
I don't care about specializing on the return type, but it would be great if I could declaim a GF's return type without SBCL clobbering it :/
21:55:19
yitzi
If you want other behavior then use :initial-value, but returning the set is more mathematically correct.
22:01:07
pjb
utis: (reduce #'intersection '((a b c)) :initial-value '(a b c d e f)) #| --> (c b a) |#
22:02:30
pjb
utis_: (reduce #'intersection '((a b c)) :initial-value '(a b c d e f)) #| --> (c b a) |#
22:13:22
Guest74
not to mention reducing with intersection wont get you what you're probably expecting.
0:24:48
jackdaniel
clim visualisation of fast gf dispatch for ecl (wip) https://i.imgur.com/fGGvPVK.png
2:47:13
rotateq
hehe i saw a video from Edi where he talks about the 2nd version for his popular math book and in the end "so also my book 'Common Lisp Recipes', more a reference for advanced users, the dumb title isn't by me, but the publisher" ^^