Skip to content

Coercions

"I have a Float but want a Double". Or: I have a String but want a Text.

AnswerΒΆ

Usually one can find the right function via Hoogle:

Hoogle

However, a more convenient option is to use the Witch library, which abstracts coercions using a single function, called into:

{-# LANGUAGE TypeApplications #-} 

import Witch 


float :: Float
float = 4

double :: Double
double = into @Double float 

str :: String
str = "hello"

text :: Text
text = into @Text str

Comments