-
Notifications
You must be signed in to change notification settings - Fork 634
Idris for Haskellers
Brandon Elam Barker edited this page Jun 3, 2018
·
50 revisions
Things to look out for when expecting Idris to be Haskell:
- Top level functions must have type annotations.
- Functions and data types must be defined in the source file before it can be used. Mutually dependent functions can be linked using a
mutualblock. - The type given to lists is not indicated using a special syntax i.e.
[Int]. Rather theListtype is used. For example,[Int]in Haskell is equivalent toList Int. Brackets are used as syntactic sugar for representing a list of values. - Functions are overloaded, for example,
(++)can meanPrelude.List.(++) : List a -> List a -> List aorPrelude.Strings.(++) : String -> String -> String. So Haskell'sfoldl (++) [] ["1","2"], for example, needs to be written asfoldl Strings.(++) "" ["1","2"]if it is not possible to disambiguate between the possible meanings of(++)based on the argument and return types given to(++) - In Idris
Stringis not represented as a synonym for a list of characters. For example, Haskell'sfoldl (++) [] ["1","2"]needs to be written asfoldl Strings.(++) "" ["1","2"]in Idris but surprisinglyconcat $ replicate 5 "bla"works just like in Haskell , becauseStringis Monoid andListis Foldable. -
derivingdoes not work yet. - Operators for cons and type annotations are swapped. Type annotations are denoted in Idris by
:rather than::. Thus Idris's cons operator is::. - In Idris there is no
undefined, holes (such as?hole) can be used instead ofundefined. Also,believe_mefrom the built-in-s can be used to defineundefined. - Haskell's
erroris inDebug.Error.error(Debug.Error.erroris not really like Idris'serrorthough because it won't get caught like it can in Haskell.) - Idris' Template-Haskell is "reflected elaboration"
-
fmapismapin Idris. - Record syntax has a slightly different syntax in Idris, notably, records have only one constructor in Idris, unlike in Haskell, where records can have multi constructors. Why this limitation ? Multi constructor records have non-total accessor functions.
- There is no
Readtypeclass in Idris. -
:letin the REPL should be used instead of justlet. - Unlike GHCI, the Idris REPL is not inside of an implicit IO monad. Use
:xin the REPL for executing IO actions. -
2 :: Intshould be written asthe Int 2in Idris. - Error messages not always tell you yet as clearly as in Haskell what is wrong if your code does not compile. Error messages are helpful for locating roughly where the error is in the source code, but not always yet as to what the error is.
-
headdoes NOT work on arbitrary lists in Idris, only on lists that are non-empty:Prelude.List.head : (l : List a) -> {auto ok : NonEmpty l} -> a - The arrow in a lambda expression or a case expression in Idris is denoted by
=>instead of->(Haskell). - There should be commas between multiple parameters in lambda expression in Idris like
\s, n => s + ninstead of\s n -> s + nin Haskell. - There is no
!!infix operator to get an element from a list by its index, useindexfunction instead. - There is no syntax for type alias in Idris, just use standard functions to define aliases, for example ,
myNewtype:Typeand thenmyNewtype=(Int, String). - In Idris type-classes are called interfaces. In Idris it is possible to get hold of the vtable (type class records), pass it around and feed it to functions explicitly (in contrast to Haskell where this can only happen implicitly).
Binary Packages
Tool Support
Community
- Libraries, available elsewhere
- Idris Developer Meetings
- The Zen of Idris
- Non English Resources
Development