Skip to main content
pick an example that doesn't use a space in a string literal, which would also be banned by the question
Source Link
ais523
  • 11
  • 19
  • 35

Haskell, cracks Unrelated String's second answer

The basic idea is to define a function a that makes it possible to write a[x][y] instead of (x y). Here's the definition, and an example of using it:

a[x][y]=head[x]y main=a[putStrLn][a[reverse]["code golf"]]main=a[putStrLn][a[reverse]["codegolf"]] 

Try it online!Try it online!

This works around the bans on horizontal whitespace and on parentheses; function arguments are now separated by ][ rather than whitespace, and because each argument is surrounded by square brackets, there's no need for any further grouping characters. Haskell uses currying for functions that take multiple arguments, meaning that a can handle these too (f x y becomes a[a[f][x]][y]), and we don't need a special case for them.

It's also possible to define functions using similar syntax, including defining functions by cases (e.g. f[0]=1 and on the next line f[1]=3); these don't need a to call because they have the square brackets built in, but otherwise work the same way (the square brackets still handle the grouping).

This means that most of the core functionality of Haskell is available – we can call most of the built-in functions, and define our own, including conditionals. That's a Turing-complete subset (loops via recursion and conditionals via functions-defined-by-cases are available, in addition to complex data structures), so the ban on whitespace and parentheses doesn't really hurt at all, and { and $ aren't required to make this subset work either.

Explanation

head[x] trivially evaluates to x – it's taking the first element of a 1-element list. The advantage over using x directly is that it ends with a non-identifier character, meaning that we can put a letter directly after it without needing to use whitespace.

a[x][y]= is a pattern match, used to define a function a; it defines the function only in the case where it's given two single-element lists as arguments, and defines x and y to be their arguments. As such, if we call a as a[x][y], then the x and y in the definition of a will be the same as the x and y at the call site. (It would be possible to give further definitions to cover the cases where x and y aren't single-element lists, but this isn't necessary to make the answer work.)

Haskell, cracks Unrelated String's second answer

The basic idea is to define a function a that makes it possible to write a[x][y] instead of (x y). Here's the definition, and an example of using it:

a[x][y]=head[x]y main=a[putStrLn][a[reverse]["code golf"]] 

Try it online!

This works around the bans on horizontal whitespace and on parentheses; function arguments are now separated by ][ rather than whitespace, and because each argument is surrounded by square brackets, there's no need for any further grouping characters. Haskell uses currying for functions that take multiple arguments, meaning that a can handle these too (f x y becomes a[a[f][x]][y]), and we don't need a special case for them.

It's also possible to define functions using similar syntax, including defining functions by cases (e.g. f[0]=1 and on the next line f[1]=3); these don't need a to call because they have the square brackets built in, but otherwise work the same way (the square brackets still handle the grouping).

This means that most of the core functionality of Haskell is available – we can call most of the built-in functions, and define our own, including conditionals. That's a Turing-complete subset (loops via recursion and conditionals via functions-defined-by-cases are available, in addition to complex data structures), so the ban on whitespace and parentheses doesn't really hurt at all, and { and $ aren't required to make this subset work either.

Explanation

head[x] trivially evaluates to x – it's taking the first element of a 1-element list. The advantage over using x directly is that it ends with a non-identifier character, meaning that we can put a letter directly after it without needing to use whitespace.

a[x][y]= is a pattern match, used to define a function a; it defines the function only in the case where it's given two single-element lists as arguments, and defines x and y to be their arguments. As such, if we call a as a[x][y], then the x and y in the definition of a will be the same as the x and y at the call site. (It would be possible to give further definitions to cover the cases where x and y aren't single-element lists, but this isn't necessary to make the answer work.)

Haskell, cracks Unrelated String's second answer

The basic idea is to define a function a that makes it possible to write a[x][y] instead of (x y). Here's the definition, and an example of using it:

a[x][y]=head[x]y main=a[putStrLn][a[reverse]["codegolf"]] 

Try it online!

This works around the bans on horizontal whitespace and on parentheses; function arguments are now separated by ][ rather than whitespace, and because each argument is surrounded by square brackets, there's no need for any further grouping characters. Haskell uses currying for functions that take multiple arguments, meaning that a can handle these too (f x y becomes a[a[f][x]][y]), and we don't need a special case for them.

It's also possible to define functions using similar syntax, including defining functions by cases (e.g. f[0]=1 and on the next line f[1]=3); these don't need a to call because they have the square brackets built in, but otherwise work the same way (the square brackets still handle the grouping).

This means that most of the core functionality of Haskell is available – we can call most of the built-in functions, and define our own, including conditionals. That's a Turing-complete subset (loops via recursion and conditionals via functions-defined-by-cases are available, in addition to complex data structures), so the ban on whitespace and parentheses doesn't really hurt at all, and { and $ aren't required to make this subset work either.

Explanation

head[x] trivially evaluates to x – it's taking the first element of a 1-element list. The advantage over using x directly is that it ends with a non-identifier character, meaning that we can put a letter directly after it without needing to use whitespace.

a[x][y]= is a pattern match, used to define a function a; it defines the function only in the case where it's given two single-element lists as arguments, and defines x and y to be their arguments. As such, if we call a as a[x][y], then the x and y in the definition of a will be the same as the x and y at the call site. (It would be possible to give further definitions to cover the cases where x and y aren't single-element lists, but this isn't necessary to make the answer work.)

Source Link
ais523
  • 11
  • 19
  • 35

Haskell, cracks Unrelated String's second answer

The basic idea is to define a function a that makes it possible to write a[x][y] instead of (x y). Here's the definition, and an example of using it:

a[x][y]=head[x]y main=a[putStrLn][a[reverse]["code golf"]] 

Try it online!

This works around the bans on horizontal whitespace and on parentheses; function arguments are now separated by ][ rather than whitespace, and because each argument is surrounded by square brackets, there's no need for any further grouping characters. Haskell uses currying for functions that take multiple arguments, meaning that a can handle these too (f x y becomes a[a[f][x]][y]), and we don't need a special case for them.

It's also possible to define functions using similar syntax, including defining functions by cases (e.g. f[0]=1 and on the next line f[1]=3); these don't need a to call because they have the square brackets built in, but otherwise work the same way (the square brackets still handle the grouping).

This means that most of the core functionality of Haskell is available – we can call most of the built-in functions, and define our own, including conditionals. That's a Turing-complete subset (loops via recursion and conditionals via functions-defined-by-cases are available, in addition to complex data structures), so the ban on whitespace and parentheses doesn't really hurt at all, and { and $ aren't required to make this subset work either.

Explanation

head[x] trivially evaluates to x – it's taking the first element of a 1-element list. The advantage over using x directly is that it ends with a non-identifier character, meaning that we can put a letter directly after it without needing to use whitespace.

a[x][y]= is a pattern match, used to define a function a; it defines the function only in the case where it's given two single-element lists as arguments, and defines x and y to be their arguments. As such, if we call a as a[x][y], then the x and y in the definition of a will be the same as the x and y at the call site. (It would be possible to give further definitions to cover the cases where x and y aren't single-element lists, but this isn't necessary to make the answer work.)

Post Made Community Wiki by ais523