Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Purescript; What is the difference between -> and =>?

Tags:

purescript

While working through PureScript tutorials, the code samples start using "=>" without introducing it. As results I don't understand when to use '=>' and not '->'.

For example this uses '=>':

instance showArray :: (Show a) => Show (Array a) where
    show array = "[" <> map show array <> "]"

where as this uses '->':

greet :: forall r. { name :: String | r} -> String
greet namedThing = "Hello, " ++ namedThing.name
like image 624
Nigel Thorne Avatar asked Oct 26 '25 09:10

Nigel Thorne


1 Answers

(Show a) => is a type constraint, which restricts the type a to instances of the class Show and a -> b is a type of function. So this code

foo :: forall a. (Show a) => a -> b

is a function foo from a to b and type a must have an instance of class Show

In OO languages it would be something like this

public B foo<A,B>(A x) where A:IShow
like image 134
ais Avatar answered Oct 29 '25 02:10

ais



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!