Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm: How can I find out the type of an Elm expression or a subexpression in elm-repl?

Tags:

elm

How can I find out the type of an Elm expression or a subexpression in elm-repl ?

Haskell's :type or :t equivalent in Elm REPL?

like image 889
C.S.Reddy Gadipally Avatar asked Apr 30 '18 15:04

C.S.Reddy Gadipally


1 Answers

The Elm REPL automatically prints the type of whatever you enter. For example:

> "foo"
"foo" : String
> f = \a b c -> (a + 1, b ++ "!", c || False)
<function> : number -> String -> Bool -> ( number, String, Bool )
> f
<function> : number -> String -> Bool -> ( number, String, Bool )
> f2 a b c = (a + 1, b ++ "!", c || False)
<function> : number -> String -> Bool -> ( number, String, Bool )

As @amalloy points out, without an equivalent to GHCi's :type command, Elm REPL (as of 0.18) forces evaluation of an expression prior to showing you the type, which may be undesirable for expensive function calls. In its current version, there is no way around this.

like image 100
Chad Gilbert Avatar answered Jan 01 '23 02:01

Chad Gilbert