Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note first that <code>last</code> is not particularly great on other grounds, since it is a partial function like <code>head</code>. If you are constantly using the tail end of the list, scrap it for <code>Data.Sequence</code> or <code>Data.Vector.Unboxed</code>:</p> <pre><code>import Data.Sequence firstThing seq = case viewl seq of EmptyL -&gt; error "no beginning" a :&lt; as -&gt; a lastThing seq = case viewr seq of EmptyR -&gt; error "no end" as :&gt; a -&gt; a -- &gt; lastThing (fromList "abc") -- 'c' -- &gt; firstThing (fromList "abc") -- 'a' </code></pre> <p>If you are using an unboxed type like <code>Int</code>, <code>Double</code>, <code>Char</code> etc. then you will get still better results with <code>Data.Vector.Unboxed</code> , see the documentation for remarks about the efficiency of <code>Data.Vector.Unboxed.head</code> and <code>Data.Vector.Unboxed.last</code> <a href="http://hackage.haskell.org/packages/archive/vector/0.10.0.1/doc/html/Data-Vector-Unboxed.html#g:4" rel="nofollow noreferrer">http://hackage.haskell.org/packages/archive/vector/0.10.0.1/doc/html/Data-Vector-Unboxed.html#g:4</a> </p> <p>In the special case where you are using lists of <code>Char</code>s use <code>Data.Text</code> wherever possible, this is <em>emphatically</em> the 'idiomatic' thing. Again see the documentation for <code>head</code> and <code>last</code> <a href="http://hackage.haskell.org/packages/archive/text/0.11.2.3/doc/html/Data-Text.html" rel="nofollow noreferrer">http://hackage.haskell.org/packages/archive/text/0.11.2.3/doc/html/Data-Text.html</a> </p> <p>If you are imagining a contrast between 'Haskell' lists and 'lists' in other languages, it is probably the contrast between 'Haskell' lists on the one hand, and vectors and arrays on the other; the latter are just as 'Haskelly' as lists.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload