g | x | w | all
Bytes Lang Time Link
029Rust240916T114211Zbzr
045Haskell240913T184613ZAntonio
069C++240916T101458Zcigien
018Wolfram Language Mathematica240913T081135Zatt
025Clojure240913T195506ZMitchell
085Java240913T074322ZKevin Cr
027C gcc240913T135527Zjdt
009K ngn/k240913T130009Zovs
033Arturo240913T074801Zchunes
023Ruby240913T071350ZG B
024R240913T071317Zpajonk
038Python 3240913T070917ZThe Empt
021PARI/GP240913T062831Zalephalp
021JavaScript V8240913T061528ZArnauld

Rust, 57 49 45 29 bytes

fn x(s:&str)->!{dbg!(s);x(s)}

Attempt This Online!

Haskell, 57, 45 bytes

Solution using a constructor:

data U=U([Char]->IO U);f s=U$(<$putStrLn s).f

Try it online!

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

Try it online!

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.

C++, 69 bytes

auto f(auto s){return[=](this auto t,auto n){return cout<<s,s=n,t;};}

Try it online!

Wolfram Language (Mathematica), 19 18 bytes

f@a_=f[Print@a;#]&

Try it online!


(subjectively) more interesting:

24 bytes:

Curry[Print@@##2;#0]@!#&

Try it online!

27 bytes:

#0@*(D@@(#/._?Print@_->$))&

Try it online!

Clojure, 25 bytes

defn f[s]#(do(pr s)(f %))

Try it online!

Java, 85 bytes

interface N{N f(String s);static N i=s->t->{System.out.println(s);return N.i.f(t);};}

Try it online.

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

C (gcc), 27 bytes

t;f(s){t&&puts(t);t=s;s=f;}

Try it online!

K (ngn/k), 9 bytes

partial application ftw

{ \x;o@y}

Try it online!

 f:{ \x;o@y}
 f:f"s1"
 f:f"s2"
"s1"
 f:f"s3"
"s2"

Arturo, 33 bytes

f:$->x->$.import:->x=>[f&print,x]

Try it!

Ungolfed:

f: function [x][
    function .import:[x] [y][
        print x
        f y
    ]
]

Ruby, 23 bytes

f=->s{->z{puts s;f[z]}}

Try it online!

R, 24 bytes

f=\(s)\(t){show(s);f(t)}

Attempt This Online!

Python 3, 38 bytes

f=lambda x:lambda y:[f(y),print(x)][0]

Try it online!

Well sadly, the anonymous function can’t be shorter while being completely anonymous… 😮‍💨

PARI/GP, 21 bytes

f(x)=t->print(x);f(t)

Attempt This Online!

JavaScript (V8), 21 bytes

f=s=>x=>f(x,print(s))

Try it online!