How to translate this function to Haskell?


Really off-topic, but how would I go about translating the following very useful function to Haskell?

fn pointless<F: Fn(&F) -> T, T>(x: F) -> T { x(&x) }

I tried:

pointless x = x x

but that didn’t work.


did you meant this?

pointless :: (a -> a) -> a -> a
pointless x = x . x

-- for example
let ex = pointless (+ 1)
ex 1 
-- outputs 3

unfortunately I’m not sure what the rust code should do :sweat:


No it’s literally what it looks like - a function that takes a function of type a that takes a function of type a and produces a value of type b. But thanks for trying! :slight_smile:


I think something like this will do the trick:

{-# LANGUAGE MultiParamTypeClasses #-}

class Fn x a b where
    apply :: x -> a -> b

pointless :: (Fn x x b) => x -> b
pointless x = apply x x