Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function application operand ($) for types in haskell?

Tags:

haskell

Is there a ($) equivalent for types in Haskell?

If I have a type with parameters

data myType a b c = ...

It would be nice to apply a monad like so :

f :: input -> errorMonad $ myType a b c
{- throws error:
   Not in scope: type constructor or class ‘$’. -}

I can get the same effect with

f :: input -> errorMonad (myType a b c)

but is not as clear IMO.

like image 570
Santiago Cuellar Avatar asked Apr 22 '20 16:04

Santiago Cuellar


People also ask

Which of the following is not a valid Haskell type signature?

(:==) is not a valid symbol for a function or variable identifier in Haskell.

What does in do in Haskell?

in goes along with let to name one or more local expressions in a pure function.

What is nil Haskell?

The Nil constructor is an empty list. It contains no objects. So any time you're using the [] expression, you're actually using Nil . Then the second constructor concatenates a single element with another list. The type of the element and the list must match up obviously.

What is returns Haskell?

return is actually just a simple function in Haskell. It does not return something. It wraps a value into a monad. Looks like return is an overloaded function.


1 Answers

A possible solution is to define your own type operator $:

{-# LANGUAGE TypeOperators, PolyKinds #-}

type ($) a = a
like image 149
chi Avatar answered Oct 23 '22 07:10

chi