Question

In Haskell :

ghci> :type null
null :: [a] -> Bool

In Frege :

frege> :type null
Empty α => α β -> Bool

How do I interpret this answer and why is there a difference?

(example from real-world haskell as adapted in real-world frege git repo)

Était-ce utile?

La solution

Because String is not [Char] in Frege, some (maybe half-hearted) attempts have been made to nevertheless guarantee a certain level of compatibility behind the scenes:

  1. Type class Empty makes testing for the empty value (null) possible (should probably be a subclass of Monoid, though)
  2. Type class ListLike gives you head and tail and (++)
  3. Type class ListSource is for types that can be viewed as Lists (via operation toList). Currently, String, Maybe and arrays. Note that list comprehension not only allows [a], but instances of ListSource on the right hand side of generators.

Both lists and strings are instances of the above classes and this way certain basic functions do work on both lists and strings, just like in Haskell, though the type of those functions is a bit more general in Frege.

Bottom line: As long as you use simple functions like null, (++), head, tail and list comprehension you may not even notice that strings are not lists in Frege.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top