| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | Rust | 240916T114211Z | bzr |
| 045 | Haskell | 240913T184613Z | Antonio |
| 069 | C++ | 240916T101458Z | cigien |
| 018 | Wolfram Language Mathematica | 240913T081135Z | att |
| 025 | Clojure | 240913T195506Z | Mitchell |
| 085 | Java | 240913T074322Z | Kevin Cr |
| 027 | C gcc | 240913T135527Z | jdt |
| 009 | K ngn/k | 240913T130009Z | ovs |
| 033 | Arturo | 240913T074801Z | chunes |
| 023 | Ruby | 240913T071350Z | G B |
| 024 | R | 240913T071317Z | pajonk |
| 038 | Python 3 | 240913T070917Z | The Empt |
| 021 | PARI/GP | 240913T062831Z | alephalp |
| 021 | JavaScript V8 | 240913T061528Z | Arnauld |
Haskell, 57, 45 bytes
Solution using a constructor:
data U=U([Char]->IO U);f s=U$(<$putStrLn s).f
Invalid solution using typeclasses:
{-#LANGUAGE FlexibleInstances#-}
class F a where g::String->a
instance F()where g _=()
instance F a=>F(String->IO a)where g a b=g b<$putStrLn a
The the typeclass based version will eventually return IO (), so it isn't really infinite. The non-typeclass based version however does go on forever.
Wolfram Language (Mathematica), 19 18 bytes
f@a_=f[Print@a;#]&
(subjectively) more interesting:
24 bytes:
Curry[Print@@##2;#0]@!#&
27 bytes:
#0@*(D@@(#/._?Print@_->$))&
Java, 85 bytes
interface N{N f(String s);static N i=s->t->{System.out.println(s);return N.i.f(t);};}
Explanation:
interface N{ // Interface to use as our lambda
N f(String s); // taking a String parameter, and returning another instance of itself
static // Static context so we're able to reference the interface
N i= // Create this interface as re-usable lambda method:
s-> // Taking a String parameter and returning another lambda method:
t->{ // Also taking a String parameter and returning a lambda method:
System.out.println(s);
// Print the String of the outer lambda with trailing newline
return // And then return
N.i.f(t);};}
// A call to the outer lambda with the inner String parameter,
// using a static call to prevent 'self-reference in initializer' errors
Arturo, 33 bytes
f:$->x->$.import:->x=>[f&print,x]
Ungolfed:
f: function [x][
function .import:[x] [y][
print x
f y
]
]
Python 3, 38 bytes
f=lambda x:lambda y:[f(y),print(x)][0]
Well sadly, the anonymous function can’t be shorter while being completely anonymous… 😮💨