[Haskell] Haskell [x] and x notation - as-pattern example

Tillmann Rendel rendel at informatik.uni-marburg.de
Thu Apr 4 14:47:12 CEST 2013


Hi Angus,

Angus Comber wrote:
> Also xs is of what type? list of values? So does this mean x is an
> element and xs must be of type list? Confused...

Here is how you can use ghci to investigate such questions:

>> ghci
> GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
>
> Prelude> let all@(x:xs) = "hello world"
>
> Prelude> x
> 'h'
>
> Prelude> xs
> "ello world"
>
> Prelude> all
> "hello world"
>
> Prelude> :t x
> x :: Char
>
> Prelude> :t xs
> xs :: [Char]
>
> Prelude> :t all
> all :: [Char]
>
> Prelude> x
> 'h'
>
> Prelude> [x]
> "h"
>
> Prelude> :t x
> x :: Char
>
> Prelude> :t [x]
> [x] :: [Char]
>
> Prelude> :q
> Leaving GHCi.

   Tillmann

PS. The haskell at haskell.org list is mostly for announcements, so 
questions like this are better suited for beginners at haskell.org or 
haskell-cafe at haskell.org.



More information about the Haskell mailing list