Newest at the top
2025-05-12 06:06:04 +0200 | <EvanR> | ...) -> a) -> a) -> a) -> a |
2025-05-12 06:04:51 +0200 | <ski> | `omega :: o where o = o -> a' in Haskellish terms |
2025-05-12 06:03:57 +0200 | <ski> | ^ shorter way to express the same type |
2025-05-12 06:03:47 +0200 | <ski> | val omega : 'b -> 'a as 'b = <fun> |
2025-05-12 06:03:44 +0200 | <ski> | # let omega : 'o -> 'a as 'o = fun x -> x x;; |
2025-05-12 06:01:09 +0200 | <ski> | (this is useful for "binary methods" and "clone methods / functional update". see <https://ocaml.org/manual/5.3/objectexamples.html#s:functional-objects> and <https://ocaml.org/manual/5.3/objectexamples.html#s:binary-methods>) |
2025-05-12 05:58:15 +0200 | <ski> | without `-rectypes', it only allows such cycles, if they go through at least one object type |
2025-05-12 05:58:04 +0200 | <monochrom> | OK that's deep magic. |
2025-05-12 05:57:50 +0200 | <ski> | `ocaml -rectypes' does, yes |
2025-05-12 05:57:41 +0200 | <monochrom> | Oh God it does equi-recursive types?! |
2025-05-12 05:57:33 +0200 | <EvanR> | it's an infinite type |
2025-05-12 05:57:10 +0200 | <ski> | val omega : ('a -> 'b as 'a) -> 'b = <fun> |
2025-05-12 05:57:08 +0200 | <ski> | # let omega x = x x;; |
2025-05-12 05:57:06 +0200 | <EvanR> | this is some fun t business |
2025-05-12 05:56:29 +0200 | <monochrom> | Wait, how does that accept that "t t" is typeable? |
2025-05-12 05:56:11 +0200 | <EvanR> | alright let me think |
2025-05-12 05:54:46 +0200 | <ski> | - : int = 144 |
2025-05-12 05:54:43 +0200 | <ski> | # fix (fun fib n -> match n with 0 -> 0 | 1 -> 1 | n -> fib (n - 1) + fib (n - 2)) 12;; |
2025-05-12 05:54:33 +0200 | <ski> | val fix : (('a -> 'b) -> 'a -> 'b) -> 'a -> 'b = <fun> |
2025-05-12 05:54:28 +0200 | <ski> | # let fix f = (fun t -> t t) (fun t x -> f (t t) x);; |
2025-05-12 05:53:53 +0200 | <EvanR> | uhg |
2025-05-12 05:53:41 +0200 | <monochrom> | No, it's designed to be compatible with by-value evaluation. |
2025-05-12 05:53:03 +0200 | <EvanR> | does the by value version need a different evaluation strategy |
2025-05-12 05:52:27 +0200 | <EvanR> | ok but the point of a fix construct is so you don't have to munge these nuts combinators, and so they can have a type |
2025-05-12 05:50:41 +0200 | <monochrom> | It is correct. :) |
2025-05-12 05:50:26 +0200 | <EvanR> | I probably messed up |
2025-05-12 05:50:16 +0200 | <EvanR> | \f -> (\t -> t t) (\x -> f (\v -> (x x v))) |
2025-05-12 05:49:03 +0200 | <ski> | yea, i prefer adding in `(\t -> t t)' for the first part, no need to repeat something longer |
2025-05-12 05:48:04 +0200 | <EvanR> | but yours is more explainable |
2025-05-12 05:47:42 +0200 | <EvanR> | I found this on some page Z = \f -> (\x -> (f (\v -> (x x v)))) (\x -> (f (\v -> (x x v)))) |
2025-05-12 05:47:33 +0200 | michalz | (~michalz@185.246.207.203) |
2025-05-12 05:47:01 +0200 | <monochrom> | So it is missing out on fix (0 :) = 0 : 0 : ... but it's OK, call-by-value languages don't have lazy lists in the first place. :) |
2025-05-12 05:45:43 +0200 | <monochrom> | Y is (\t -> t t) (\t -> f (t t)). For call-by-value languages we eta expand to (\t x -> f (t t) x) so one more argument is needed for evaluation so there is the delay I said we need. |
2025-05-12 05:44:51 +0200 | Unicorn_Princess | (~Unicorn_P@user/Unicorn-Princess/x-3540542) (Remote host closed the connection) |
2025-05-12 05:44:20 +0200 | <ski> | (note the eta-expansion) |
2025-05-12 05:43:00 +0200 | <EvanR> | I see |
2025-05-12 05:42:06 +0200 | <ski> | it's the by-value fixed point combinator |
2025-05-12 05:41:48 +0200 | <EvanR> | is that the Z combinator ski |
2025-05-12 05:41:15 +0200 | <monochrom> | So you cannot make "fix (0 :) = 0 : 0 : ..." like in Haskell, but you can still make "fix (\f -> \n -> ... fibonacci ...)" |
2025-05-12 05:39:40 +0200 | <ski> | fix f = (\t -> t t) (\t x -> f (t t) x) |
2025-05-12 05:39:36 +0200 | <monochrom> | Even in call-by-value languages, lambdas are lazy in bodies, or at least delayed, i.e., "\x -> undefined" does not cause that undefined to be evaluated, only application "(\x -> undefined) 5" does. That little delay is leveraged to make fixed point combinators and emulation of laziness. |
2025-05-12 05:39:33 +0200 | <ski> | fix :: ((a -> b) -> (a -> b)) -> (a -> b) |
2025-05-12 05:38:16 +0200 | <EvanR> | how do all these languages get recursion without lazy evaluation |
2025-05-12 05:36:21 +0200 | <monochrom> | True. |
2025-05-12 05:28:34 +0200 | <EvanR> | or else evaluating fix f necessarily freezes |
2025-05-12 05:28:03 +0200 | <EvanR> | true or false, to have a working fixed point construct for recursion, you need some kind of lazy evaluation |
2025-05-12 05:27:43 +0200 | weary-traveler | (~user@user/user363627) user363627 |
2025-05-12 05:27:18 +0200 | weary-traveler | (~user@user/user363627) (Remote host closed the connection) |
2025-05-12 05:22:59 +0200 | <monochrom> | :) |
2025-05-12 05:18:32 +0200 | weary-traveler | (~user@user/user363627) user363627 |