Creating an alias for a function

How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's (define head car) car :: [a] -> a car x = head x The reason for doing this is to more closely mirror legacy code. Michael

car = head letting the compiler infer the type, or car :: [a] -> a car = head for the explicit version. -Ross On Oct 6, 2009, at 10:01 PM, michael rice wrote:
How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's
(define head car)
car :: [a] -> a car x = head x
The reason for doing this is to more closely mirror legacy code.
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wed, Oct 7, 2009 at 1:26 AM, Bulat Ziganshin
Hello Ross,
Wednesday, October 7, 2009, 6:02:28 AM, you wrote:
car = head
unfortunately it doesn't work without -fno-monomorphism-restriction
It should be fine without the monomorphism restriction. Said restriction only applies to functions with typeclass constraints, of which this has none. Luke

Hello Luke, Wednesday, October 7, 2009, 11:35:47 AM, you wrote:
car = head
unfortunately it doesn't work without -fno-monomorphism-restriction
It should be fine without the monomorphism restriction. Said restriction only applies to functions with typeclass constraints, of which this has none.
oh, i don't known this. but anyway michael may have such functions about those you need to alias -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Actually I used it to fake the Pascal ord(x) function:
ord = fromEnum
Problem?
Michael
--- On Wed, 10/7/09, Bulat Ziganshin
car = head
unfortunately it doesn't work without -fno-monomorphism-restriction
It should be fine without the monomorphism restriction. Said restriction only applies to functions with typeclass constraints, of which this has none.
oh, i don't known this. but anyway michael may have such functions about those you need to alias -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2009/10/7 michael rice
Actually I used it to fake the Pascal ord(x) function:
ord = fromEnum
Problem?
Michael
If the monomorphism restriction applies, the compiler (assuming you're using GHC) will tell you about it. -- Deniz Dogan

Hello Deniz, Wednesday, October 7, 2009, 5:03:59 PM, you wrote: it depends. what i see with ghc 6.6.1: C:\!\Haskell>runghc test.hs test.hs:1:6: Ambiguous type variable `a' in the constraint: `Enum a' arising from use of `fromEnum' at test.hs:1:6-13 Possible cause: the monomorphism restriction applied to the following: ord :: a -> Int (bound at test.hs:1:0) Probable fix: give these definition(s) an explicit type signature or use -fno-monomorphism-restriction C:\!\Haskell>ghc --make test.hs [1 of 1] Compiling Main ( test.hs, test.o ) Linking test.exe ... test.hs: ord = fromEnum main = print (ord 'a')
2009/10/7 michael rice
Actually I used it to fake the Pascal ord(x) function:
ord = fromEnum
Problem?
Michael
If the monomorphism restriction applies, the compiler (assuming you're using GHC) will tell you about it.
-- Deniz Dogan
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

2009/10/7 Bulat Ziganshin
Hello Deniz,
Wednesday, October 7, 2009, 5:03:59 PM, you wrote:
it depends. what i see with ghc 6.6.1:
[snip]
Possible cause: the monomorphism restriction applied to the following: ord :: a -> Int (bound at test.hs:1:0) Probable fix: give these definition(s) an explicit type signature or use -fno-monomorphism-restriction
I don't see the problem? GHC seems to tell you about the monomorphism restriction in your example. -- Deniz Dogan

Hello Deniz, Wednesday, October 7, 2009, 5:23:24 PM, you wrote:
Possible cause: the monomorphism restriction applied to the following: ord :: a -> Int (bound at test.hs:1:0) Probable fix: give these definition(s) an explicit type signature or use -fno-monomorphism-restriction
I don't see the problem? GHC seems to tell you about the monomorphism restriction in your example.
look further. runghc complains, ghc - don't. may be runghc enables -Wall? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Hallo,
On Tue, Oct 6, 2009 at 11:01 PM, michael rice
How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's
(define head car)
car :: [a] -> a car x = head x
The reason for doing this is to more closely mirror legacy code.
Just do: car = head -- -alex http://www.ventonegro.org/

Well, you can drop the arguments entirely, and let the type be inferred to get car = head which is pretty nice. You could use an INLINE hint to make the compiler replace it before compilation, though I don't think it would change performance much... /Joe On Oct 6, 2009, at 10:01 PM, michael rice wrote:
How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's
(define head car)
car :: [a] -> a car x = head x
The reason for doing this is to more closely mirror legacy code.
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks all!
There's ALWAYS seems to be a neat way to do what's needed with Haskell.
Michael
--- On Tue, 10/6/09, Joe Fredette
How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's
(define head car)
car :: [a] -> a car x = head x
The reason for doing this is to more closely mirror legacy code.
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Michael, You can define a function without listing some or all of its arguments by specifying it in terms of another function. So all you really need to write is, e.g., car = head cdr = tail cadr = car . cdr caddr = car . cadr cadar = car . cdr . car etc... On Oct 6, 2009, at 7:01 PM, michael rice wrote:
How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's
(define head car)
car :: [a] -> a car x = head x
The reason for doing this is to more closely mirror legacy code.
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (8)
-
Alex Queiroz
-
Bulat Ziganshin
-
Deniz Dogan
-
Gregory Crosswhite
-
Joe Fredette
-
Luke Palmer
-
michael rice
-
Ross Mellgren